Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 56 | #include <linux/freezer.h> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 57 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 74 | #define NFS4_BITMASK_SZ 3 |
| 75 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 76 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 78 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 79 | /* file attributes which can be mapped to nfs attributes */ |
| 80 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 81 | | ATTR_UID \ |
| 82 | | ATTR_GID \ |
| 83 | | ATTR_SIZE \ |
| 84 | | ATTR_ATIME \ |
| 85 | | ATTR_MTIME \ |
| 86 | | ATTR_CTIME \ |
| 87 | | ATTR_ATIME_SET \ |
| 88 | | ATTR_MTIME_SET) |
| 89 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 90 | struct nfs4_opendata; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 91 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 93 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 94 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); |
| 95 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 96 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 97 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 98 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 99 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 100 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 101 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 102 | struct rpc_cred *cred, |
| 103 | struct nfs4_slot *slot, |
| 104 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 105 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 106 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 107 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 108 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 109 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 112 | static inline struct nfs4_label * |
| 113 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 114 | struct iattr *sattr, struct nfs4_label *label) |
| 115 | { |
| 116 | int err; |
| 117 | |
| 118 | if (label == NULL) |
| 119 | return NULL; |
| 120 | |
| 121 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 122 | return NULL; |
| 123 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 124 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 125 | &dentry->d_name, (void **)&label->label, &label->len); |
| 126 | if (err == 0) |
| 127 | return label; |
| 128 | |
| 129 | return NULL; |
| 130 | } |
| 131 | static inline void |
| 132 | nfs4_label_release_security(struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | security_release_secctx(label->label, label->len); |
| 136 | } |
| 137 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 138 | { |
| 139 | if (label) |
| 140 | return server->attr_bitmask; |
| 141 | |
| 142 | return server->attr_bitmask_nl; |
| 143 | } |
| 144 | #else |
| 145 | static inline struct nfs4_label * |
| 146 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 147 | struct iattr *sattr, struct nfs4_label *l) |
| 148 | { return NULL; } |
| 149 | static inline void |
| 150 | nfs4_label_release_security(struct nfs4_label *label) |
| 151 | { return; } |
| 152 | static inline u32 * |
| 153 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 154 | { return server->attr_bitmask; } |
| 155 | #endif |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 158 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | if (err >= -1000) |
| 161 | return err; |
| 162 | switch (err) { |
| 163 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 164 | case -NFS4ERR_LAYOUTTRYLATER: |
| 165 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 166 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 167 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 168 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 169 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 170 | case -NFS4ERR_BADOWNER: |
| 171 | case -NFS4ERR_BADNAME: |
| 172 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 173 | case -NFS4ERR_SHARE_DENIED: |
| 174 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 175 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 176 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 177 | case -NFS4ERR_FILE_OPEN: |
| 178 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 181 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 184 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * This is our standard bitmap for GETATTR requests. |
| 189 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 190 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | FATTR4_WORD0_TYPE |
| 192 | | FATTR4_WORD0_CHANGE |
| 193 | | FATTR4_WORD0_SIZE |
| 194 | | FATTR4_WORD0_FSID |
| 195 | | FATTR4_WORD0_FILEID, |
| 196 | FATTR4_WORD1_MODE |
| 197 | | FATTR4_WORD1_NUMLINKS |
| 198 | | FATTR4_WORD1_OWNER |
| 199 | | FATTR4_WORD1_OWNER_GROUP |
| 200 | | FATTR4_WORD1_RAWDEV |
| 201 | | FATTR4_WORD1_SPACE_USED |
| 202 | | FATTR4_WORD1_TIME_ACCESS |
| 203 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 204 | | FATTR4_WORD1_TIME_MODIFY |
| 205 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 206 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 207 | FATTR4_WORD2_SECURITY_LABEL |
| 208 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 211 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 212 | FATTR4_WORD0_TYPE |
| 213 | | FATTR4_WORD0_CHANGE |
| 214 | | FATTR4_WORD0_SIZE |
| 215 | | FATTR4_WORD0_FSID |
| 216 | | FATTR4_WORD0_FILEID, |
| 217 | FATTR4_WORD1_MODE |
| 218 | | FATTR4_WORD1_NUMLINKS |
| 219 | | FATTR4_WORD1_OWNER |
| 220 | | FATTR4_WORD1_OWNER_GROUP |
| 221 | | FATTR4_WORD1_RAWDEV |
| 222 | | FATTR4_WORD1_SPACE_USED |
| 223 | | FATTR4_WORD1_TIME_ACCESS |
| 224 | | FATTR4_WORD1_TIME_METADATA |
| 225 | | FATTR4_WORD1_TIME_MODIFY, |
| 226 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 227 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 228 | | FATTR4_WORD2_SECURITY_LABEL |
| 229 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 230 | }; |
| 231 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 232 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 233 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 234 | | FATTR4_WORD0_FILEID, |
| 235 | }; |
| 236 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 237 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | FATTR4_WORD0_FILES_AVAIL |
| 239 | | FATTR4_WORD0_FILES_FREE |
| 240 | | FATTR4_WORD0_FILES_TOTAL, |
| 241 | FATTR4_WORD1_SPACE_AVAIL |
| 242 | | FATTR4_WORD1_SPACE_FREE |
| 243 | | FATTR4_WORD1_SPACE_TOTAL |
| 244 | }; |
| 245 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 246 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | FATTR4_WORD0_MAXLINK |
| 248 | | FATTR4_WORD0_MAXNAME, |
| 249 | 0 |
| 250 | }; |
| 251 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 252 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | | FATTR4_WORD0_MAXREAD |
| 254 | | FATTR4_WORD0_MAXWRITE |
| 255 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 256 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 257 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 258 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 259 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 262 | const u32 nfs4_fs_locations_bitmap[3] = { |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 263 | FATTR4_WORD0_CHANGE |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 264 | | FATTR4_WORD0_SIZE |
| 265 | | FATTR4_WORD0_FSID |
| 266 | | FATTR4_WORD0_FILEID |
| 267 | | FATTR4_WORD0_FS_LOCATIONS, |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 268 | FATTR4_WORD1_OWNER |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 269 | | FATTR4_WORD1_OWNER_GROUP |
| 270 | | FATTR4_WORD1_RAWDEV |
| 271 | | FATTR4_WORD1_SPACE_USED |
| 272 | | FATTR4_WORD1_TIME_ACCESS |
| 273 | | FATTR4_WORD1_TIME_METADATA |
| 274 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 275 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 276 | }; |
| 277 | |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 278 | static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, |
| 279 | struct inode *inode) |
| 280 | { |
| 281 | unsigned long cache_validity; |
| 282 | |
| 283 | memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst)); |
| 284 | if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) |
| 285 | return; |
| 286 | |
| 287 | cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
| 288 | if (!(cache_validity & NFS_INO_REVAL_FORCED)) |
| 289 | cache_validity &= ~(NFS_INO_INVALID_CHANGE |
| 290 | | NFS_INO_INVALID_SIZE); |
| 291 | |
| 292 | if (!(cache_validity & NFS_INO_INVALID_SIZE)) |
| 293 | dst[0] &= ~FATTR4_WORD0_SIZE; |
| 294 | |
| 295 | if (!(cache_validity & NFS_INO_INVALID_CHANGE)) |
| 296 | dst[0] &= ~FATTR4_WORD0_CHANGE; |
| 297 | } |
| 298 | |
| 299 | static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, |
| 300 | const __u32 *src, struct inode *inode) |
| 301 | { |
| 302 | nfs4_bitmap_copy_adjust(dst, src, inode); |
| 303 | } |
| 304 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 305 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct nfs4_readdir_arg *readdir) |
| 307 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 308 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 309 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 312 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | readdir->cookie = 0; |
| 318 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 319 | if (cookie == 2) |
| 320 | return; |
| 321 | |
| 322 | /* |
| 323 | * NFSv4 servers do not return entries for '.' and '..' |
| 324 | * Therefore, we fake these entries here. We let '.' |
| 325 | * have cookie 0 and '..' have cookie 1. Note that |
| 326 | * when talking to the server, we always send cookie 0 |
| 327 | * instead of 1 or 2. |
| 328 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 329 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | if (cookie == 0) { |
| 332 | *p++ = xdr_one; /* next */ |
| 333 | *p++ = xdr_zero; /* cookie, first word */ |
| 334 | *p++ = xdr_one; /* cookie, second word */ |
| 335 | *p++ = xdr_one; /* entry len */ |
| 336 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 337 | p++; |
| 338 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 339 | *p++ = htonl(attrs); /* bitmap */ |
| 340 | *p++ = htonl(12); /* attribute buffer length */ |
| 341 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 342 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | *p++ = xdr_one; /* next */ |
| 346 | *p++ = xdr_zero; /* cookie, first word */ |
| 347 | *p++ = xdr_two; /* cookie, second word */ |
| 348 | *p++ = xdr_two; /* entry len */ |
| 349 | memcpy(p, "..\0\0", 4); /* entry */ |
| 350 | p++; |
| 351 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 352 | *p++ = htonl(attrs); /* bitmap */ |
| 353 | *p++ = htonl(12); /* attribute buffer length */ |
| 354 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 355 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | readdir->pgbase = (char *)p - (char *)start; |
| 358 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 359 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 362 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 363 | nfs4_stateid *stateid, |
| 364 | struct rpc_cred *cred) |
| 365 | { |
| 366 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 367 | |
| 368 | ops->test_and_free_expired(server, stateid, cred); |
| 369 | } |
| 370 | |
| 371 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 372 | nfs4_stateid *stateid, |
| 373 | struct rpc_cred *cred) |
| 374 | { |
| 375 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 376 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 377 | } |
| 378 | |
| 379 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 380 | const nfs4_stateid *stateid, |
| 381 | struct rpc_cred *cred) |
| 382 | { |
| 383 | nfs4_stateid tmp; |
| 384 | |
| 385 | nfs4_stateid_copy(&tmp, stateid); |
| 386 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 387 | } |
| 388 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 389 | static long nfs4_update_delay(long *timeout) |
| 390 | { |
| 391 | long ret; |
| 392 | if (!timeout) |
| 393 | return NFS4_POLL_RETRY_MAX; |
| 394 | if (*timeout <= 0) |
| 395 | *timeout = NFS4_POLL_RETRY_MIN; |
| 396 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 397 | *timeout = NFS4_POLL_RETRY_MAX; |
| 398 | ret = *timeout; |
| 399 | *timeout <<= 1; |
| 400 | return ret; |
| 401 | } |
| 402 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 404 | { |
| 405 | int res = 0; |
| 406 | |
| 407 | might_sleep(); |
| 408 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 409 | freezable_schedule_timeout_killable_unsafe( |
| 410 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 411 | if (fatal_signal_pending(current)) |
| 412 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 413 | return res; |
| 414 | } |
| 415 | |
| 416 | /* This is the error handling routine for processes that are allowed |
| 417 | * to sleep. |
| 418 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 419 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 420 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 421 | { |
| 422 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 423 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 424 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 425 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 426 | int ret = errorcode; |
| 427 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 428 | exception->delay = 0; |
| 429 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 430 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 431 | |
| 432 | if (stateid == NULL && state != NULL) |
| 433 | stateid = &state->stateid; |
| 434 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 435 | switch(errorcode) { |
| 436 | case 0: |
| 437 | return 0; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 438 | case -NFS4ERR_BADHANDLE: |
| 439 | case -ESTALE: |
| 440 | if (inode != NULL && S_ISREG(inode->i_mode)) |
| 441 | pnfs_destroy_layout(NFS_I(inode)); |
| 442 | break; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 443 | case -NFS4ERR_DELEG_REVOKED: |
| 444 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 445 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 446 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 447 | if (inode != NULL && stateid != NULL) { |
| 448 | nfs_inode_find_state_and_recover(inode, |
| 449 | stateid); |
| 450 | goto wait_on_recovery; |
| 451 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 452 | /* Fall through */ |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 453 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 454 | if (inode) { |
| 455 | int err; |
| 456 | |
| 457 | err = nfs_async_inode_return_delegation(inode, |
| 458 | stateid); |
| 459 | if (err == 0) |
| 460 | goto wait_on_recovery; |
| 461 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 462 | exception->retry = 1; |
| 463 | break; |
| 464 | } |
| 465 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 466 | if (state == NULL) |
| 467 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 468 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 469 | if (ret < 0) |
| 470 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 471 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 472 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 473 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 474 | nfs4_schedule_lease_recovery(clp); |
| 475 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 476 | case -NFS4ERR_MOVED: |
| 477 | ret = nfs4_schedule_migration_recovery(server); |
| 478 | if (ret < 0) |
| 479 | break; |
| 480 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 481 | case -NFS4ERR_LEASE_MOVED: |
| 482 | nfs4_schedule_lease_moved_recovery(clp); |
| 483 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 484 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 485 | case -NFS4ERR_BADSESSION: |
| 486 | case -NFS4ERR_BADSLOT: |
| 487 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 488 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 489 | case -NFS4ERR_DEADSESSION: |
| 490 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 491 | case -NFS4ERR_SEQ_MISORDERED: |
| 492 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 493 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 494 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 495 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 496 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 497 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 498 | if (exception->timeout > HZ) { |
| 499 | /* We have retried a decent amount, time to |
| 500 | * fail |
| 501 | */ |
| 502 | ret = -EBUSY; |
| 503 | break; |
| 504 | } |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 505 | /* Fall through */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 506 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 507 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 508 | /* Fall through */ |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 509 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 510 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 511 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 512 | exception->delay = 1; |
| 513 | return 0; |
| 514 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 515 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 516 | case -NFS4ERR_OLD_STATEID: |
| 517 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 518 | break; |
| 519 | case -NFS4ERR_BADOWNER: |
| 520 | /* The following works around a Linux server bug! */ |
| 521 | case -NFS4ERR_BADNAME: |
| 522 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 523 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 524 | exception->retry = 1; |
| 525 | printk(KERN_WARNING "NFS: v4 server %s " |
| 526 | "does not accept raw " |
| 527 | "uid/gids. " |
| 528 | "Reenabling the idmapper.\n", |
| 529 | server->nfs_client->cl_hostname); |
| 530 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 531 | } |
| 532 | /* We failed to handle the error */ |
| 533 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 534 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 535 | exception->recovering = 1; |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | /* This is the error handling routine for processes that are allowed |
| 540 | * to sleep. |
| 541 | */ |
| 542 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 543 | { |
| 544 | struct nfs_client *clp = server->nfs_client; |
| 545 | int ret; |
| 546 | |
| 547 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 548 | if (exception->delay) { |
| 549 | ret = nfs4_delay(server->client, &exception->timeout); |
| 550 | goto out_retry; |
| 551 | } |
| 552 | if (exception->recovering) { |
| 553 | ret = nfs4_wait_clnt_recover(clp); |
| 554 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 555 | return -EIO; |
| 556 | goto out_retry; |
| 557 | } |
| 558 | return ret; |
| 559 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 560 | if (ret == 0) |
| 561 | exception->retry = 1; |
| 562 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 563 | } |
| 564 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 565 | static int |
| 566 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 567 | int errorcode, struct nfs4_exception *exception) |
| 568 | { |
| 569 | struct nfs_client *clp = server->nfs_client; |
| 570 | int ret; |
| 571 | |
| 572 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 573 | if (exception->delay) { |
| 574 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 575 | goto out_retry; |
| 576 | } |
| 577 | if (exception->recovering) { |
| 578 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 579 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 580 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 581 | goto out_retry; |
| 582 | } |
| 583 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 584 | ret = -EIO; |
| 585 | return ret; |
| 586 | out_retry: |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 587 | if (ret == 0) { |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 588 | exception->retry = 1; |
Bill Baker | 0f90be1 | 2018-06-19 16:24:58 -0500 | [diff] [blame] | 589 | /* |
| 590 | * For NFS4ERR_MOVED, the client transport will need to |
| 591 | * be recomputed after migration recovery has completed. |
| 592 | */ |
| 593 | if (errorcode == -NFS4ERR_MOVED) |
| 594 | rpc_task_release_transport(task); |
| 595 | } |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 596 | return ret; |
| 597 | } |
| 598 | |
Olga Kornievskaia | 0f913a5 | 2018-07-09 15:13:33 -0400 | [diff] [blame] | 599 | int |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 600 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 601 | struct nfs4_state *state, long *timeout) |
| 602 | { |
| 603 | struct nfs4_exception exception = { |
| 604 | .state = state, |
| 605 | }; |
| 606 | |
| 607 | if (task->tk_status >= 0) |
| 608 | return 0; |
| 609 | if (timeout) |
| 610 | exception.timeout = *timeout; |
| 611 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 612 | task->tk_status, |
| 613 | &exception); |
| 614 | if (exception.delay && timeout) |
| 615 | *timeout = exception.timeout; |
| 616 | if (exception.retry) |
| 617 | return -EAGAIN; |
| 618 | return 0; |
| 619 | } |
| 620 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 621 | /* |
| 622 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 623 | * or 'false' otherwise. |
| 624 | */ |
| 625 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 626 | { |
| 627 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 628 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 629 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 630 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 631 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | spin_lock(&clp->cl_lock); |
| 634 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 635 | clp->cl_last_renewal = timestamp; |
| 636 | spin_unlock(&clp->cl_lock); |
| 637 | } |
| 638 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 639 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 640 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 641 | struct nfs_client *clp = server->nfs_client; |
| 642 | |
| 643 | if (!nfs4_has_session(clp)) |
| 644 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 645 | } |
| 646 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 647 | struct nfs4_call_sync_data { |
| 648 | const struct nfs_server *seq_server; |
| 649 | struct nfs4_sequence_args *seq_args; |
| 650 | struct nfs4_sequence_res *seq_res; |
| 651 | }; |
| 652 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 653 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 654 | struct nfs4_sequence_res *res, int cache_reply, |
| 655 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 656 | { |
| 657 | args->sa_slot = NULL; |
| 658 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 659 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 660 | |
| 661 | res->sr_slot = NULL; |
| 662 | } |
| 663 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 664 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 665 | { |
| 666 | struct nfs4_slot *slot = res->sr_slot; |
| 667 | struct nfs4_slot_table *tbl; |
| 668 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 669 | tbl = slot->table; |
| 670 | spin_lock(&tbl->slot_tbl_lock); |
| 671 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 672 | nfs4_free_slot(tbl, slot); |
| 673 | spin_unlock(&tbl->slot_tbl_lock); |
| 674 | |
| 675 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static int nfs40_sequence_done(struct rpc_task *task, |
| 679 | struct nfs4_sequence_res *res) |
| 680 | { |
| 681 | if (res->sr_slot != NULL) |
| 682 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 683 | return 1; |
| 684 | } |
| 685 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 686 | #if defined(CONFIG_NFS_V4_1) |
| 687 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 688 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 689 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 690 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 691 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 692 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 693 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 694 | if (!slot) |
| 695 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 696 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 697 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 698 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 699 | /* Bump the slot sequence number */ |
| 700 | if (slot->seq_done) |
| 701 | slot->seq_nr++; |
| 702 | slot->seq_done = 0; |
| 703 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 704 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 705 | /* Be nice to the server: try to ensure that the last transmitted |
| 706 | * value for highest_user_slotid <= target_highest_slotid |
| 707 | */ |
| 708 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 709 | send_new_highest_used_slotid = true; |
| 710 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 711 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 712 | send_new_highest_used_slotid = false; |
| 713 | goto out_unlock; |
| 714 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 715 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 716 | |
| 717 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 718 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 719 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 720 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 721 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 722 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 723 | if (waitqueue_active(&tbl->slot_waitq)) |
| 724 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 725 | } |
| 726 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 727 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 728 | { |
| 729 | nfs41_release_slot(res->sr_slot); |
| 730 | res->sr_slot = NULL; |
| 731 | } |
| 732 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 733 | static int nfs41_sequence_process(struct rpc_task *task, |
| 734 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 735 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 736 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 737 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 738 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 739 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 740 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 741 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 742 | if (slot == NULL) |
| 743 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 744 | /* don't increment the sequence number if the task wasn't sent */ |
| 745 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 746 | goto out; |
| 747 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 748 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 749 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 750 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 751 | if (res->sr_status != -NFS4ERR_DELAY) |
| 752 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 753 | interrupted = true; |
| 754 | } |
| 755 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 756 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 757 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 758 | switch (res->sr_status) { |
| 759 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 760 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 761 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 762 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 763 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 764 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 765 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 766 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 767 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 768 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 769 | case 1: |
| 770 | /* |
| 771 | * sr_status remains 1 if an RPC level error occurred. |
| 772 | * The server may or may not have processed the sequence |
| 773 | * operation.. |
| 774 | * Mark the slot as having hosted an interrupted RPC call. |
| 775 | */ |
| 776 | slot->interrupted = 1; |
| 777 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 778 | case -NFS4ERR_DELAY: |
| 779 | /* The server detected a resend of the RPC call and |
| 780 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 781 | * of RFC5661. |
| 782 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 783 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 784 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 785 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 786 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 787 | goto out_retry; |
Trond Myklebust | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 788 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 789 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 790 | /* |
| 791 | * The server thinks we tried to replay a request. |
| 792 | * Retry the call after bumping the sequence ID. |
| 793 | */ |
| 794 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 795 | case -NFS4ERR_BADSLOT: |
| 796 | /* |
| 797 | * The slot id we used was probably retired. Try again |
| 798 | * using a different slot id. |
| 799 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 800 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 801 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 802 | goto retry_nowait; |
| 803 | case -NFS4ERR_SEQ_MISORDERED: |
| 804 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 805 | * Was the last operation on this sequence interrupted? |
| 806 | * If so, retry after bumping the sequence number. |
| 807 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 808 | if (interrupted) |
| 809 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 810 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 811 | * Could this slot have been previously retired? |
| 812 | * If so, then the server may be expecting seq_nr = 1! |
| 813 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 814 | if (slot->seq_nr != 1) { |
| 815 | slot->seq_nr = 1; |
| 816 | goto retry_nowait; |
| 817 | } |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 818 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 819 | default: |
| 820 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 821 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 822 | } |
| 823 | out: |
| 824 | /* The session may be reset by one of the error handlers. */ |
| 825 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 826 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 827 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 828 | session_recover: |
| 829 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 830 | goto retry_nowait; |
| 831 | retry_new_seq: |
| 832 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 833 | retry_nowait: |
| 834 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 835 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 836 | task->tk_status = 0; |
| 837 | ret = 0; |
| 838 | } |
| 839 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 841 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 842 | goto out; |
| 843 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 844 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 845 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 846 | |
| 847 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 848 | { |
| 849 | if (!nfs41_sequence_process(task, res)) |
| 850 | return 0; |
| 851 | if (res->sr_slot != NULL) |
| 852 | nfs41_sequence_free_slot(res); |
| 853 | return 1; |
| 854 | |
| 855 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 856 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 857 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 858 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 859 | { |
| 860 | if (res->sr_slot == NULL) |
| 861 | return 1; |
| 862 | if (res->sr_slot->table->session != NULL) |
| 863 | return nfs41_sequence_process(task, res); |
| 864 | return nfs40_sequence_done(task, res); |
| 865 | } |
| 866 | |
| 867 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 868 | { |
| 869 | if (res->sr_slot != NULL) { |
| 870 | if (res->sr_slot->table->session != NULL) |
| 871 | nfs41_sequence_free_slot(res); |
| 872 | else |
| 873 | nfs40_sequence_free_slot(res); |
| 874 | } |
| 875 | } |
| 876 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 877 | 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] | 878 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 879 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 880 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 881 | if (!res->sr_slot->table->session) |
| 882 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 883 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 884 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 885 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 886 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 887 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 888 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 889 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 890 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 891 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 892 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 893 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 894 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 895 | } |
| 896 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 897 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 898 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 899 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 900 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 901 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 902 | } |
| 903 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 904 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 905 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 906 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 907 | }; |
| 908 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 909 | static void |
| 910 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 911 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 912 | { |
| 913 | struct rpc_task *task; |
| 914 | |
| 915 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 916 | if (!IS_ERR(task)) |
| 917 | rpc_put_task_async(task); |
| 918 | } |
| 919 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 920 | #else /* !CONFIG_NFS_V4_1 */ |
| 921 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 922 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 923 | { |
| 924 | return nfs40_sequence_done(task, res); |
| 925 | } |
| 926 | |
| 927 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 928 | { |
| 929 | if (res->sr_slot != NULL) |
| 930 | nfs40_sequence_free_slot(res); |
| 931 | } |
| 932 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 933 | int nfs4_sequence_done(struct rpc_task *task, |
| 934 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 935 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 936 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 937 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 938 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 939 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 940 | static void |
| 941 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 942 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 943 | { |
| 944 | WARN_ON_ONCE(1); |
| 945 | slot->interrupted = 0; |
| 946 | } |
| 947 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 948 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 949 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 950 | static |
| 951 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 952 | struct nfs4_sequence_res *res, |
| 953 | struct nfs4_slot *slot) |
| 954 | { |
| 955 | if (!slot) |
| 956 | return; |
| 957 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 958 | args->sa_slot = slot; |
| 959 | |
| 960 | res->sr_slot = slot; |
| 961 | res->sr_timestamp = jiffies; |
| 962 | res->sr_status_flags = 0; |
| 963 | res->sr_status = 1; |
| 964 | |
| 965 | } |
| 966 | |
| 967 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 968 | struct nfs4_sequence_args *args, |
| 969 | struct nfs4_sequence_res *res, |
| 970 | struct rpc_task *task) |
| 971 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 972 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 973 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 974 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 975 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 976 | /* slot already allocated? */ |
| 977 | if (res->sr_slot != NULL) |
| 978 | goto out_start; |
| 979 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 980 | if (session) { |
| 981 | tbl = &session->fc_slot_table; |
| 982 | task->tk_timeout = 0; |
| 983 | } |
| 984 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 985 | for (;;) { |
| 986 | spin_lock(&tbl->slot_tbl_lock); |
| 987 | /* The state manager will wait until the slot table is empty */ |
| 988 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 989 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 990 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 991 | slot = nfs4_alloc_slot(tbl); |
| 992 | if (IS_ERR(slot)) { |
| 993 | /* Try again in 1/4 second */ |
| 994 | if (slot == ERR_PTR(-ENOMEM)) |
| 995 | task->tk_timeout = HZ >> 2; |
| 996 | goto out_sleep; |
| 997 | } |
| 998 | spin_unlock(&tbl->slot_tbl_lock); |
| 999 | |
| 1000 | if (likely(!slot->interrupted)) |
| 1001 | break; |
| 1002 | nfs4_sequence_process_interrupted(client, |
| 1003 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1004 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1005 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 1006 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 1007 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 1008 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 1009 | out_start: |
| 1010 | rpc_call_start(task); |
| 1011 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1012 | |
| 1013 | out_sleep: |
| 1014 | if (args->sa_privileged) |
| 1015 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 1016 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 1017 | else |
| 1018 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1019 | spin_unlock(&tbl->slot_tbl_lock); |
| 1020 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1021 | } |
| 1022 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1023 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1024 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1025 | { |
| 1026 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1027 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1028 | data->seq_args, data->seq_res, task); |
| 1029 | } |
| 1030 | |
| 1031 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1032 | { |
| 1033 | struct nfs4_call_sync_data *data = calldata; |
| 1034 | nfs4_sequence_done(task, data->seq_res); |
| 1035 | } |
| 1036 | |
| 1037 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1038 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1039 | .rpc_call_done = nfs40_call_sync_done, |
| 1040 | }; |
| 1041 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1042 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1043 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1044 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1045 | struct nfs4_sequence_args *args, |
| 1046 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1047 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1048 | int ret; |
| 1049 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1050 | struct nfs_client *clp = server->nfs_client; |
| 1051 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1052 | .seq_server = server, |
| 1053 | .seq_args = args, |
| 1054 | .seq_res = res, |
| 1055 | }; |
| 1056 | struct rpc_task_setup task_setup = { |
| 1057 | .rpc_client = clnt, |
| 1058 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1059 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1060 | .callback_data = &data |
| 1061 | }; |
| 1062 | |
| 1063 | task = rpc_run_task(&task_setup); |
| 1064 | if (IS_ERR(task)) |
| 1065 | ret = PTR_ERR(task); |
| 1066 | else { |
| 1067 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1068 | rpc_put_task(task); |
| 1069 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1070 | return ret; |
| 1071 | } |
| 1072 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1073 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1074 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1075 | struct rpc_message *msg, |
| 1076 | struct nfs4_sequence_args *args, |
| 1077 | struct nfs4_sequence_res *res, |
| 1078 | int cache_reply) |
| 1079 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1080 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1081 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1084 | static void |
| 1085 | nfs4_inc_nlink_locked(struct inode *inode) |
| 1086 | { |
| 1087 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1088 | inc_nlink(inode); |
| 1089 | } |
| 1090 | |
| 1091 | static void |
| 1092 | nfs4_dec_nlink_locked(struct inode *inode) |
| 1093 | { |
| 1094 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; |
| 1095 | drop_nlink(inode); |
| 1096 | } |
| 1097 | |
| 1098 | static void |
| 1099 | update_changeattr_locked(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1100 | unsigned long timestamp, unsigned long cache_validity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | { |
| 1102 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1103 | |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1104 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1105 | | NFS_INO_INVALID_MTIME |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1106 | | NFS_INO_INVALID_DATA |
| 1107 | | cache_validity; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1108 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1109 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1110 | nfsi->attrtimeo_timestamp = jiffies; |
| 1111 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1113 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1114 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1115 | NFS_INO_INVALID_ACL; |
| 1116 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1117 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1118 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1119 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
Trond Myklebust | c8d0715 | 2018-07-31 15:54:12 -0400 | [diff] [blame] | 1120 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1121 | nfs_fscache_invalidate(dir); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | static void |
| 1125 | update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1126 | unsigned long timestamp, unsigned long cache_validity) |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 1127 | { |
| 1128 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 1129 | update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | spin_unlock(&dir->i_lock); |
| 1131 | } |
| 1132 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1133 | struct nfs4_open_createattrs { |
| 1134 | struct nfs4_label *label; |
| 1135 | struct iattr *sattr; |
| 1136 | const __u32 verf[2]; |
| 1137 | }; |
| 1138 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1139 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1140 | int err, struct nfs4_exception *exception) |
| 1141 | { |
| 1142 | if (err != -EINVAL) |
| 1143 | return false; |
| 1144 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1145 | return false; |
| 1146 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1147 | exception->retry = 1; |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1151 | static u32 |
| 1152 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1153 | fmode_t fmode, int openflags) |
| 1154 | { |
| 1155 | u32 res = 0; |
| 1156 | |
| 1157 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1158 | case FMODE_READ: |
| 1159 | res = NFS4_SHARE_ACCESS_READ; |
| 1160 | break; |
| 1161 | case FMODE_WRITE: |
| 1162 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1163 | break; |
| 1164 | case FMODE_READ|FMODE_WRITE: |
| 1165 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1166 | } |
| 1167 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1168 | goto out; |
| 1169 | /* Want no delegation if we're using O_DIRECT */ |
| 1170 | if (openflags & O_DIRECT) |
| 1171 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1172 | out: |
| 1173 | return res; |
| 1174 | } |
| 1175 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1176 | static enum open_claim_type4 |
| 1177 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1178 | enum open_claim_type4 claim) |
| 1179 | { |
| 1180 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1181 | return claim; |
| 1182 | switch (claim) { |
| 1183 | default: |
| 1184 | return claim; |
| 1185 | case NFS4_OPEN_CLAIM_FH: |
| 1186 | return NFS4_OPEN_CLAIM_NULL; |
| 1187 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1188 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1189 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1190 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1191 | } |
| 1192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | { |
| 1196 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1197 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1198 | p->o_res.seqid = p->o_arg.seqid; |
| 1199 | p->c_res.seqid = p->c_arg.seqid; |
| 1200 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1201 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1202 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1203 | 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] | 1204 | } |
| 1205 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1206 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1207 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1208 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1209 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1210 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1211 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1212 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1213 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1214 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1215 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1216 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1217 | struct nfs4_opendata *p; |
| 1218 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1219 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | if (p == NULL) |
| 1221 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1222 | |
| 1223 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1224 | if (IS_ERR(p->f_label)) |
| 1225 | goto err_free_p; |
| 1226 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1227 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1228 | if (IS_ERR(p->a_label)) |
| 1229 | goto err_free_f; |
| 1230 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1231 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1232 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1233 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1234 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1235 | nfs_sb_active(dentry->d_sb); |
| 1236 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1237 | p->dir = parent; |
| 1238 | p->owner = sp; |
| 1239 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1240 | p->o_arg.open_flags = flags; |
| 1241 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1242 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1243 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1244 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1245 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1246 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1247 | * will return permission denied for all bits until close */ |
| 1248 | if (!(flags & O_EXCL)) { |
| 1249 | /* ask server to check for all possible rights as results |
| 1250 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1251 | switch (p->o_arg.claim) { |
| 1252 | default: |
| 1253 | break; |
| 1254 | case NFS4_OPEN_CLAIM_NULL: |
| 1255 | case NFS4_OPEN_CLAIM_FH: |
| 1256 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1257 | NFS4_ACCESS_MODIFY | |
| 1258 | NFS4_ACCESS_EXTEND | |
| 1259 | NFS4_ACCESS_EXECUTE; |
| 1260 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1261 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1262 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1263 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1264 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1265 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1266 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1267 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1268 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1269 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1270 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1271 | case NFS4_OPEN_CLAIM_NULL: |
| 1272 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1273 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1274 | p->o_arg.fh = NFS_FH(dir); |
| 1275 | break; |
| 1276 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1277 | case NFS4_OPEN_CLAIM_FH: |
| 1278 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1279 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1280 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1281 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1282 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1283 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1284 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1285 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1286 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1287 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1288 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1289 | p->c_arg.fh = &p->o_res.fh; |
| 1290 | p->c_arg.stateid = &p->o_res.stateid; |
| 1291 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1292 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1293 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1294 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1295 | |
| 1296 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1297 | nfs4_label_free(p->a_label); |
| 1298 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1299 | nfs4_label_free(p->f_label); |
| 1300 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | kfree(p); |
| 1302 | err: |
| 1303 | dput(parent); |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1307 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1308 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1309 | struct nfs4_opendata *p = container_of(kref, |
| 1310 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1311 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1312 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1313 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1314 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1315 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1316 | if (p->state != NULL) |
| 1317 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1318 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1319 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1320 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1321 | nfs4_label_free(p->f_label); |
| 1322 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1323 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1324 | dput(p->dentry); |
| 1325 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1326 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1327 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1328 | kfree(p); |
| 1329 | } |
| 1330 | |
| 1331 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1332 | { |
| 1333 | if (p != NULL) |
| 1334 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1335 | } |
| 1336 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1337 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1338 | fmode_t fmode) |
| 1339 | { |
| 1340 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1341 | case FMODE_READ|FMODE_WRITE: |
| 1342 | return state->n_rdwr != 0; |
| 1343 | case FMODE_WRITE: |
| 1344 | return state->n_wronly != 0; |
| 1345 | case FMODE_READ: |
| 1346 | return state->n_rdonly != 0; |
| 1347 | } |
| 1348 | WARN_ON_ONCE(1); |
| 1349 | return false; |
| 1350 | } |
| 1351 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1352 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1353 | { |
| 1354 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1356 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | goto out; |
| 1358 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1359 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1360 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1361 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1362 | break; |
| 1363 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1364 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1365 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1366 | break; |
| 1367 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1368 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1369 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1370 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1372 | return ret; |
| 1373 | } |
| 1374 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1375 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1376 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1377 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1378 | if (delegation == NULL) |
| 1379 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1380 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1381 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1382 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1383 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1384 | switch (claim) { |
| 1385 | case NFS4_OPEN_CLAIM_NULL: |
| 1386 | case NFS4_OPEN_CLAIM_FH: |
| 1387 | break; |
| 1388 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1389 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1390 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 1391 | /* Fall through */ |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1392 | default: |
| 1393 | return 0; |
| 1394 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1395 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1396 | return 1; |
| 1397 | } |
| 1398 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1399 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1400 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1401 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1402 | case FMODE_WRITE: |
| 1403 | state->n_wronly++; |
| 1404 | break; |
| 1405 | case FMODE_READ: |
| 1406 | state->n_rdonly++; |
| 1407 | break; |
| 1408 | case FMODE_READ|FMODE_WRITE: |
| 1409 | state->n_rdwr++; |
| 1410 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1411 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1412 | } |
| 1413 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1414 | #ifdef CONFIG_NFS_V4_1 |
| 1415 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1416 | { |
| 1417 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1418 | return true; |
| 1419 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1420 | return true; |
| 1421 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1422 | return true; |
| 1423 | return false; |
| 1424 | } |
| 1425 | #endif /* CONFIG_NFS_V4_1 */ |
| 1426 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1427 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1428 | { |
| 1429 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1430 | wake_up_all(&state->waitq); |
| 1431 | } |
| 1432 | |
| 1433 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1434 | const nfs4_stateid *stateid) |
| 1435 | { |
| 1436 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1437 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1438 | |
| 1439 | if (stateid_seqid == state_seqid + 1U || |
| 1440 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1441 | nfs_state_log_update_open_stateid(state); |
| 1442 | else |
| 1443 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1444 | } |
| 1445 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1446 | 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] | 1447 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1448 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1449 | bool need_recover = false; |
| 1450 | |
| 1451 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1452 | need_recover = true; |
| 1453 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1454 | need_recover = true; |
| 1455 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1456 | need_recover = true; |
| 1457 | if (need_recover) |
| 1458 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1459 | } |
| 1460 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1461 | /* |
| 1462 | * Check for whether or not the caller may update the open stateid |
| 1463 | * to the value passed in by stateid. |
| 1464 | * |
| 1465 | * Note: This function relies heavily on the server implementing |
| 1466 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1467 | * correctly. |
| 1468 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1469 | * are then incremented on every state transition. |
| 1470 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1471 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1472 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1473 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1474 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1475 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1476 | if (stateid->seqid == cpu_to_be32(1)) |
| 1477 | nfs_state_log_update_open_stateid(state); |
| 1478 | else |
| 1479 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1480 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1481 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1482 | |
| 1483 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1484 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1485 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1486 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1487 | return false; |
| 1488 | } |
| 1489 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1490 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1491 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1492 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1493 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1494 | if (state->n_wronly) |
| 1495 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1496 | if (state->n_rdonly) |
| 1497 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1498 | if (state->n_rdwr) |
| 1499 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1500 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1503 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1504 | nfs4_stateid *stateid, fmode_t fmode) |
| 1505 | { |
| 1506 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1507 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1508 | case FMODE_WRITE: |
| 1509 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1510 | break; |
| 1511 | case FMODE_READ: |
| 1512 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1513 | break; |
| 1514 | case 0: |
| 1515 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1516 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1517 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1518 | } |
| 1519 | if (stateid == NULL) |
| 1520 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1521 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1522 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1523 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1524 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1525 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1526 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1527 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1528 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1529 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1530 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1531 | out: |
| 1532 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1533 | } |
| 1534 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1535 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1536 | nfs4_stateid *arg_stateid, |
| 1537 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1538 | { |
| 1539 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1540 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1541 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1542 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1543 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1544 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1545 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1548 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1549 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1550 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1551 | DEFINE_WAIT(wait); |
| 1552 | int status = 0; |
| 1553 | for (;;) { |
| 1554 | |
| 1555 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1556 | return; |
| 1557 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1558 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1559 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1560 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1561 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1562 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1563 | break; |
| 1564 | |
| 1565 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1566 | /* |
| 1567 | * Ensure we process the state changes in the same order |
| 1568 | * in which the server processed them by delaying the |
| 1569 | * update of the stateid until we are in sequence. |
| 1570 | */ |
| 1571 | write_sequnlock(&state->seqlock); |
| 1572 | spin_unlock(&state->owner->so_lock); |
| 1573 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1574 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1575 | if (!signal_pending(current)) { |
| 1576 | if (schedule_timeout(5*HZ) == 0) |
| 1577 | status = -EAGAIN; |
| 1578 | else |
| 1579 | status = 0; |
| 1580 | } else |
| 1581 | status = -EINTR; |
| 1582 | finish_wait(&state->waitq, &wait); |
| 1583 | rcu_read_lock(); |
| 1584 | spin_lock(&state->owner->so_lock); |
| 1585 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1586 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1587 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1588 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1589 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1590 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1591 | nfs_test_and_clear_all_open_stateid(state); |
| 1592 | } |
| 1593 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1594 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1595 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1596 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1597 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1598 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1601 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1602 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1603 | fmode_t fmode, |
| 1604 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1606 | /* |
| 1607 | * Protect the call to nfs4_state_set_mode_locked and |
| 1608 | * serialise the stateid update |
| 1609 | */ |
| 1610 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1611 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1612 | switch (fmode) { |
| 1613 | case FMODE_READ: |
| 1614 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1615 | break; |
| 1616 | case FMODE_WRITE: |
| 1617 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1618 | break; |
| 1619 | case FMODE_READ|FMODE_WRITE: |
| 1620 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1621 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1622 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1623 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1627 | const nfs4_stateid *deleg_stateid, |
| 1628 | fmode_t fmode) |
| 1629 | { |
| 1630 | /* |
| 1631 | * Protect the call to nfs4_state_set_mode_locked and |
| 1632 | * serialise the stateid update |
| 1633 | */ |
| 1634 | write_seqlock(&state->seqlock); |
| 1635 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1636 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1637 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1640 | static int update_open_stateid(struct nfs4_state *state, |
| 1641 | const nfs4_stateid *open_stateid, |
| 1642 | const nfs4_stateid *delegation, |
| 1643 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1644 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1645 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1646 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1647 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1648 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1649 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1650 | int ret = 0; |
| 1651 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1652 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1653 | |
| 1654 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1655 | spin_lock(&state->owner->so_lock); |
| 1656 | if (open_stateid != NULL) { |
| 1657 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1658 | ret = 1; |
| 1659 | } |
| 1660 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1661 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1662 | if (deleg_cur == NULL) |
| 1663 | goto no_delegation; |
| 1664 | |
| 1665 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1666 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1667 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1668 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1669 | goto no_delegation_unlock; |
| 1670 | |
| 1671 | if (delegation == NULL) |
| 1672 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1673 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1674 | goto no_delegation_unlock; |
| 1675 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1676 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1677 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1678 | ret = 1; |
| 1679 | no_delegation_unlock: |
| 1680 | spin_unlock(&deleg_cur->lock); |
| 1681 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1682 | if (ret) |
| 1683 | update_open_stateflags(state, fmode); |
| 1684 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1685 | rcu_read_unlock(); |
| 1686 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1687 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1688 | nfs4_schedule_state_manager(clp); |
| 1689 | if (freeme.type != 0) |
| 1690 | nfs4_test_and_free_stateid(server, &freeme, |
| 1691 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1692 | |
| 1693 | return ret; |
| 1694 | } |
| 1695 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1696 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1697 | const nfs4_stateid *stateid) |
| 1698 | { |
| 1699 | struct nfs4_state *state = lsp->ls_state; |
| 1700 | bool ret = false; |
| 1701 | |
| 1702 | spin_lock(&state->state_lock); |
| 1703 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1704 | goto out_noupdate; |
| 1705 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1706 | goto out_noupdate; |
| 1707 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1708 | ret = true; |
| 1709 | out_noupdate: |
| 1710 | spin_unlock(&state->state_lock); |
| 1711 | return ret; |
| 1712 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1713 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1714 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1715 | { |
| 1716 | struct nfs_delegation *delegation; |
| 1717 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1718 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | rcu_read_lock(); |
| 1720 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1721 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1722 | rcu_read_unlock(); |
| 1723 | return; |
| 1724 | } |
| 1725 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1726 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1727 | } |
| 1728 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1729 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1730 | { |
| 1731 | struct nfs4_state *state = opendata->state; |
| 1732 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1733 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1734 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1735 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1736 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1737 | nfs4_stateid stateid; |
| 1738 | int ret = -EAGAIN; |
| 1739 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1740 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1741 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1742 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1743 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1744 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1745 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1746 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1747 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1748 | rcu_read_lock(); |
| 1749 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1750 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1751 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1752 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1753 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1754 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1755 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1756 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1757 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1758 | if (!opendata->is_recover) { |
| 1759 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1760 | if (ret != 0) |
| 1761 | goto out; |
| 1762 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1763 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1764 | |
| 1765 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1766 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1767 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1768 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1769 | out: |
| 1770 | return ERR_PTR(ret); |
| 1771 | out_return_state: |
| 1772 | atomic_inc(&state->count); |
| 1773 | return state; |
| 1774 | } |
| 1775 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1776 | static void |
| 1777 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1778 | { |
| 1779 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1780 | struct nfs_delegation *delegation; |
| 1781 | int delegation_flags = 0; |
| 1782 | |
| 1783 | rcu_read_lock(); |
| 1784 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1785 | if (delegation) |
| 1786 | delegation_flags = delegation->flags; |
| 1787 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1788 | switch (data->o_arg.claim) { |
| 1789 | default: |
| 1790 | break; |
| 1791 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1792 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1793 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1794 | "returning a delegation for " |
| 1795 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1796 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1797 | return; |
| 1798 | } |
| 1799 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1800 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1801 | data->owner->so_cred, |
| 1802 | data->o_res.delegation_type, |
| 1803 | &data->o_res.delegation, |
| 1804 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1805 | else |
| 1806 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1807 | data->owner->so_cred, |
| 1808 | data->o_res.delegation_type, |
| 1809 | &data->o_res.delegation, |
| 1810 | data->o_res.pagemod_limit); |
Jeff Layton | 8b199e5 | 2018-07-05 05:48:14 -0400 | [diff] [blame] | 1811 | |
| 1812 | if (data->o_res.do_recall) |
| 1813 | nfs_async_inode_return_delegation(state->inode, |
| 1814 | &data->o_res.delegation); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /* |
| 1818 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1819 | * and update the nfs4_state. |
| 1820 | */ |
| 1821 | static struct nfs4_state * |
| 1822 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1823 | { |
| 1824 | struct inode *inode = data->state->inode; |
| 1825 | struct nfs4_state *state = data->state; |
| 1826 | int ret; |
| 1827 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1828 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1829 | if (data->rpc_status) |
| 1830 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1831 | /* cached opens have already been processed */ |
| 1832 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1833 | } |
| 1834 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1835 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1836 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1837 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1838 | |
| 1839 | if (data->o_res.delegation_type != 0) |
| 1840 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1841 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1842 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1843 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1844 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1845 | |
| 1846 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1847 | } |
| 1848 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1849 | static struct inode * |
| 1850 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1851 | { |
| 1852 | struct inode *inode; |
| 1853 | |
| 1854 | switch (data->o_arg.claim) { |
| 1855 | case NFS4_OPEN_CLAIM_NULL: |
| 1856 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1857 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1858 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1859 | return ERR_PTR(-EAGAIN); |
| 1860 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1861 | &data->f_attr, data->f_label); |
| 1862 | break; |
| 1863 | default: |
| 1864 | inode = d_inode(data->dentry); |
| 1865 | ihold(inode); |
| 1866 | nfs_refresh_inode(inode, &data->f_attr); |
| 1867 | } |
| 1868 | return inode; |
| 1869 | } |
| 1870 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1871 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1872 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1873 | { |
| 1874 | struct nfs4_state *state; |
| 1875 | struct inode *inode; |
| 1876 | |
| 1877 | inode = nfs4_opendata_get_inode(data); |
| 1878 | if (IS_ERR(inode)) |
| 1879 | return ERR_CAST(inode); |
| 1880 | if (data->state != NULL && data->state->inode == inode) { |
| 1881 | state = data->state; |
| 1882 | atomic_inc(&state->count); |
| 1883 | } else |
| 1884 | state = nfs4_get_open_state(inode, data->owner); |
| 1885 | iput(inode); |
| 1886 | if (state == NULL) |
| 1887 | state = ERR_PTR(-ENOMEM); |
| 1888 | return state; |
| 1889 | } |
| 1890 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1891 | static struct nfs4_state * |
| 1892 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1893 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1894 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1895 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1896 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1897 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1898 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1899 | goto out; |
| 1900 | } |
| 1901 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1902 | state = nfs4_opendata_find_nfs4_state(data); |
| 1903 | if (IS_ERR(state)) |
| 1904 | goto out; |
| 1905 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1906 | if (data->o_res.delegation_type != 0) |
| 1907 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1908 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1909 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1910 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1911 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1912 | return state; |
| 1913 | } |
| 1914 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1915 | static struct nfs4_state * |
| 1916 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1917 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1918 | struct nfs4_state *ret; |
| 1919 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1920 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1921 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1922 | else |
| 1923 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1924 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1925 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1926 | } |
| 1927 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1928 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1929 | { |
| 1930 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1931 | struct nfs_open_context *ctx; |
| 1932 | |
| 1933 | spin_lock(&state->inode->i_lock); |
| 1934 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1935 | if (ctx->state != state) |
| 1936 | continue; |
| 1937 | get_nfs_open_context(ctx); |
| 1938 | spin_unlock(&state->inode->i_lock); |
| 1939 | return ctx; |
| 1940 | } |
| 1941 | spin_unlock(&state->inode->i_lock); |
| 1942 | return ERR_PTR(-ENOENT); |
| 1943 | } |
| 1944 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1945 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1946 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1947 | { |
| 1948 | struct nfs4_opendata *opendata; |
| 1949 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1950 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1951 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1952 | if (opendata == NULL) |
| 1953 | return ERR_PTR(-ENOMEM); |
| 1954 | opendata->state = state; |
| 1955 | atomic_inc(&state->count); |
| 1956 | return opendata; |
| 1957 | } |
| 1958 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1959 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1960 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1961 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1962 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1963 | int ret; |
| 1964 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1965 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1966 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1967 | opendata->o_arg.open_flags = 0; |
| 1968 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1969 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1970 | NFS_SB(opendata->dentry->d_sb), |
| 1971 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1972 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1973 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1974 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1975 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1976 | if (ret != 0) |
| 1977 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1978 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1979 | if (IS_ERR(newstate)) |
| 1980 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1981 | if (newstate != opendata->state) |
| 1982 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1983 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1984 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1988 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1989 | int ret; |
| 1990 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1991 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1992 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1993 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1994 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1995 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1996 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1997 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1998 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1999 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2000 | if (ret != 0) |
| 2001 | return ret; |
| 2002 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2003 | if (ret != 0) |
| 2004 | return ret; |
| 2005 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2006 | if (ret != 0) |
| 2007 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2008 | /* |
| 2009 | * We may have performed cached opens for all three recoveries. |
| 2010 | * Check if we need to update the current stateid. |
| 2011 | */ |
| 2012 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2013 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2014 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2015 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2016 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 2017 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2018 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2019 | return 0; |
| 2020 | } |
| 2021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | /* |
| 2023 | * OPEN_RECLAIM: |
| 2024 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2026 | 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] | 2027 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2028 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2029 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2030 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | int status; |
| 2032 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2033 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2034 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2035 | if (IS_ERR(opendata)) |
| 2036 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2037 | rcu_read_lock(); |
| 2038 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2039 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2040 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2041 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2042 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2043 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2044 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | return status; |
| 2046 | } |
| 2047 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2048 | 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] | 2049 | { |
| 2050 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2051 | struct nfs4_exception exception = { }; |
| 2052 | int err; |
| 2053 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2054 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2055 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2056 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2057 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2058 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2059 | break; |
| 2060 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | } while (exception.retry); |
| 2062 | return err; |
| 2063 | } |
| 2064 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2065 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2066 | { |
| 2067 | struct nfs_open_context *ctx; |
| 2068 | int ret; |
| 2069 | |
| 2070 | ctx = nfs4_state_find_open_context(state); |
| 2071 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2072 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2073 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2074 | put_nfs_open_context(ctx); |
| 2075 | return ret; |
| 2076 | } |
| 2077 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2078 | 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] | 2079 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2080 | switch (err) { |
| 2081 | default: |
| 2082 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2083 | "%d.\n", __func__, err); |
| 2084 | case 0: |
| 2085 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2086 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2087 | case -ESTALE: |
| 2088 | break; |
| 2089 | case -NFS4ERR_BADSESSION: |
| 2090 | case -NFS4ERR_BADSLOT: |
| 2091 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2092 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2093 | case -NFS4ERR_DEADSESSION: |
| 2094 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2095 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2096 | return -EAGAIN; |
| 2097 | case -NFS4ERR_STALE_CLIENTID: |
| 2098 | case -NFS4ERR_STALE_STATEID: |
| 2099 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2100 | /* Don't recall a delegation if it was lost */ |
| 2101 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2102 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2103 | case -NFS4ERR_MOVED: |
| 2104 | nfs4_schedule_migration_recovery(server); |
| 2105 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2106 | case -NFS4ERR_LEASE_MOVED: |
| 2107 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2108 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2109 | case -NFS4ERR_DELEG_REVOKED: |
| 2110 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2111 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2112 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2113 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2114 | nfs_inode_find_state_and_recover(state->inode, |
| 2115 | stateid); |
| 2116 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2117 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2118 | case -NFS4ERR_DELAY: |
| 2119 | case -NFS4ERR_GRACE: |
| 2120 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2121 | ssleep(1); |
| 2122 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2123 | case -ENOMEM: |
| 2124 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2125 | if (fl) { |
| 2126 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2127 | if (lsp) |
| 2128 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2129 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2130 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | return err; |
| 2133 | } |
| 2134 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2135 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2136 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2137 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2138 | { |
| 2139 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2140 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2141 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2142 | |
| 2143 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2144 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2145 | if (IS_ERR(opendata)) |
| 2146 | return PTR_ERR(opendata); |
| 2147 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2148 | write_seqlock(&state->seqlock); |
| 2149 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2150 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2151 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2152 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2153 | case FMODE_READ|FMODE_WRITE: |
| 2154 | case FMODE_WRITE: |
| 2155 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2156 | if (err) |
| 2157 | break; |
| 2158 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2159 | if (err) |
| 2160 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 2161 | /* Fall through */ |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2162 | case FMODE_READ: |
| 2163 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2164 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2165 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2166 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2167 | } |
| 2168 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2169 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2170 | { |
| 2171 | struct nfs4_opendata *data = calldata; |
| 2172 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2173 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2174 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2175 | } |
| 2176 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2177 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2178 | { |
| 2179 | struct nfs4_opendata *data = calldata; |
| 2180 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2181 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2182 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2183 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2184 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2185 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2186 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2187 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2188 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2189 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static void nfs4_open_confirm_release(void *calldata) |
| 2193 | { |
| 2194 | struct nfs4_opendata *data = calldata; |
| 2195 | struct nfs4_state *state = NULL; |
| 2196 | |
| 2197 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2198 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2199 | goto out_free; |
| 2200 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2201 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2202 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2203 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2204 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2205 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2206 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2207 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2211 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2212 | .rpc_call_done = nfs4_open_confirm_done, |
| 2213 | .rpc_release = nfs4_open_confirm_release, |
| 2214 | }; |
| 2215 | |
| 2216 | /* |
| 2217 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2218 | */ |
| 2219 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2220 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2221 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2222 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2223 | struct rpc_message msg = { |
| 2224 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2225 | .rpc_argp = &data->c_arg, |
| 2226 | .rpc_resp = &data->c_res, |
| 2227 | .rpc_cred = data->owner->so_cred, |
| 2228 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2229 | struct rpc_task_setup task_setup_data = { |
| 2230 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2231 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2232 | .callback_ops = &nfs4_open_confirm_ops, |
| 2233 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2234 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2235 | .flags = RPC_TASK_ASYNC, |
| 2236 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | int status; |
| 2238 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2239 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2240 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2241 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2242 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2243 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2244 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2245 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2246 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2247 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2248 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2249 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2250 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2251 | smp_wmb(); |
| 2252 | } else |
| 2253 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2254 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | return status; |
| 2256 | } |
| 2257 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2258 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2260 | struct nfs4_opendata *data = calldata; |
| 2261 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2262 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2263 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2264 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2265 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2266 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2267 | /* |
| 2268 | * Check if we still need to send an OPEN call, or if we can use |
| 2269 | * a delegation instead. |
| 2270 | */ |
| 2271 | if (data->state != NULL) { |
| 2272 | struct nfs_delegation *delegation; |
| 2273 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2274 | if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2275 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2276 | rcu_read_lock(); |
| 2277 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2278 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2279 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2280 | rcu_read_unlock(); |
| 2281 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2282 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2283 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2284 | switch (claim) { |
| 2285 | default: |
| 2286 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2287 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2288 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2289 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2290 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 2291 | /* Fall through */ |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2292 | case NFS4_OPEN_CLAIM_FH: |
| 2293 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2294 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2295 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2296 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2297 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2298 | &data->o_res.seq_res, |
| 2299 | task) != 0) |
| 2300 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2301 | |
| 2302 | /* Set the create mode (note dependency on the session type) */ |
| 2303 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2304 | if (data->o_arg.open_flags & O_EXCL) { |
| 2305 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2306 | if (nfs4_has_persistent_session(clp)) |
| 2307 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2308 | else if (clp->cl_mvops->minor_version > 0) |
| 2309 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2310 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2311 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2312 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2313 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2314 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2315 | out_no_action: |
| 2316 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2317 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2318 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2319 | } |
| 2320 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2321 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2322 | { |
| 2323 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2325 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2326 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2327 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2328 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2329 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2330 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2331 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2332 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2333 | case S_IFREG: |
| 2334 | break; |
| 2335 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2336 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2337 | break; |
| 2338 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2339 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2340 | break; |
| 2341 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2342 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2343 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2344 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2345 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2346 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2347 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2348 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2349 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2350 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2351 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2352 | static void nfs4_open_release(void *calldata) |
| 2353 | { |
| 2354 | struct nfs4_opendata *data = calldata; |
| 2355 | struct nfs4_state *state = NULL; |
| 2356 | |
| 2357 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2358 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2359 | goto out_free; |
| 2360 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2361 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2362 | goto out_free; |
| 2363 | /* In case we need an open_confirm, no cleanup! */ |
| 2364 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2365 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2366 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2367 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2368 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2369 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2370 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2374 | .rpc_call_prepare = nfs4_open_prepare, |
| 2375 | .rpc_call_done = nfs4_open_done, |
| 2376 | .rpc_release = nfs4_open_release, |
| 2377 | }; |
| 2378 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2379 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2380 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2381 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2382 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2383 | struct nfs_server *server = NFS_SERVER(dir); |
| 2384 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2385 | struct nfs_openres *o_res = &data->o_res; |
| 2386 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2387 | struct rpc_message msg = { |
| 2388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2389 | .rpc_argp = o_arg, |
| 2390 | .rpc_resp = o_res, |
| 2391 | .rpc_cred = data->owner->so_cred, |
| 2392 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2393 | struct rpc_task_setup task_setup_data = { |
| 2394 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2395 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2396 | .callback_ops = &nfs4_open_ops, |
| 2397 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2398 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2399 | .flags = RPC_TASK_ASYNC, |
| 2400 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2401 | int status; |
| 2402 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2403 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2404 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2405 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2406 | data->cancelled = false; |
| 2407 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2408 | if (!ctx) { |
| 2409 | 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] | 2410 | data->is_recover = true; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2411 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2412 | 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] | 2413 | pnfs_lgopen_prepare(data, ctx); |
| 2414 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2415 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2416 | if (IS_ERR(task)) |
| 2417 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2418 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2419 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2420 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2421 | smp_wmb(); |
| 2422 | } else |
| 2423 | status = data->rpc_status; |
| 2424 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2425 | |
| 2426 | return status; |
| 2427 | } |
| 2428 | |
| 2429 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2430 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2431 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2432 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2433 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2434 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2435 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2436 | if (status != 0 || !data->rpc_done) |
| 2437 | return status; |
| 2438 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2439 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2440 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2441 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2442 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2443 | |
| 2444 | return status; |
| 2445 | } |
| 2446 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2447 | /* |
| 2448 | * Additional permission checks in order to distinguish between an |
| 2449 | * open for read, and an open for execute. This works around the |
| 2450 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2451 | * the same. |
| 2452 | * Note that in the non-execute case, we want to turn off permission |
| 2453 | * checking if we just created a new file (POSIX open() semantics). |
| 2454 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2455 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2456 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2457 | struct nfs4_state *state, fmode_t fmode, |
| 2458 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2459 | { |
| 2460 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2461 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2462 | |
| 2463 | /* access call failed or for some reason the server doesn't |
| 2464 | * support any access modes -- defer access call until later */ |
| 2465 | if (opendata->o_res.access_supported == 0) |
| 2466 | return 0; |
| 2467 | |
| 2468 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2469 | /* |
| 2470 | * Use openflags to check for exec, because fmode won't |
| 2471 | * always have FMODE_EXEC set when file open for exec. |
| 2472 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2473 | if (openflags & __FMODE_EXEC) { |
| 2474 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2475 | if (S_ISDIR(state->inode->i_mode)) |
| 2476 | mask = NFS4_ACCESS_LOOKUP; |
| 2477 | else |
| 2478 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2479 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2480 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2481 | |
| 2482 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2483 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2484 | nfs_access_add_cache(state->inode, &cache); |
| 2485 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2486 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2487 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2488 | return 0; |
| 2489 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2490 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2491 | } |
| 2492 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2493 | /* |
| 2494 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2495 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2496 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2497 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2498 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2499 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2500 | struct nfs_server *server = NFS_SERVER(dir); |
| 2501 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2502 | struct nfs_openres *o_res = &data->o_res; |
| 2503 | int status; |
| 2504 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2505 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2506 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2507 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2508 | if (status != 0) { |
| 2509 | if (status == -NFS4ERR_BADNAME && |
| 2510 | !(o_arg->open_flags & O_CREAT)) |
| 2511 | return -ENOENT; |
| 2512 | return status; |
| 2513 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2514 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2515 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2516 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2517 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2518 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2519 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2520 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2521 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2522 | if (data->file_created || |
| 2523 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2524 | update_changeattr(dir, &o_res->cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 2525 | o_res->f_attr->time_start, 0); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2526 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2527 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2528 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2530 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2532 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2534 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2535 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2536 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2537 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2538 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2539 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | /* |
| 2543 | * OPEN_EXPIRED: |
| 2544 | * reclaim state on the server after a network partition. |
| 2545 | * Assumes caller holds the appropriate lock |
| 2546 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2547 | 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] | 2548 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2549 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2550 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2552 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2553 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2554 | if (IS_ERR(opendata)) |
| 2555 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2556 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2557 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2558 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2559 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2560 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2563 | 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] | 2564 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2565 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2566 | struct nfs4_exception exception = { }; |
| 2567 | int err; |
| 2568 | |
| 2569 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2570 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2571 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2572 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2573 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2574 | switch (err) { |
| 2575 | default: |
| 2576 | goto out; |
| 2577 | case -NFS4ERR_GRACE: |
| 2578 | case -NFS4ERR_DELAY: |
| 2579 | nfs4_handle_exception(server, err, &exception); |
| 2580 | err = 0; |
| 2581 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2582 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2583 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2584 | return err; |
| 2585 | } |
| 2586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2588 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2590 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2592 | ctx = nfs4_state_find_open_context(state); |
| 2593 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2594 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2595 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2596 | put_nfs_open_context(ctx); |
| 2597 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2600 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2601 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2602 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2603 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2604 | write_seqlock(&state->seqlock); |
| 2605 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2606 | write_sequnlock(&state->seqlock); |
| 2607 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2608 | } |
| 2609 | |
| 2610 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2611 | { |
| 2612 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2613 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2617 | { |
| 2618 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2619 | nfs40_clear_delegation_stateid(state); |
| 2620 | return nfs4_open_expired(sp, state); |
| 2621 | } |
| 2622 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2623 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2624 | nfs4_stateid *stateid, |
| 2625 | struct rpc_cred *cred) |
| 2626 | { |
| 2627 | return -NFS4ERR_BAD_STATEID; |
| 2628 | } |
| 2629 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2630 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2631 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2632 | nfs4_stateid *stateid, |
| 2633 | struct rpc_cred *cred) |
| 2634 | { |
| 2635 | int status; |
| 2636 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2637 | switch (stateid->type) { |
| 2638 | default: |
| 2639 | break; |
| 2640 | case NFS4_INVALID_STATEID_TYPE: |
| 2641 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2642 | return -NFS4ERR_BAD_STATEID; |
| 2643 | case NFS4_REVOKED_STATEID_TYPE: |
| 2644 | goto out_free; |
| 2645 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2646 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2647 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2648 | switch (status) { |
| 2649 | case -NFS4ERR_EXPIRED: |
| 2650 | case -NFS4ERR_ADMIN_REVOKED: |
| 2651 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2652 | break; |
| 2653 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2654 | return status; |
| 2655 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2656 | out_free: |
| 2657 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2658 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2659 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2660 | } |
| 2661 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2662 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2663 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2664 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2665 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2666 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2667 | struct rpc_cred *cred; |
| 2668 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2669 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2670 | /* Get the delegation credential for use by test/free_stateid */ |
| 2671 | rcu_read_lock(); |
| 2672 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2673 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2674 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2679 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2680 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2681 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2682 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2683 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2684 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2685 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2686 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2687 | cred = get_rpccred(delegation->cred); |
| 2688 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2689 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2690 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2691 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2692 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2693 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2694 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2698 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2699 | * |
| 2700 | * @state: NFSv4 state for an inode |
| 2701 | * |
| 2702 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2703 | * Otherwise a negative NFS4ERR value is returned. |
| 2704 | */ |
| 2705 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2706 | { |
| 2707 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2708 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2709 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2710 | |
| 2711 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2712 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2713 | |
| 2714 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2715 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2716 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2717 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2718 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2719 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2720 | spin_unlock(&state->state_lock); |
| 2721 | |
| 2722 | nfs4_put_lock_state(prev); |
| 2723 | prev = lsp; |
| 2724 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2725 | status = nfs41_test_and_free_expired_stateid(server, |
| 2726 | &lsp->ls_stateid, |
| 2727 | cred); |
| 2728 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2729 | if (status == -NFS4ERR_EXPIRED || |
| 2730 | status == -NFS4ERR_BAD_STATEID) { |
| 2731 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2732 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2733 | if (!recover_lost_locks) |
| 2734 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2735 | } else if (status != NFS_OK) { |
| 2736 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2737 | nfs4_put_lock_state(prev); |
| 2738 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2739 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2740 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2741 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2742 | } |
| 2743 | spin_unlock(&state->state_lock); |
| 2744 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2745 | out: |
| 2746 | return ret; |
| 2747 | } |
| 2748 | |
| 2749 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2750 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2751 | * |
| 2752 | * @state: NFSv4 state for an inode |
| 2753 | * |
| 2754 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2755 | * Otherwise a negative NFS4ERR value is returned. |
| 2756 | */ |
| 2757 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2758 | { |
| 2759 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2760 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2761 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2762 | int status; |
| 2763 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2764 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2765 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2766 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2767 | return NFS_OK; |
| 2768 | return -NFS4ERR_OPENMODE; |
| 2769 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2770 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2771 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2772 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2773 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2774 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2775 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2776 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2777 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2778 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2779 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2780 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2781 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2782 | if (nfs_open_stateid_recover_openmode(state)) |
| 2783 | return -NFS4ERR_OPENMODE; |
| 2784 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2788 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2789 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2790 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2791 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2792 | status = nfs41_check_expired_locks(state); |
| 2793 | if (status != NFS_OK) |
| 2794 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2795 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2796 | if (status != NFS_OK) |
| 2797 | status = nfs4_open_expired(sp, state); |
| 2798 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2799 | } |
| 2800 | #endif |
| 2801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2803 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2804 | * fields corresponding to attributes that were used to store the verifier. |
| 2805 | * Make sure we clobber those fields in the later setattr call |
| 2806 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2807 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2808 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2809 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2810 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2811 | __u32 attrset[3]; |
| 2812 | unsigned ret; |
| 2813 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2814 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2815 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2816 | attrset[i] = opendata->o_res.attrset[i]; |
| 2817 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2818 | attrset[i] &= ~bitmask[i]; |
| 2819 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2820 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2821 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2822 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2823 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2824 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2825 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2826 | ret |= ATTR_ATIME_SET; |
| 2827 | else |
| 2828 | ret |= ATTR_ATIME; |
| 2829 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2830 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2831 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2832 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2833 | ret |= ATTR_MTIME_SET; |
| 2834 | else |
| 2835 | ret |= ATTR_MTIME; |
| 2836 | } |
| 2837 | |
| 2838 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2839 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2840 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2843 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2844 | fmode_t fmode, |
| 2845 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2846 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2847 | { |
| 2848 | struct nfs4_state_owner *sp = opendata->owner; |
| 2849 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2850 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2851 | struct nfs4_state *state; |
| 2852 | unsigned int seq; |
| 2853 | int ret; |
| 2854 | |
| 2855 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2856 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2857 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2858 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2859 | goto out; |
| 2860 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2861 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2862 | ret = PTR_ERR(state); |
| 2863 | if (IS_ERR(state)) |
| 2864 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2865 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2866 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2867 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2868 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2869 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2870 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2871 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2872 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2873 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2874 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2875 | alias = d_exact_alias(dentry, state->inode); |
| 2876 | if (!alias) |
| 2877 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2878 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2879 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2880 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2881 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2882 | } |
| 2883 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2884 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2885 | } |
| 2886 | |
Trond Myklebust | af9b6d7 | 2018-06-29 12:45:53 -0400 | [diff] [blame] | 2887 | /* Parse layoutget results before we check for access */ |
| 2888 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
| 2889 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2890 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2891 | if (ret != 0) |
| 2892 | goto out; |
| 2893 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2894 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2895 | nfs_inode_attach_open_context(ctx); |
| 2896 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2897 | nfs4_schedule_stateid_recovery(server, state); |
| 2898 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2899 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2900 | out: |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2901 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2902 | return ret; |
| 2903 | } |
| 2904 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2905 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2906 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2908 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2909 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2910 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2911 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2912 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
| 2914 | struct nfs4_state_owner *sp; |
| 2915 | struct nfs4_state *state = NULL; |
| 2916 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2917 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2918 | struct dentry *dentry = ctx->dentry; |
| 2919 | struct rpc_cred *cred = ctx->cred; |
| 2920 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2921 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2922 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2923 | struct iattr *sattr = c->sattr; |
| 2924 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2925 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2926 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | |
| 2928 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2930 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2931 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2933 | goto out_err; |
| 2934 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2935 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2936 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2937 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2938 | if (d_really_is_positive(dentry)) |
| 2939 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2940 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2941 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2942 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2943 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2944 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2945 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2946 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2948 | if (label) { |
| 2949 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2950 | if (IS_ERR(olabel)) { |
| 2951 | status = PTR_ERR(olabel); |
| 2952 | goto err_opendata_put; |
| 2953 | } |
| 2954 | } |
| 2955 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2956 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2957 | if (!opendata->f_attr.mdsthreshold) { |
| 2958 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2959 | if (!opendata->f_attr.mdsthreshold) |
| 2960 | goto err_free_label; |
| 2961 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2962 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2963 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2964 | if (d_really_is_positive(dentry)) |
| 2965 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2966 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2967 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2968 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2969 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2970 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2971 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2972 | 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] | 2973 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2974 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2975 | /* |
| 2976 | * send create attributes which was not set by open |
| 2977 | * with an extra setattr. |
| 2978 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2979 | if (attrs || label) { |
| 2980 | unsigned ia_old = sattr->ia_valid; |
| 2981 | |
| 2982 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2983 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2984 | status = nfs4_do_setattr(state->inode, cred, |
| 2985 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2986 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2987 | if (status == 0) { |
| 2988 | nfs_setattr_update_inode(state->inode, sattr, |
| 2989 | opendata->o_res.f_attr); |
| 2990 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2991 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2992 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2993 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2994 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2995 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2996 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2997 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2998 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2999 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 3000 | opendata->f_attr.mdsthreshold = NULL; |
| 3001 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3002 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3003 | nfs4_label_free(olabel); |
| 3004 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3005 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3008 | err_free_label: |
| 3009 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 3010 | err_opendata_put: |
| 3011 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 3012 | err_put_state_owner: |
| 3013 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | return status; |
| 3016 | } |
| 3017 | |
| 3018 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3019 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 3020 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 3021 | int flags, |
| 3022 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3023 | struct nfs4_label *label, |
| 3024 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3026 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | struct nfs4_exception exception = { }; |
| 3028 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3029 | struct nfs4_open_createattrs c = { |
| 3030 | .label = label, |
| 3031 | .sattr = sattr, |
| 3032 | .verf = { |
| 3033 | [0] = (__u32)jiffies, |
| 3034 | [1] = (__u32)current->pid, |
| 3035 | }, |
| 3036 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | int status; |
| 3038 | |
| 3039 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 3040 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 3041 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3042 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | if (status == 0) |
| 3044 | break; |
| 3045 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3046 | * book-keeping w.r.t. state-changing operations |
| 3047 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3048 | * It is actually a sign of a bug on the client or on the server. |
| 3049 | * |
| 3050 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3051 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | * have unhashed the old state_owner for us, and that we can |
| 3053 | * therefore safely retry using a new one. We should still warn |
| 3054 | * the user though... |
| 3055 | */ |
| 3056 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3057 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3058 | " returned a bad sequence-id error!\n", |
| 3059 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | exception.retry = 1; |
| 3061 | continue; |
| 3062 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3063 | /* |
| 3064 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3065 | * state before it received the OPEN_CONFIRM. |
| 3066 | * Recover by retrying the request as per the discussion |
| 3067 | * on Page 181 of RFC3530. |
| 3068 | */ |
| 3069 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3070 | exception.retry = 1; |
| 3071 | continue; |
| 3072 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3073 | if (status == -EAGAIN) { |
| 3074 | /* We must have found a delegation */ |
| 3075 | exception.retry = 1; |
| 3076 | continue; |
| 3077 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3078 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3079 | continue; |
| 3080 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | status, &exception)); |
| 3082 | } while (exception.retry); |
| 3083 | return res; |
| 3084 | } |
| 3085 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3086 | static int _nfs4_do_setattr(struct inode *inode, |
| 3087 | struct nfs_setattrargs *arg, |
| 3088 | struct nfs_setattrres *res, |
| 3089 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3090 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3091 | { |
| 3092 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3093 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3094 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3095 | .rpc_argp = arg, |
| 3096 | .rpc_resp = res, |
| 3097 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3098 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3099 | struct rpc_cred *delegation_cred = NULL; |
| 3100 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3101 | bool truncate; |
| 3102 | int status; |
| 3103 | |
| 3104 | nfs_fattr_init(res->fattr); |
| 3105 | |
| 3106 | /* Servers should only apply open mode checks for file size changes */ |
| 3107 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3108 | if (!truncate) |
| 3109 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3110 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3111 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3112 | /* Use that stateid */ |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3113 | } else if (ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3114 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3115 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3116 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3117 | l_ctx = nfs_get_lock_context(ctx); |
| 3118 | if (IS_ERR(l_ctx)) |
| 3119 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3120 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3121 | &arg->stateid, &delegation_cred); |
| 3122 | nfs_put_lock_context(l_ctx); |
| 3123 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3124 | return -EBADF; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3125 | } else { |
| 3126 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3127 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3128 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3129 | if (delegation_cred) |
| 3130 | msg.rpc_cred = delegation_cred; |
| 3131 | |
| 3132 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3133 | |
| 3134 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3135 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3136 | renew_lease(server, timestamp); |
| 3137 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3138 | return status; |
| 3139 | } |
| 3140 | |
| 3141 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3142 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3143 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3144 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3146 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3147 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3148 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3149 | struct nfs_setattrargs arg = { |
| 3150 | .fh = NFS_FH(inode), |
| 3151 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3153 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3154 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3155 | }; |
| 3156 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3158 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3160 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3161 | struct nfs4_exception exception = { |
| 3162 | .state = state, |
| 3163 | .inode = inode, |
| 3164 | .stateid = &arg.stateid, |
| 3165 | }; |
| 3166 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3169 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3170 | nfs4_bitmask(server, olabel), |
| 3171 | inode); |
| 3172 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3173 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3174 | switch (err) { |
| 3175 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3176 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3177 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3178 | "applying open mode checks to " |
| 3179 | "a SETATTR that is not " |
| 3180 | "changing file size.\n", |
| 3181 | server->nfs_client->cl_hostname); |
| 3182 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3183 | if (state && !(state->state & FMODE_WRITE)) { |
| 3184 | err = -EBADF; |
| 3185 | if (sattr->ia_valid & ATTR_OPEN) |
| 3186 | err = -EACCES; |
| 3187 | goto out; |
| 3188 | } |
| 3189 | } |
| 3190 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3192 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | return err; |
| 3194 | } |
| 3195 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3196 | static bool |
| 3197 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3198 | { |
| 3199 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3200 | return false; |
| 3201 | |
| 3202 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3203 | } |
| 3204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | struct nfs4_closedata { |
| 3206 | struct inode *inode; |
| 3207 | struct nfs4_state *state; |
| 3208 | struct nfs_closeargs arg; |
| 3209 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3210 | struct { |
| 3211 | struct nfs4_layoutreturn_args arg; |
| 3212 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3213 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3214 | u32 roc_barrier; |
| 3215 | bool roc; |
| 3216 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3217 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3218 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | }; |
| 3220 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3221 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3222 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3223 | struct nfs4_closedata *calldata = data; |
| 3224 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3225 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3226 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3227 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3228 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3229 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3230 | nfs4_put_open_state(calldata->state); |
| 3231 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3232 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3233 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3234 | kfree(calldata); |
| 3235 | } |
| 3236 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3237 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3239 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3242 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3243 | struct nfs4_exception exception = { |
| 3244 | .state = state, |
| 3245 | .inode = calldata->inode, |
| 3246 | .stateid = &calldata->arg.stateid, |
| 3247 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3249 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3250 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3251 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3252 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3253 | |
| 3254 | /* Handle Layoutreturn errors */ |
| 3255 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3256 | switch (calldata->res.lr_ret) { |
| 3257 | default: |
| 3258 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3259 | break; |
| 3260 | case 0: |
| 3261 | calldata->arg.lr_args = NULL; |
| 3262 | calldata->res.lr_res = NULL; |
| 3263 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3264 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 3265 | if (nfs4_layoutreturn_refresh_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame^] | 3266 | &calldata->arg.lr_args->range, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3267 | calldata->inode)) |
| 3268 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3269 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3270 | case -NFS4ERR_ADMIN_REVOKED: |
| 3271 | case -NFS4ERR_DELEG_REVOKED: |
| 3272 | case -NFS4ERR_EXPIRED: |
| 3273 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3274 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3275 | case -NFS4ERR_WRONG_CRED: |
| 3276 | calldata->arg.lr_args = NULL; |
| 3277 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3278 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3279 | } |
| 3280 | } |
| 3281 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3282 | /* 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] | 3283 | * the state_owner. we keep this around to process errors |
| 3284 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | switch (task->tk_status) { |
| 3286 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3287 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3288 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3289 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3290 | case -NFS4ERR_ACCESS: |
| 3291 | if (calldata->arg.bitmask != NULL) { |
| 3292 | calldata->arg.bitmask = NULL; |
| 3293 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3294 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3295 | |
| 3296 | } |
| 3297 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3298 | case -NFS4ERR_OLD_STATEID: |
| 3299 | /* Did we race with OPEN? */ |
| 3300 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3301 | state)) |
| 3302 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3303 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3304 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3306 | case -NFS4ERR_EXPIRED: |
| 3307 | nfs4_free_revoked_stateid(server, |
| 3308 | &calldata->arg.stateid, |
| 3309 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3310 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3311 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3312 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3314 | task->tk_status = nfs4_async_handle_exception(task, |
| 3315 | server, task->tk_status, &exception); |
| 3316 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3317 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3319 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3320 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3321 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3322 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3323 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3324 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3325 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3326 | return; |
| 3327 | lr_restart: |
| 3328 | calldata->res.lr_ret = 0; |
| 3329 | out_restart: |
| 3330 | task->tk_status = 0; |
| 3331 | rpc_restart_call_prepare(task); |
| 3332 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3335 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3337 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3338 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3339 | struct inode *inode = calldata->inode; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3340 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3341 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3342 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3343 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3344 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3345 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3346 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3347 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3348 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3349 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3350 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3351 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3352 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3353 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3354 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3355 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3356 | if (state->n_rdonly == 0) |
| 3357 | call_close |= is_rdonly; |
| 3358 | else if (is_rdonly) |
| 3359 | calldata->arg.fmode |= FMODE_READ; |
| 3360 | if (state->n_wronly == 0) |
| 3361 | call_close |= is_wronly; |
| 3362 | else if (is_wronly) |
| 3363 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3364 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3365 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3366 | } else if (is_rdwr) |
| 3367 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3368 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3369 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3370 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3371 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3372 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3373 | |
| 3374 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3375 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3376 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3377 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3378 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3379 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3380 | nfs_release_seqid(calldata->arg.seqid); |
| 3381 | goto out_wait; |
| 3382 | } |
| 3383 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 3384 | lo = calldata->arg.lr_args ? calldata->arg.lr_args->layout : NULL; |
| 3385 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 3386 | calldata->arg.lr_args = NULL; |
| 3387 | calldata->res.lr_res = NULL; |
| 3388 | } |
| 3389 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3390 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3391 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3392 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3393 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3394 | /* Close-to-open cache consistency revalidation */ |
| 3395 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3396 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3397 | else |
| 3398 | calldata->arg.bitmask = NULL; |
| 3399 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3400 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3401 | calldata->arg.share_access = |
| 3402 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3403 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3404 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3405 | if (calldata->res.fattr == NULL) |
| 3406 | calldata->arg.bitmask = NULL; |
| 3407 | else if (calldata->arg.bitmask == NULL) |
| 3408 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3409 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3410 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3411 | &calldata->arg.seq_args, |
| 3412 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3413 | task) != 0) |
| 3414 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3415 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3416 | return; |
| 3417 | out_no_action: |
| 3418 | task->tk_action = NULL; |
| 3419 | out_wait: |
| 3420 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3423 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3424 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3425 | .rpc_call_done = nfs4_close_done, |
| 3426 | .rpc_release = nfs4_free_closedata, |
| 3427 | }; |
| 3428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | /* |
| 3430 | * It is possible for data to be read/written from a mem-mapped file |
| 3431 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3432 | * This means that we can't safely call nfsv4 close on a file until |
| 3433 | * the inode is cleared. This in turn means that we are not good |
| 3434 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3435 | * share state even when we are done with one of the three share |
| 3436 | * stateid's in the inode. |
| 3437 | * |
| 3438 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3439 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3440 | 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] | 3441 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3442 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3443 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3445 | struct nfs4_state_owner *sp = state->owner; |
| 3446 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3447 | struct rpc_message msg = { |
| 3448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3449 | .rpc_cred = state->owner->so_cred, |
| 3450 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3451 | struct rpc_task_setup task_setup_data = { |
| 3452 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3453 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3454 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3455 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3456 | .flags = RPC_TASK_ASYNC, |
| 3457 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3458 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3460 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3461 | &task_setup_data.rpc_client, &msg); |
| 3462 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3463 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3465 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3466 | 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] | 3467 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3469 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3470 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3471 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3473 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3474 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3475 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3476 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3477 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3478 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3479 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3480 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3481 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3482 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3483 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3484 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3485 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3486 | if (calldata->lr.roc) { |
| 3487 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3488 | calldata->res.lr_res = &calldata->lr.res; |
| 3489 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3490 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3491 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3492 | msg.rpc_argp = &calldata->arg; |
| 3493 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3494 | task_setup_data.callback_data = calldata; |
| 3495 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3496 | if (IS_ERR(task)) |
| 3497 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3498 | status = 0; |
| 3499 | if (wait) |
| 3500 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3501 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3502 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3503 | out_free_calldata: |
| 3504 | kfree(calldata); |
| 3505 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3506 | nfs4_put_open_state(state); |
| 3507 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3508 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3511 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3512 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3513 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3516 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3517 | |
| 3518 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3520 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3521 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3522 | |
| 3523 | nfs4_label_release_security(label); |
| 3524 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3525 | if (IS_ERR(state)) |
| 3526 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3527 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
| 3529 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3530 | 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] | 3531 | { |
| 3532 | if (ctx->state == NULL) |
| 3533 | return; |
| 3534 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3535 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3536 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3537 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3540 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3541 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3542 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3545 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3546 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3547 | struct nfs4_server_caps_arg args = { |
| 3548 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3549 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3550 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | struct nfs4_server_caps_res res = {}; |
| 3552 | struct rpc_message msg = { |
| 3553 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3554 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | .rpc_resp = &res, |
| 3556 | }; |
| 3557 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3558 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3560 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3561 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3562 | FATTR4_WORD0_LINK_SUPPORT | |
| 3563 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3564 | FATTR4_WORD0_ACLSUPPORT; |
| 3565 | if (minorversion) |
| 3566 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3567 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3568 | 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] | 3569 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3570 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3571 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3572 | case 0: |
| 3573 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3574 | res.attr_bitmask[2] = 0; |
| 3575 | break; |
| 3576 | case 1: |
| 3577 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3578 | break; |
| 3579 | case 2: |
| 3580 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3583 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3584 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3585 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3586 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3587 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3588 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3589 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3590 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | server->caps |= NFS_CAP_ACLS; |
| 3592 | if (res.has_links != 0) |
| 3593 | server->caps |= NFS_CAP_HARDLINKS; |
| 3594 | if (res.has_symlinks != 0) |
| 3595 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3596 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3597 | server->caps |= NFS_CAP_FILEID; |
| 3598 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3599 | server->caps |= NFS_CAP_MODE; |
| 3600 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3601 | server->caps |= NFS_CAP_NLINK; |
| 3602 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3603 | server->caps |= NFS_CAP_OWNER; |
| 3604 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3605 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3606 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3607 | server->caps |= NFS_CAP_ATIME; |
| 3608 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3609 | server->caps |= NFS_CAP_CTIME; |
| 3610 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3611 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3612 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3613 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3614 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3615 | #endif |
| 3616 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3617 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3618 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3619 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3620 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3621 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3622 | 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] | 3623 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3624 | |
| 3625 | /* Avoid a regression due to buggy server */ |
| 3626 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3627 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3628 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3629 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3632 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | return status; |
| 3636 | } |
| 3637 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3638 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | { |
| 3640 | struct nfs4_exception exception = { }; |
| 3641 | int err; |
| 3642 | do { |
| 3643 | err = nfs4_handle_exception(server, |
| 3644 | _nfs4_server_capabilities(server, fhandle), |
| 3645 | &exception); |
| 3646 | } while (exception.retry); |
| 3647 | return err; |
| 3648 | } |
| 3649 | |
| 3650 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3651 | struct nfs_fsinfo *info) |
| 3652 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3653 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3655 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | }; |
| 3657 | struct nfs4_lookup_res res = { |
| 3658 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3659 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | .fh = fhandle, |
| 3661 | }; |
| 3662 | struct rpc_message msg = { |
| 3663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3664 | .rpc_argp = &args, |
| 3665 | .rpc_resp = &res, |
| 3666 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3667 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3668 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3669 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3670 | /* |
| 3671 | * Process the label in the upcoming getfattr |
| 3672 | */ |
| 3673 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3674 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3675 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3676 | 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] | 3677 | } |
| 3678 | |
| 3679 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3680 | struct nfs_fsinfo *info) |
| 3681 | { |
| 3682 | struct nfs4_exception exception = { }; |
| 3683 | int err; |
| 3684 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3685 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3686 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3687 | switch (err) { |
| 3688 | case 0: |
| 3689 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3690 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3691 | default: |
| 3692 | err = nfs4_handle_exception(server, err, &exception); |
| 3693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3695 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return err; |
| 3697 | } |
| 3698 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3699 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3700 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3701 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3702 | struct rpc_auth_create_args auth_args = { |
| 3703 | .pseudoflavor = flavor, |
| 3704 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3705 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3706 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3707 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3708 | if (IS_ERR(auth)) |
| 3709 | return -EACCES; |
| 3710 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3713 | /* |
| 3714 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3715 | * |
| 3716 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3717 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3718 | * |
| 3719 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3720 | * negative errno value. |
| 3721 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3722 | 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] | 3723 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3725 | /* Per 3530bis 15.33.5 */ |
| 3726 | static const rpc_authflavor_t flav_array[] = { |
| 3727 | RPC_AUTH_GSS_KRB5P, |
| 3728 | RPC_AUTH_GSS_KRB5I, |
| 3729 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3730 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3731 | RPC_AUTH_NULL, |
| 3732 | }; |
| 3733 | int status = -EPERM; |
| 3734 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3736 | if (server->auth_info.flavor_len > 0) { |
| 3737 | /* try each flavor specified by user */ |
| 3738 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3739 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3740 | server->auth_info.flavors[i]); |
| 3741 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3742 | continue; |
| 3743 | break; |
| 3744 | } |
| 3745 | } else { |
| 3746 | /* no flavors specified by user, try default list */ |
| 3747 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3748 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3749 | flav_array[i]); |
| 3750 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3751 | continue; |
| 3752 | break; |
| 3753 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3754 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3755 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3756 | /* |
| 3757 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3758 | * to access the mount. It could also mean that we tried to mount |
| 3759 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3760 | * existing mount programs don't handle -EACCES very well so it should |
| 3761 | * be mapped to -EPERM instead. |
| 3762 | */ |
| 3763 | if (status == -EACCES) |
| 3764 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3765 | return status; |
| 3766 | } |
| 3767 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3768 | /** |
| 3769 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3770 | * @server: initialized nfs_server handle |
| 3771 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3772 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3773 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3774 | * |
| 3775 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3776 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3777 | 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] | 3778 | struct nfs_fsinfo *info, |
| 3779 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3780 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3781 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3782 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3783 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3784 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3785 | |
| 3786 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3787 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3788 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | if (status == 0) |
| 3791 | status = nfs4_server_capabilities(server, fhandle); |
| 3792 | if (status == 0) |
| 3793 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3794 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3795 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3798 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3799 | struct nfs_fsinfo *info) |
| 3800 | { |
| 3801 | int error; |
| 3802 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3803 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3804 | |
| 3805 | error = nfs4_server_capabilities(server, mntfh); |
| 3806 | if (error < 0) { |
| 3807 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3808 | return error; |
| 3809 | } |
| 3810 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3811 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3812 | if (IS_ERR(label)) |
| 3813 | return PTR_ERR(label); |
| 3814 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3815 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3816 | if (error < 0) { |
| 3817 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3818 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3822 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3823 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3824 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3825 | err_free_label: |
| 3826 | nfs4_label_free(label); |
| 3827 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3828 | return error; |
| 3829 | } |
| 3830 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3831 | /* |
| 3832 | * Get locations and (maybe) other attributes of a referral. |
| 3833 | * Note that we'll actually follow the referral later when |
| 3834 | * we detect fsid mismatch in inode revalidation |
| 3835 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3836 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3837 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3838 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3839 | { |
| 3840 | int status = -ENOMEM; |
| 3841 | struct page *page = NULL; |
| 3842 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3843 | |
| 3844 | page = alloc_page(GFP_KERNEL); |
| 3845 | if (page == NULL) |
| 3846 | goto out; |
| 3847 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3848 | if (locations == NULL) |
| 3849 | goto out; |
| 3850 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3851 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3852 | if (status != 0) |
| 3853 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3854 | |
| 3855 | /* |
| 3856 | * If the fsid didn't change, this is a migration event, not a |
| 3857 | * referral. Cause us to drop into the exception handler, which |
| 3858 | * will kick off migration recovery. |
| 3859 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3860 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3861 | dprintk("%s: server did not return a different fsid for" |
| 3862 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3863 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3864 | goto out; |
| 3865 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3866 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3867 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3868 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3869 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3870 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3871 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3872 | out: |
| 3873 | if (page) |
| 3874 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3875 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3876 | return status; |
| 3877 | } |
| 3878 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3879 | 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] | 3880 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3881 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3883 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | struct nfs4_getattr_arg args = { |
| 3885 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3886 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | }; |
| 3888 | struct nfs4_getattr_res res = { |
| 3889 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3890 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | .server = server, |
| 3892 | }; |
| 3893 | struct rpc_message msg = { |
| 3894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3895 | .rpc_argp = &args, |
| 3896 | .rpc_resp = &res, |
| 3897 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3898 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3899 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3900 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3901 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3902 | 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] | 3903 | } |
| 3904 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3905 | 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] | 3906 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3907 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | { |
| 3909 | struct nfs4_exception exception = { }; |
| 3910 | int err; |
| 3911 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3912 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3913 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3914 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | &exception); |
| 3916 | } while (exception.retry); |
| 3917 | return err; |
| 3918 | } |
| 3919 | |
| 3920 | /* |
| 3921 | * The file is not closed if it is opened due to the a request to change |
| 3922 | * the size of the file. The open call will not be needed once the |
| 3923 | * VFS layer lookup-intents are implemented. |
| 3924 | * |
| 3925 | * Close is called when the inode is destroyed. |
| 3926 | * If we haven't opened the file for O_WRONLY, we |
| 3927 | * need to in the size_change case to obtain a stateid. |
| 3928 | * |
| 3929 | * Got race? |
| 3930 | * Because OPEN is always done by name in nfsv4, it is |
| 3931 | * possible that we opened a different file by the same |
| 3932 | * name. We can recognize this race condition, but we |
| 3933 | * can't do anything about it besides returning an error. |
| 3934 | * |
| 3935 | * This will be fixed with VFS changes (lookup-intent). |
| 3936 | */ |
| 3937 | static int |
| 3938 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3939 | struct iattr *sattr) |
| 3940 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3941 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3942 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3943 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3944 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | int status; |
| 3946 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3947 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3948 | sattr->ia_valid & ATTR_SIZE && |
| 3949 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3950 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3951 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3952 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3954 | /* Deal with open(O_TRUNC) */ |
| 3955 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3956 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3957 | |
| 3958 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3959 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3960 | return 0; |
| 3961 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3962 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3963 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3964 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3965 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3966 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3967 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3968 | } |
| 3969 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3970 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3971 | if (IS_ERR(label)) |
| 3972 | return PTR_ERR(label); |
| 3973 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3974 | /* Return any delegations if we're going to change ACLs */ |
| 3975 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 3976 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3977 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3978 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3979 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3980 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3981 | nfs_setsecurity(inode, fattr, label); |
| 3982 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3983 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | return status; |
| 3985 | } |
| 3986 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3987 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3988 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3989 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3990 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3991 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3992 | int status; |
| 3993 | struct nfs4_lookup_arg args = { |
| 3994 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3995 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3996 | .name = name, |
| 3997 | }; |
| 3998 | struct nfs4_lookup_res res = { |
| 3999 | .server = server, |
| 4000 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4001 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4002 | .fh = fhandle, |
| 4003 | }; |
| 4004 | struct rpc_message msg = { |
| 4005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 4006 | .rpc_argp = &args, |
| 4007 | .rpc_resp = &res, |
| 4008 | }; |
| 4009 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4010 | args.bitmask = nfs4_bitmask(server, label); |
| 4011 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4012 | nfs_fattr_init(fattr); |
| 4013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4015 | 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] | 4016 | dprintk("NFS reply lookup: %d\n", status); |
| 4017 | return status; |
| 4018 | } |
| 4019 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4020 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4021 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4022 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4023 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 4024 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4025 | fattr->nlink = 2; |
| 4026 | } |
| 4027 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4028 | 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] | 4029 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4030 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4031 | { |
| 4032 | struct nfs4_exception exception = { }; |
| 4033 | struct rpc_clnt *client = *clnt; |
| 4034 | int err; |
| 4035 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4036 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4037 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4038 | switch (err) { |
| 4039 | case -NFS4ERR_BADNAME: |
| 4040 | err = -ENOENT; |
| 4041 | goto out; |
| 4042 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4043 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 4044 | if (err == -NFS4ERR_MOVED) |
| 4045 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4046 | goto out; |
| 4047 | case -NFS4ERR_WRONGSEC: |
| 4048 | err = -EPERM; |
| 4049 | if (client != *clnt) |
| 4050 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4051 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4052 | if (IS_ERR(client)) |
| 4053 | return PTR_ERR(client); |
| 4054 | |
| 4055 | exception.retry = 1; |
| 4056 | break; |
| 4057 | default: |
| 4058 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4059 | } |
| 4060 | } while (exception.retry); |
| 4061 | |
| 4062 | out: |
| 4063 | if (err == 0) |
| 4064 | *clnt = client; |
| 4065 | else if (client != *clnt) |
| 4066 | rpc_shutdown_client(client); |
| 4067 | |
| 4068 | return err; |
| 4069 | } |
| 4070 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4071 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4072 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4073 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4075 | int status; |
| 4076 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4077 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4078 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4079 | if (client != NFS_CLIENT(dir)) { |
| 4080 | rpc_shutdown_client(client); |
| 4081 | nfs_fixup_secinfo_attributes(fattr); |
| 4082 | } |
| 4083 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4086 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4087 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4088 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4089 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4090 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4091 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4092 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4093 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4094 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4095 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4096 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4097 | } |
| 4098 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4099 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4100 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4101 | struct nfs4_label *label) |
| 4102 | { |
| 4103 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4104 | struct nfs_server *server = NFS_SERVER(inode); |
| 4105 | int status; |
| 4106 | struct nfs4_lookupp_arg args = { |
| 4107 | .bitmask = server->attr_bitmask, |
| 4108 | .fh = NFS_FH(inode), |
| 4109 | }; |
| 4110 | struct nfs4_lookupp_res res = { |
| 4111 | .server = server, |
| 4112 | .fattr = fattr, |
| 4113 | .label = label, |
| 4114 | .fh = fhandle, |
| 4115 | }; |
| 4116 | struct rpc_message msg = { |
| 4117 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4118 | .rpc_argp = &args, |
| 4119 | .rpc_resp = &res, |
| 4120 | }; |
| 4121 | |
| 4122 | args.bitmask = nfs4_bitmask(server, label); |
| 4123 | |
| 4124 | nfs_fattr_init(fattr); |
| 4125 | |
| 4126 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4127 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4128 | &res.seq_res, 0); |
| 4129 | dprintk("NFS reply lookupp: %d\n", status); |
| 4130 | return status; |
| 4131 | } |
| 4132 | |
| 4133 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4134 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4135 | { |
| 4136 | struct nfs4_exception exception = { }; |
| 4137 | int err; |
| 4138 | do { |
| 4139 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4140 | trace_nfs4_lookupp(inode, err); |
| 4141 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4142 | &exception); |
| 4143 | } while (exception.retry); |
| 4144 | return err; |
| 4145 | } |
| 4146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4148 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4149 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | struct nfs4_accessargs args = { |
| 4151 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4152 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4154 | struct nfs4_accessres res = { |
| 4155 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4156 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | struct rpc_message msg = { |
| 4158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4159 | .rpc_argp = &args, |
| 4160 | .rpc_resp = &res, |
| 4161 | .rpc_cred = entry->cred, |
| 4162 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4163 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4165 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4166 | res.fattr = nfs_alloc_fattr(); |
| 4167 | if (res.fattr == NULL) |
| 4168 | return -ENOMEM; |
| 4169 | args.bitmask = server->cache_consistency_bitmask; |
| 4170 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4171 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4172 | 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] | 4173 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4174 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4175 | if (res.fattr) |
| 4176 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4178 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | return status; |
| 4180 | } |
| 4181 | |
| 4182 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4183 | { |
| 4184 | struct nfs4_exception exception = { }; |
| 4185 | int err; |
| 4186 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4187 | err = _nfs4_proc_access(inode, entry); |
| 4188 | trace_nfs4_access(inode, err); |
| 4189 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | &exception); |
| 4191 | } while (exception.retry); |
| 4192 | return err; |
| 4193 | } |
| 4194 | |
| 4195 | /* |
| 4196 | * TODO: For the time being, we don't try to get any attributes |
| 4197 | * along with any of the zero-copy operations READ, READDIR, |
| 4198 | * READLINK, WRITE. |
| 4199 | * |
| 4200 | * In the case of the first three, we want to put the GETATTR |
| 4201 | * after the read-type operation -- this is because it is hard |
| 4202 | * to predict the length of a GETATTR response in v4, and thus |
| 4203 | * align the READ data correctly. This means that the GETATTR |
| 4204 | * may end up partially falling into the page cache, and we should |
| 4205 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4206 | * To do this efficiently, we need to know the total length |
| 4207 | * of data received, which doesn't seem to be available outside |
| 4208 | * of the RPC layer. |
| 4209 | * |
| 4210 | * In the case of WRITE, we also want to put the GETATTR after |
| 4211 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4212 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | * |
| 4214 | * Both of these changes to the XDR layer would in fact be quite |
| 4215 | * minor, but I decided to leave them for a subsequent patch. |
| 4216 | */ |
| 4217 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4218 | unsigned int pgbase, unsigned int pglen) |
| 4219 | { |
| 4220 | struct nfs4_readlink args = { |
| 4221 | .fh = NFS_FH(inode), |
| 4222 | .pgbase = pgbase, |
| 4223 | .pglen = pglen, |
| 4224 | .pages = &page, |
| 4225 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4226 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | struct rpc_message msg = { |
| 4228 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4229 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4230 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | }; |
| 4232 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4233 | 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] | 4234 | } |
| 4235 | |
| 4236 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4237 | unsigned int pgbase, unsigned int pglen) |
| 4238 | { |
| 4239 | struct nfs4_exception exception = { }; |
| 4240 | int err; |
| 4241 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4242 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4243 | trace_nfs4_readlink(inode, err); |
| 4244 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | &exception); |
| 4246 | } while (exception.retry); |
| 4247 | return err; |
| 4248 | } |
| 4249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4251 | * 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] | 4252 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | static int |
| 4254 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4255 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4257 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4258 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4259 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | int status = 0; |
| 4262 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4263 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4264 | if (IS_ERR(ctx)) |
| 4265 | return PTR_ERR(ctx); |
| 4266 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4267 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4268 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4269 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4270 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4271 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | if (IS_ERR(state)) { |
| 4273 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4274 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4277 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4278 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | return status; |
| 4280 | } |
| 4281 | |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4282 | static int |
| 4283 | _nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4285 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4286 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4288 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4290 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4291 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4292 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4295 | .rpc_argp = &args, |
| 4296 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4298 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4299 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4300 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4301 | 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] | 4302 | if (status == 0) { |
| 4303 | spin_lock(&dir->i_lock); |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4304 | update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4305 | /* Removing a directory decrements nlink in the parent */ |
| 4306 | if (ftype == NF4DIR && dir->i_nlink > 2) |
| 4307 | nfs4_dec_nlink_locked(dir); |
| 4308 | spin_unlock(&dir->i_lock); |
| 4309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | return status; |
| 4311 | } |
| 4312 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4313 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4314 | { |
| 4315 | struct nfs4_exception exception = { }; |
| 4316 | struct inode *inode = d_inode(dentry); |
| 4317 | int err; |
| 4318 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4319 | if (inode) { |
| 4320 | if (inode->i_nlink == 1) |
| 4321 | nfs4_inode_return_delegation(inode); |
| 4322 | else |
| 4323 | nfs4_inode_make_writeable(inode); |
| 4324 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4325 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4326 | err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4327 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4328 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4329 | &exception); |
| 4330 | } while (exception.retry); |
| 4331 | return err; |
| 4332 | } |
| 4333 | |
| 4334 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | { |
| 4336 | struct nfs4_exception exception = { }; |
| 4337 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | do { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4340 | err = _nfs4_proc_remove(dir, name, NF4DIR); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4341 | trace_nfs4_remove(dir, name, err); |
| 4342 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | &exception); |
| 4344 | } while (exception.retry); |
| 4345 | return err; |
| 4346 | } |
| 4347 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4348 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4349 | struct dentry *dentry, |
| 4350 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4352 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4353 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4355 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4357 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4358 | |
| 4359 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4360 | |
| 4361 | if (inode) |
| 4362 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4365 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4366 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4367 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4368 | &data->args.seq_args, |
| 4369 | &data->res.seq_res, |
| 4370 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | } |
| 4372 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4373 | 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] | 4374 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4375 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4376 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4377 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4378 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4379 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4380 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4381 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4382 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4383 | if (task->tk_status == 0) |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4384 | update_changeattr(dir, &res->cinfo, |
| 4385 | res->dir_attr->time_start, 0); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4386 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4389 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4390 | struct dentry *old_dentry, |
| 4391 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4392 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4393 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4394 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4395 | struct inode *old_inode = d_inode(old_dentry); |
| 4396 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4397 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4398 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4399 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4400 | if (new_inode) |
| 4401 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4402 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4403 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4404 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4405 | } |
| 4406 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4407 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4408 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4409 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4410 | &data->args.seq_args, |
| 4411 | &data->res.seq_res, |
| 4412 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4416 | struct inode *new_dir) |
| 4417 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4418 | struct nfs_renamedata *data = task->tk_calldata; |
| 4419 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4420 | |
| 4421 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4422 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4423 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4424 | return 0; |
| 4425 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4426 | if (task->tk_status == 0) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4427 | if (new_dir != old_dir) { |
| 4428 | /* Note: If we moved a directory, nlink will change */ |
| 4429 | update_changeattr(old_dir, &res->old_cinfo, |
| 4430 | res->old_fattr->time_start, |
| 4431 | NFS_INO_INVALID_OTHER); |
| 4432 | update_changeattr(new_dir, &res->new_cinfo, |
| 4433 | res->new_fattr->time_start, |
| 4434 | NFS_INO_INVALID_OTHER); |
| 4435 | } else |
| 4436 | update_changeattr(old_dir, &res->old_cinfo, |
| 4437 | res->old_fattr->time_start, |
| 4438 | 0); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4439 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4440 | return 1; |
| 4441 | } |
| 4442 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4443 | 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] | 4444 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4445 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4446 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | struct nfs4_link_arg arg = { |
| 4448 | .fh = NFS_FH(inode), |
| 4449 | .dir_fh = NFS_FH(dir), |
| 4450 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4451 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4453 | struct nfs4_link_res res = { |
| 4454 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4455 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4456 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | struct rpc_message msg = { |
| 4458 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4459 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4460 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4462 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4464 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4465 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4466 | goto out; |
| 4467 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4468 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4469 | if (IS_ERR(res.label)) { |
| 4470 | status = PTR_ERR(res.label); |
| 4471 | goto out; |
| 4472 | } |
| 4473 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4474 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4475 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4476 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4477 | 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] | 4478 | if (!status) { |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4479 | update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4480 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4481 | if (!status) |
| 4482 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4483 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4484 | |
| 4485 | |
| 4486 | nfs4_label_free(res.label); |
| 4487 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4488 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4489 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | return status; |
| 4491 | } |
| 4492 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4493 | 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] | 4494 | { |
| 4495 | struct nfs4_exception exception = { }; |
| 4496 | int err; |
| 4497 | do { |
| 4498 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4499 | _nfs4_proc_link(inode, dir, name), |
| 4500 | &exception); |
| 4501 | } while (exception.retry); |
| 4502 | return err; |
| 4503 | } |
| 4504 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4505 | struct nfs4_createdata { |
| 4506 | struct rpc_message msg; |
| 4507 | struct nfs4_create_arg arg; |
| 4508 | struct nfs4_create_res res; |
| 4509 | struct nfs_fh fh; |
| 4510 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4511 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4512 | }; |
| 4513 | |
| 4514 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4515 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4516 | { |
| 4517 | struct nfs4_createdata *data; |
| 4518 | |
| 4519 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4520 | if (data != NULL) { |
| 4521 | struct nfs_server *server = NFS_SERVER(dir); |
| 4522 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4523 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4524 | if (IS_ERR(data->label)) |
| 4525 | goto out_free; |
| 4526 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4527 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4528 | data->msg.rpc_argp = &data->arg; |
| 4529 | data->msg.rpc_resp = &data->res; |
| 4530 | data->arg.dir_fh = NFS_FH(dir); |
| 4531 | data->arg.server = server; |
| 4532 | data->arg.name = name; |
| 4533 | data->arg.attrs = sattr; |
| 4534 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4535 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4536 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4537 | data->res.server = server; |
| 4538 | data->res.fh = &data->fh; |
| 4539 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4540 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4541 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4542 | } |
| 4543 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4544 | out_free: |
| 4545 | kfree(data); |
| 4546 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4550 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4551 | 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] | 4552 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4553 | if (status == 0) { |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4554 | spin_lock(&dir->i_lock); |
| 4555 | update_changeattr_locked(dir, &data->res.dir_cinfo, |
Trond Myklebust | 5636ec4 | 2018-07-31 15:54:11 -0400 | [diff] [blame] | 4556 | data->res.fattr->time_start, 0); |
Trond Myklebust | 3c59117 | 2018-07-31 15:54:10 -0400 | [diff] [blame] | 4557 | /* Creating a directory bumps nlink in the parent */ |
| 4558 | if (data->arg.ftype == NF4DIR) |
| 4559 | nfs4_inc_nlink_locked(dir); |
| 4560 | spin_unlock(&dir->i_lock); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4561 | 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] | 4562 | } |
| 4563 | return status; |
| 4564 | } |
| 4565 | |
| 4566 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4567 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4568 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4569 | kfree(data); |
| 4570 | } |
| 4571 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4572 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4573 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4574 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4576 | struct nfs4_createdata *data; |
| 4577 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4579 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4580 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4581 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4582 | status = -ENOMEM; |
| 4583 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4584 | if (data == NULL) |
| 4585 | goto out; |
| 4586 | |
| 4587 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4588 | data->arg.u.symlink.pages = &page; |
| 4589 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4590 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4592 | status = nfs4_do_create(dir, dentry, data); |
| 4593 | |
| 4594 | nfs4_free_createdata(data); |
| 4595 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | return status; |
| 4597 | } |
| 4598 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4599 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4600 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | { |
| 4602 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4603 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4605 | |
| 4606 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4609 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4610 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4611 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | &exception); |
| 4613 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4614 | |
| 4615 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | return err; |
| 4617 | } |
| 4618 | |
| 4619 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4620 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4622 | struct nfs4_createdata *data; |
| 4623 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4625 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4626 | if (data == NULL) |
| 4627 | goto out; |
| 4628 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4629 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4630 | status = nfs4_do_create(dir, dentry, data); |
| 4631 | |
| 4632 | nfs4_free_createdata(data); |
| 4633 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | return status; |
| 4635 | } |
| 4636 | |
| 4637 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4638 | struct iattr *sattr) |
| 4639 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4640 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4642 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4644 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4645 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4646 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4647 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4648 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4650 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4651 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4652 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | &exception); |
| 4654 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4655 | nfs4_label_release_security(label); |
| 4656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | return err; |
| 4658 | } |
| 4659 | |
| 4660 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4661 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4663 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | struct nfs4_readdir_arg args = { |
| 4665 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4666 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | .pgbase = 0, |
| 4668 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4669 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4670 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | }; |
| 4672 | struct nfs4_readdir_res res; |
| 4673 | struct rpc_message msg = { |
| 4674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4675 | .rpc_argp = &args, |
| 4676 | .rpc_resp = &res, |
| 4677 | .rpc_cred = cred, |
| 4678 | }; |
| 4679 | int status; |
| 4680 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4681 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4682 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4683 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4684 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4686 | 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] | 4687 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4688 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4689 | status += args.pgbase; |
| 4690 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4691 | |
| 4692 | nfs_invalidate_atime(dir); |
| 4693 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4694 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | return status; |
| 4696 | } |
| 4697 | |
| 4698 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4699 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | { |
| 4701 | struct nfs4_exception exception = { }; |
| 4702 | int err; |
| 4703 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4704 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4705 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4706 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4707 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | &exception); |
| 4709 | } while (exception.retry); |
| 4710 | return err; |
| 4711 | } |
| 4712 | |
| 4713 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4714 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4716 | struct nfs4_createdata *data; |
| 4717 | int mode = sattr->ia_mode; |
| 4718 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4720 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4721 | if (data == NULL) |
| 4722 | goto out; |
| 4723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4725 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4727 | data->arg.ftype = NF4BLK; |
| 4728 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4729 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
| 4731 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4732 | data->arg.ftype = NF4CHR; |
| 4733 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4734 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4735 | } else if (!S_ISSOCK(mode)) { |
| 4736 | status = -EINVAL; |
| 4737 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4739 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4740 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4741 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4742 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4743 | nfs4_free_createdata(data); |
| 4744 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | return status; |
| 4746 | } |
| 4747 | |
| 4748 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4749 | struct iattr *sattr, dev_t rdev) |
| 4750 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4751 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4753 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4755 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4756 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4757 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4758 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4759 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4761 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4762 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4763 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | &exception); |
| 4765 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4766 | |
| 4767 | nfs4_label_release_security(label); |
| 4768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | return err; |
| 4770 | } |
| 4771 | |
| 4772 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4773 | struct nfs_fsstat *fsstat) |
| 4774 | { |
| 4775 | struct nfs4_statfs_arg args = { |
| 4776 | .fh = fhandle, |
| 4777 | .bitmask = server->attr_bitmask, |
| 4778 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4779 | struct nfs4_statfs_res res = { |
| 4780 | .fsstat = fsstat, |
| 4781 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | struct rpc_message msg = { |
| 4783 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4784 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4785 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | }; |
| 4787 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4788 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4789 | 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] | 4790 | } |
| 4791 | |
| 4792 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4793 | { |
| 4794 | struct nfs4_exception exception = { }; |
| 4795 | int err; |
| 4796 | do { |
| 4797 | err = nfs4_handle_exception(server, |
| 4798 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4799 | &exception); |
| 4800 | } while (exception.retry); |
| 4801 | return err; |
| 4802 | } |
| 4803 | |
| 4804 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4805 | struct nfs_fsinfo *fsinfo) |
| 4806 | { |
| 4807 | struct nfs4_fsinfo_arg args = { |
| 4808 | .fh = fhandle, |
| 4809 | .bitmask = server->attr_bitmask, |
| 4810 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4811 | struct nfs4_fsinfo_res res = { |
| 4812 | .fsinfo = fsinfo, |
| 4813 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | struct rpc_message msg = { |
| 4815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4816 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4817 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | }; |
| 4819 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4820 | 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] | 4821 | } |
| 4822 | |
| 4823 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4824 | { |
| 4825 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4826 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | int err; |
| 4828 | |
| 4829 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4830 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4831 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4832 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4833 | nfs4_set_lease_period(server->nfs_client, |
| 4834 | fsinfo->lease_time * HZ, |
| 4835 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4836 | break; |
| 4837 | } |
| 4838 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | } while (exception.retry); |
| 4840 | return err; |
| 4841 | } |
| 4842 | |
| 4843 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4844 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4845 | int error; |
| 4846 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4847 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4848 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4849 | if (error == 0) { |
| 4850 | /* block layout checks this! */ |
| 4851 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4852 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4853 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4854 | |
| 4855 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4859 | struct nfs_pathconf *pathconf) |
| 4860 | { |
| 4861 | struct nfs4_pathconf_arg args = { |
| 4862 | .fh = fhandle, |
| 4863 | .bitmask = server->attr_bitmask, |
| 4864 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4865 | struct nfs4_pathconf_res res = { |
| 4866 | .pathconf = pathconf, |
| 4867 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | struct rpc_message msg = { |
| 4869 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4870 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4871 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | }; |
| 4873 | |
| 4874 | /* None of the pathconf attributes are mandatory to implement */ |
| 4875 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4876 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4877 | return 0; |
| 4878 | } |
| 4879 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4880 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4881 | 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] | 4882 | } |
| 4883 | |
| 4884 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4885 | struct nfs_pathconf *pathconf) |
| 4886 | { |
| 4887 | struct nfs4_exception exception = { }; |
| 4888 | int err; |
| 4889 | |
| 4890 | do { |
| 4891 | err = nfs4_handle_exception(server, |
| 4892 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4893 | &exception); |
| 4894 | } while (exception.retry); |
| 4895 | return err; |
| 4896 | } |
| 4897 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4898 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4899 | const struct nfs_open_context *ctx, |
| 4900 | const struct nfs_lock_context *l_ctx, |
| 4901 | fmode_t fmode) |
| 4902 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4903 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4904 | } |
| 4905 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4906 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4907 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4908 | const struct nfs_open_context *ctx, |
| 4909 | const struct nfs_lock_context *l_ctx, |
| 4910 | fmode_t fmode) |
| 4911 | { |
| 4912 | nfs4_stateid current_stateid; |
| 4913 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4914 | /* If the current stateid represents a lost lock, then exit */ |
| 4915 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4916 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4917 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4918 | } |
| 4919 | |
| 4920 | static bool nfs4_error_stateid_expired(int err) |
| 4921 | { |
| 4922 | switch (err) { |
| 4923 | case -NFS4ERR_DELEG_REVOKED: |
| 4924 | case -NFS4ERR_ADMIN_REVOKED: |
| 4925 | case -NFS4ERR_BAD_STATEID: |
| 4926 | case -NFS4ERR_STALE_STATEID: |
| 4927 | case -NFS4ERR_OLD_STATEID: |
| 4928 | case -NFS4ERR_OPENMODE: |
| 4929 | case -NFS4ERR_EXPIRED: |
| 4930 | return true; |
| 4931 | } |
| 4932 | return false; |
| 4933 | } |
| 4934 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4935 | 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] | 4936 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4937 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4939 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4940 | if (task->tk_status < 0) { |
| 4941 | struct nfs4_exception exception = { |
| 4942 | .inode = hdr->inode, |
| 4943 | .state = hdr->args.context->state, |
| 4944 | .stateid = &hdr->args.stateid, |
| 4945 | }; |
| 4946 | task->tk_status = nfs4_async_handle_exception(task, |
| 4947 | server, task->tk_status, &exception); |
| 4948 | if (exception.retry) { |
| 4949 | rpc_restart_call_prepare(task); |
| 4950 | return -EAGAIN; |
| 4951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4955 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4956 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4959 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4960 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4961 | { |
| 4962 | |
| 4963 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4964 | nfs4_stateid_is_current(&args->stateid, |
| 4965 | args->context, |
| 4966 | args->lock_context, |
| 4967 | FMODE_READ)) |
| 4968 | return false; |
| 4969 | rpc_restart_call_prepare(task); |
| 4970 | return true; |
| 4971 | } |
| 4972 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4973 | 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] | 4974 | { |
| 4975 | |
| 4976 | dprintk("--> %s\n", __func__); |
| 4977 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4978 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4979 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4980 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4981 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4982 | if (task->tk_status > 0) |
| 4983 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4984 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4985 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4988 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4989 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4991 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4992 | if (!hdr->pgio_done_cb) |
| 4993 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4994 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4995 | 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] | 4996 | } |
| 4997 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4998 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4999 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 5000 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5001 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5002 | &hdr->args.seq_args, |
| 5003 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 5004 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5005 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5006 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 5007 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 5008 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5009 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5010 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 5011 | return -EIO; |
| 5012 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5015 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 5016 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5018 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5019 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5020 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 5021 | if (task->tk_status < 0) { |
| 5022 | struct nfs4_exception exception = { |
| 5023 | .inode = hdr->inode, |
| 5024 | .state = hdr->args.context->state, |
| 5025 | .stateid = &hdr->args.stateid, |
| 5026 | }; |
| 5027 | task->tk_status = nfs4_async_handle_exception(task, |
| 5028 | NFS_SERVER(inode), task->tk_status, |
| 5029 | &exception); |
| 5030 | if (exception.retry) { |
| 5031 | rpc_restart_call_prepare(task); |
| 5032 | return -EAGAIN; |
| 5033 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5035 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5036 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 5037 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5038 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5039 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | } |
| 5041 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5042 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 5043 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5044 | { |
| 5045 | |
| 5046 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 5047 | nfs4_stateid_is_current(&args->stateid, |
| 5048 | args->context, |
| 5049 | args->lock_context, |
| 5050 | FMODE_WRITE)) |
| 5051 | return false; |
| 5052 | rpc_restart_call_prepare(task); |
| 5053 | return true; |
| 5054 | } |
| 5055 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5056 | 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] | 5057 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5058 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5059 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5060 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 5061 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5062 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 5063 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 5064 | } |
| 5065 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5066 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5067 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5068 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5069 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5070 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5071 | return false; |
| 5072 | /* Otherwise, request attributes if and only if we don't hold |
| 5073 | * a delegation |
| 5074 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5075 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5076 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5077 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5078 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5079 | struct rpc_message *msg, |
| 5080 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5082 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5083 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5084 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5085 | hdr->args.bitmask = NULL; |
| 5086 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5087 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5088 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5089 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5090 | if (!hdr->pgio_done_cb) |
| 5091 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5092 | hdr->res.server = server; |
| 5093 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5095 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5096 | 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] | 5097 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5100 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5101 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5102 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5103 | &data->args.seq_args, |
| 5104 | &data->res.seq_res, |
| 5105 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | } |
| 5107 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5108 | 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] | 5109 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5111 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5112 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5113 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5114 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5115 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5116 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5118 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5121 | 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] | 5122 | { |
| 5123 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5124 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5125 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5126 | } |
| 5127 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5128 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5129 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5131 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5132 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5133 | if (data->commit_done_cb == NULL) |
| 5134 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5135 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5136 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5137 | 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] | 5138 | 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] | 5139 | } |
| 5140 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 5141 | static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args, |
| 5142 | struct nfs_commitres *res) |
| 5143 | { |
| 5144 | struct inode *dst_inode = file_inode(dst); |
| 5145 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 5146 | struct rpc_message msg = { |
| 5147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], |
| 5148 | .rpc_argp = args, |
| 5149 | .rpc_resp = res, |
| 5150 | }; |
| 5151 | |
| 5152 | args->fh = NFS_FH(dst_inode); |
| 5153 | return nfs4_call_sync(server->client, server, &msg, |
| 5154 | &args->seq_args, &res->seq_res, 1); |
| 5155 | } |
| 5156 | |
| 5157 | int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res) |
| 5158 | { |
| 5159 | struct nfs_commitargs args = { |
| 5160 | .offset = offset, |
| 5161 | .count = count, |
| 5162 | }; |
| 5163 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 5164 | struct nfs4_exception exception = { }; |
| 5165 | int status; |
| 5166 | |
| 5167 | do { |
| 5168 | status = _nfs4_proc_commit(dst, &args, res); |
| 5169 | status = nfs4_handle_exception(dst_server, status, &exception); |
| 5170 | } while (exception.retry); |
| 5171 | |
| 5172 | return status; |
| 5173 | } |
| 5174 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5175 | struct nfs4_renewdata { |
| 5176 | struct nfs_client *client; |
| 5177 | unsigned long timestamp; |
| 5178 | }; |
| 5179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | /* |
| 5181 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5182 | * standalone procedure for queueing an asynchronous RENEW. |
| 5183 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5184 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5185 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5186 | struct nfs4_renewdata *data = calldata; |
| 5187 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5188 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5189 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5190 | nfs4_schedule_state_renewal(clp); |
| 5191 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5192 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5193 | } |
| 5194 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5195 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5197 | struct nfs4_renewdata *data = calldata; |
| 5198 | struct nfs_client *clp = data->client; |
| 5199 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5201 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5202 | switch (task->tk_status) { |
| 5203 | case 0: |
| 5204 | break; |
| 5205 | case -NFS4ERR_LEASE_MOVED: |
| 5206 | nfs4_schedule_lease_moved_recovery(clp); |
| 5207 | break; |
| 5208 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5209 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5210 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5211 | return; |
| 5212 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5213 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5214 | return; |
| 5215 | } |
| 5216 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5218 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5221 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5222 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5223 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5224 | }; |
| 5225 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5226 | static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | { |
| 5228 | struct rpc_message msg = { |
| 5229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5230 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5231 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5233 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5235 | if (renew_flags == 0) |
| 5236 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5237 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5238 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5239 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5240 | if (data == NULL) { |
| 5241 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5242 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5243 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5244 | data->client = clp; |
| 5245 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5246 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5247 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5250 | static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | { |
| 5252 | struct rpc_message msg = { |
| 5253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5254 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5255 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | }; |
| 5257 | unsigned long now = jiffies; |
| 5258 | int status; |
| 5259 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5260 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | if (status < 0) |
| 5262 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5263 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | return 0; |
| 5265 | } |
| 5266 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5267 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5268 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5269 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5270 | } |
| 5271 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5272 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5273 | * 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] | 5274 | * the stack. |
| 5275 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5276 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5277 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5278 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5279 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5280 | { |
| 5281 | struct page *newpage, **spages; |
| 5282 | int rc = 0; |
| 5283 | size_t len; |
| 5284 | spages = pages; |
| 5285 | |
| 5286 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5287 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5288 | newpage = alloc_page(GFP_KERNEL); |
| 5289 | |
| 5290 | if (newpage == NULL) |
| 5291 | goto unwind; |
| 5292 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5293 | buf += len; |
| 5294 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5295 | *pages++ = newpage; |
| 5296 | rc++; |
| 5297 | } while (buflen != 0); |
| 5298 | |
| 5299 | return rc; |
| 5300 | |
| 5301 | unwind: |
| 5302 | for(; rc > 0; rc--) |
| 5303 | __free_page(spages[rc-1]); |
| 5304 | return -ENOMEM; |
| 5305 | } |
| 5306 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5307 | struct nfs4_cached_acl { |
| 5308 | int cached; |
| 5309 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5310 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5311 | }; |
| 5312 | |
| 5313 | 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] | 5314 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5315 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5316 | |
| 5317 | spin_lock(&inode->i_lock); |
| 5318 | kfree(nfsi->nfs4_acl); |
| 5319 | nfsi->nfs4_acl = acl; |
| 5320 | spin_unlock(&inode->i_lock); |
| 5321 | } |
| 5322 | |
| 5323 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5324 | { |
| 5325 | nfs4_set_cached_acl(inode, NULL); |
| 5326 | } |
| 5327 | |
| 5328 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5329 | { |
| 5330 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5331 | struct nfs4_cached_acl *acl; |
| 5332 | int ret = -ENOENT; |
| 5333 | |
| 5334 | spin_lock(&inode->i_lock); |
| 5335 | acl = nfsi->nfs4_acl; |
| 5336 | if (acl == NULL) |
| 5337 | goto out; |
| 5338 | if (buf == NULL) /* user is just asking for length */ |
| 5339 | goto out_len; |
| 5340 | if (acl->cached == 0) |
| 5341 | goto out; |
| 5342 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5343 | if (acl->len > buflen) |
| 5344 | goto out; |
| 5345 | memcpy(buf, acl->data, acl->len); |
| 5346 | out_len: |
| 5347 | ret = acl->len; |
| 5348 | out: |
| 5349 | spin_unlock(&inode->i_lock); |
| 5350 | return ret; |
| 5351 | } |
| 5352 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5353 | 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] | 5354 | { |
| 5355 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5356 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5357 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5358 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5359 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5360 | if (acl == NULL) |
| 5361 | goto out; |
| 5362 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5363 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5364 | } else { |
| 5365 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5366 | if (acl == NULL) |
| 5367 | goto out; |
| 5368 | acl->cached = 0; |
| 5369 | } |
| 5370 | acl->len = acl_len; |
| 5371 | out: |
| 5372 | nfs4_set_cached_acl(inode, acl); |
| 5373 | } |
| 5374 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5375 | /* |
| 5376 | * The getxattr API returns the required buffer length when called with a |
| 5377 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5378 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5379 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5380 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5381 | * the cache. If not so, we throw away the page, and cache the required |
| 5382 | * length. The next getxattr call will then produce another round trip to |
| 5383 | * the server, this time with the input buf of the required size. |
| 5384 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5385 | 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] | 5386 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5387 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5388 | struct nfs_getaclargs args = { |
| 5389 | .fh = NFS_FH(inode), |
| 5390 | .acl_pages = pages, |
| 5391 | .acl_len = buflen, |
| 5392 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5393 | struct nfs_getaclres res = { |
| 5394 | .acl_len = buflen, |
| 5395 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5396 | struct rpc_message msg = { |
| 5397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5398 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5399 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5400 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5401 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5402 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5403 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5404 | if (npages > ARRAY_SIZE(pages)) |
| 5405 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5406 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5407 | for (i = 0; i < npages; i++) { |
| 5408 | pages[i] = alloc_page(GFP_KERNEL); |
| 5409 | if (!pages[i]) |
| 5410 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5411 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5412 | |
| 5413 | /* for decoding across pages */ |
| 5414 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5415 | if (!res.acl_scratch) |
| 5416 | goto out_free; |
| 5417 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5418 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5419 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5420 | 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] | 5421 | __func__, buf, buflen, npages, args.acl_len); |
| 5422 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5423 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5424 | if (ret) |
| 5425 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5426 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5427 | /* Handle the case where the passed-in buffer is too short */ |
| 5428 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5429 | /* Did the user only issue a request for the acl length? */ |
| 5430 | if (buf == NULL) |
| 5431 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5432 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5433 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5434 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5435 | 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] | 5436 | if (buf) { |
| 5437 | if (res.acl_len > buflen) { |
| 5438 | ret = -ERANGE; |
| 5439 | goto out_free; |
| 5440 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5441 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5442 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5443 | out_ok: |
| 5444 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5445 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5446 | for (i = 0; i < npages; i++) |
| 5447 | if (pages[i]) |
| 5448 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5449 | if (res.acl_scratch) |
| 5450 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5451 | return ret; |
| 5452 | } |
| 5453 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5454 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5455 | { |
| 5456 | struct nfs4_exception exception = { }; |
| 5457 | ssize_t ret; |
| 5458 | do { |
| 5459 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5460 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5461 | if (ret >= 0) |
| 5462 | break; |
| 5463 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5464 | } while (exception.retry); |
| 5465 | return ret; |
| 5466 | } |
| 5467 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5468 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5469 | { |
| 5470 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5471 | int ret; |
| 5472 | |
| 5473 | if (!nfs4_server_supports_acls(server)) |
| 5474 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5475 | ret = nfs_revalidate_inode(server, inode); |
| 5476 | if (ret < 0) |
| 5477 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5478 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5479 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5480 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5481 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5482 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5483 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5484 | return ret; |
| 5485 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5486 | } |
| 5487 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5488 | 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] | 5489 | { |
| 5490 | struct nfs_server *server = NFS_SERVER(inode); |
| 5491 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5492 | struct nfs_setaclargs arg = { |
| 5493 | .fh = NFS_FH(inode), |
| 5494 | .acl_pages = pages, |
| 5495 | .acl_len = buflen, |
| 5496 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5497 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5498 | struct rpc_message msg = { |
| 5499 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5500 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5501 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5502 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5503 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5504 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5505 | |
| 5506 | if (!nfs4_server_supports_acls(server)) |
| 5507 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5508 | if (npages > ARRAY_SIZE(pages)) |
| 5509 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5510 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5511 | if (i < 0) |
| 5512 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5513 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5514 | 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] | 5515 | |
| 5516 | /* |
| 5517 | * Free each page after tx, so the only ref left is |
| 5518 | * held by the network stack |
| 5519 | */ |
| 5520 | for (; i > 0; i--) |
| 5521 | put_page(pages[i-1]); |
| 5522 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5523 | /* |
| 5524 | * Acl update can result in inode attribute update. |
| 5525 | * so mark the attribute cache invalid. |
| 5526 | */ |
| 5527 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5528 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5529 | | NFS_INO_INVALID_CTIME |
| 5530 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5531 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5532 | nfs_access_zap_cache(inode); |
| 5533 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5534 | return ret; |
| 5535 | } |
| 5536 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5537 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5538 | { |
| 5539 | struct nfs4_exception exception = { }; |
| 5540 | int err; |
| 5541 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5542 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5543 | trace_nfs4_set_acl(inode, err); |
| 5544 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5545 | &exception); |
| 5546 | } while (exception.retry); |
| 5547 | return err; |
| 5548 | } |
| 5549 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5550 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5551 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5552 | size_t buflen) |
| 5553 | { |
| 5554 | struct nfs_server *server = NFS_SERVER(inode); |
| 5555 | struct nfs_fattr fattr; |
| 5556 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5557 | |
| 5558 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5559 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5560 | .fh = NFS_FH(inode), |
| 5561 | .bitmask = bitmask, |
| 5562 | }; |
| 5563 | struct nfs4_getattr_res res = { |
| 5564 | .fattr = &fattr, |
| 5565 | .label = &label, |
| 5566 | .server = server, |
| 5567 | }; |
| 5568 | struct rpc_message msg = { |
| 5569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5570 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5571 | .rpc_resp = &res, |
| 5572 | }; |
| 5573 | int ret; |
| 5574 | |
| 5575 | nfs_fattr_init(&fattr); |
| 5576 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5577 | 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] | 5578 | if (ret) |
| 5579 | return ret; |
| 5580 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5581 | return -ENOENT; |
| 5582 | if (buflen < label.len) |
| 5583 | return -ERANGE; |
| 5584 | return 0; |
| 5585 | } |
| 5586 | |
| 5587 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5588 | size_t buflen) |
| 5589 | { |
| 5590 | struct nfs4_exception exception = { }; |
| 5591 | int err; |
| 5592 | |
| 5593 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5594 | return -EOPNOTSUPP; |
| 5595 | |
| 5596 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5597 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5598 | trace_nfs4_get_security_label(inode, err); |
| 5599 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5600 | &exception); |
| 5601 | } while (exception.retry); |
| 5602 | return err; |
| 5603 | } |
| 5604 | |
| 5605 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5606 | struct nfs4_label *ilabel, |
| 5607 | struct nfs_fattr *fattr, |
| 5608 | struct nfs4_label *olabel) |
| 5609 | { |
| 5610 | |
| 5611 | struct iattr sattr = {0}; |
| 5612 | struct nfs_server *server = NFS_SERVER(inode); |
| 5613 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5614 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5615 | .fh = NFS_FH(inode), |
| 5616 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5617 | .server = server, |
| 5618 | .bitmask = bitmask, |
| 5619 | .label = ilabel, |
| 5620 | }; |
| 5621 | struct nfs_setattrres res = { |
| 5622 | .fattr = fattr, |
| 5623 | .label = olabel, |
| 5624 | .server = server, |
| 5625 | }; |
| 5626 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5628 | .rpc_argp = &arg, |
| 5629 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5630 | }; |
| 5631 | int status; |
| 5632 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5633 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5634 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5635 | 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] | 5636 | if (status) |
| 5637 | dprintk("%s failed: %d\n", __func__, status); |
| 5638 | |
| 5639 | return status; |
| 5640 | } |
| 5641 | |
| 5642 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5643 | struct nfs4_label *ilabel, |
| 5644 | struct nfs_fattr *fattr, |
| 5645 | struct nfs4_label *olabel) |
| 5646 | { |
| 5647 | struct nfs4_exception exception = { }; |
| 5648 | int err; |
| 5649 | |
| 5650 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5651 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5652 | fattr, olabel); |
| 5653 | trace_nfs4_set_security_label(inode, err); |
| 5654 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5655 | &exception); |
| 5656 | } while (exception.retry); |
| 5657 | return err; |
| 5658 | } |
| 5659 | |
| 5660 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5661 | 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] | 5662 | { |
| 5663 | struct nfs4_label ilabel, *olabel = NULL; |
| 5664 | struct nfs_fattr fattr; |
| 5665 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5666 | int status; |
| 5667 | |
| 5668 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5669 | return -EOPNOTSUPP; |
| 5670 | |
| 5671 | nfs_fattr_init(&fattr); |
| 5672 | |
| 5673 | ilabel.pi = 0; |
| 5674 | ilabel.lfs = 0; |
| 5675 | ilabel.label = (char *)buf; |
| 5676 | ilabel.len = buflen; |
| 5677 | |
| 5678 | cred = rpc_lookup_cred(); |
| 5679 | if (IS_ERR(cred)) |
| 5680 | return PTR_ERR(cred); |
| 5681 | |
| 5682 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5683 | if (IS_ERR(olabel)) { |
| 5684 | status = -PTR_ERR(olabel); |
| 5685 | goto out; |
| 5686 | } |
| 5687 | |
| 5688 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5689 | if (status == 0) |
| 5690 | nfs_setsecurity(inode, &fattr, olabel); |
| 5691 | |
| 5692 | nfs4_label_free(olabel); |
| 5693 | out: |
| 5694 | put_rpccred(cred); |
| 5695 | return status; |
| 5696 | } |
| 5697 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5698 | |
| 5699 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5700 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5701 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5702 | { |
| 5703 | __be32 verf[2]; |
| 5704 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5705 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5706 | /* An impossible timestamp guarantees this value |
| 5707 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5708 | verf[0] = cpu_to_be32(U32_MAX); |
| 5709 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5710 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5711 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5712 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5713 | |
| 5714 | verf[0] = cpu_to_be32(ns >> 32); |
| 5715 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5716 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5717 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5718 | } |
| 5719 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5720 | static int |
| 5721 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5722 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5723 | size_t len; |
| 5724 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5725 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5726 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5727 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5728 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5729 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5730 | len = 14 + |
| 5731 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5732 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5733 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5734 | 1; |
| 5735 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5736 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5737 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5738 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5739 | return -EINVAL; |
| 5740 | |
| 5741 | /* |
| 5742 | * Since this string is allocated at mount time, and held until the |
| 5743 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5744 | * about a memory-reclaim deadlock. |
| 5745 | */ |
| 5746 | str = kmalloc(len, GFP_KERNEL); |
| 5747 | if (!str) |
| 5748 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5749 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5750 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5751 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5752 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5753 | clp->cl_rpcclient->cl_nodename, |
| 5754 | nfs4_client_id_uniquifier, |
| 5755 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5756 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5757 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5758 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5759 | clp->cl_rpcclient->cl_nodename, |
| 5760 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5761 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5762 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5763 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5764 | clp->cl_owner_id = str; |
| 5765 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5766 | } |
| 5767 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5768 | static int |
| 5769 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5770 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5771 | size_t len; |
| 5772 | char *str; |
| 5773 | |
| 5774 | len = 10 + 10 + 1 + 10 + 1 + |
| 5775 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5776 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5777 | |
| 5778 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5779 | return -EINVAL; |
| 5780 | |
| 5781 | /* |
| 5782 | * Since this string is allocated at mount time, and held until the |
| 5783 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5784 | * about a memory-reclaim deadlock. |
| 5785 | */ |
| 5786 | str = kmalloc(len, GFP_KERNEL); |
| 5787 | if (!str) |
| 5788 | return -ENOMEM; |
| 5789 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5790 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5791 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5792 | nfs4_client_id_uniquifier, |
| 5793 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5794 | clp->cl_owner_id = str; |
| 5795 | return 0; |
| 5796 | } |
| 5797 | |
| 5798 | static int |
| 5799 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5800 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5801 | size_t len; |
| 5802 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5803 | |
| 5804 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5805 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5806 | |
| 5807 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5808 | return nfs4_init_uniquifier_client_string(clp); |
| 5809 | |
| 5810 | len = 10 + 10 + 1 + 10 + 1 + |
| 5811 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5812 | |
| 5813 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5814 | return -EINVAL; |
| 5815 | |
| 5816 | /* |
| 5817 | * Since this string is allocated at mount time, and held until the |
| 5818 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5819 | * about a memory-reclaim deadlock. |
| 5820 | */ |
| 5821 | str = kmalloc(len, GFP_KERNEL); |
| 5822 | if (!str) |
| 5823 | return -ENOMEM; |
| 5824 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5825 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5826 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5827 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5828 | clp->cl_owner_id = str; |
| 5829 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5830 | } |
| 5831 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5832 | /* |
| 5833 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5834 | * services. Advertise one based on the address family of the |
| 5835 | * clientaddr. |
| 5836 | */ |
| 5837 | static unsigned int |
| 5838 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5839 | { |
| 5840 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5841 | return scnprintf(buf, len, "tcp6"); |
| 5842 | else |
| 5843 | return scnprintf(buf, len, "tcp"); |
| 5844 | } |
| 5845 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5846 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5847 | { |
| 5848 | struct nfs4_setclientid *sc = calldata; |
| 5849 | |
| 5850 | if (task->tk_status == 0) |
| 5851 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5852 | } |
| 5853 | |
| 5854 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5855 | .rpc_call_done = nfs4_setclientid_done, |
| 5856 | }; |
| 5857 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5858 | /** |
| 5859 | * nfs4_proc_setclientid - Negotiate client ID |
| 5860 | * @clp: state data structure |
| 5861 | * @program: RPC program for NFSv4 callback service |
| 5862 | * @port: IP port number for NFS4 callback service |
| 5863 | * @cred: RPC credential to use for this call |
| 5864 | * @res: where to place the result |
| 5865 | * |
| 5866 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5867 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5868 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5869 | unsigned short port, struct rpc_cred *cred, |
| 5870 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | { |
| 5872 | nfs4_verifier sc_verifier; |
| 5873 | struct nfs4_setclientid setclientid = { |
| 5874 | .sc_verifier = &sc_verifier, |
| 5875 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5876 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | }; |
| 5878 | struct rpc_message msg = { |
| 5879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5880 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5881 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5882 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5884 | struct rpc_task *task; |
| 5885 | struct rpc_task_setup task_setup_data = { |
| 5886 | .rpc_client = clp->cl_rpcclient, |
| 5887 | .rpc_message = &msg, |
| 5888 | .callback_ops = &nfs4_setclientid_ops, |
| 5889 | .callback_data = &setclientid, |
| 5890 | .flags = RPC_TASK_TIMEOUT, |
| 5891 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5892 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5894 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5895 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5896 | |
| 5897 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5898 | status = nfs4_init_uniform_client_string(clp); |
| 5899 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5900 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5901 | |
| 5902 | if (status) |
| 5903 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5904 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5905 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5906 | setclientid.sc_netid_len = |
| 5907 | nfs4_init_callback_netid(clp, |
| 5908 | setclientid.sc_netid, |
| 5909 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5910 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5911 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5912 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5913 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5914 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5915 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5916 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5917 | task = rpc_run_task(&task_setup_data); |
| 5918 | if (IS_ERR(task)) { |
| 5919 | status = PTR_ERR(task); |
| 5920 | goto out; |
| 5921 | } |
| 5922 | status = task->tk_status; |
| 5923 | if (setclientid.sc_cred) { |
| 5924 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5925 | put_rpccred(setclientid.sc_cred); |
| 5926 | } |
| 5927 | rpc_put_task(task); |
| 5928 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5929 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5930 | dprintk("NFS reply setclientid: %d\n", status); |
| 5931 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5934 | /** |
| 5935 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5936 | * @clp: state data structure |
| 5937 | * @res: result of a previous SETCLIENTID |
| 5938 | * @cred: RPC credential to use for this call |
| 5939 | * |
| 5940 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5941 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5942 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5943 | struct nfs4_setclientid_res *arg, |
| 5944 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | struct rpc_message msg = { |
| 5947 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5948 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5949 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5951 | int status; |
| 5952 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5953 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5954 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5955 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5956 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5957 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5958 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5959 | return status; |
| 5960 | } |
| 5961 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5962 | struct nfs4_delegreturndata { |
| 5963 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5964 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5965 | struct nfs_fh fh; |
| 5966 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5967 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5968 | struct { |
| 5969 | struct nfs4_layoutreturn_args arg; |
| 5970 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5971 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5972 | u32 roc_barrier; |
| 5973 | bool roc; |
| 5974 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5975 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5976 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5977 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5978 | }; |
| 5979 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5980 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5981 | { |
| 5982 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5983 | struct nfs4_exception exception = { |
| 5984 | .inode = data->inode, |
| 5985 | .stateid = &data->stateid, |
| 5986 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5987 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5988 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5989 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5990 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5991 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5992 | |
| 5993 | /* Handle Layoutreturn errors */ |
| 5994 | if (data->args.lr_args && task->tk_status != 0) { |
| 5995 | switch(data->res.lr_ret) { |
| 5996 | default: |
| 5997 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5998 | break; |
| 5999 | case 0: |
| 6000 | data->args.lr_args = NULL; |
| 6001 | data->res.lr_res = NULL; |
| 6002 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 6003 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 6004 | if (nfs4_layoutreturn_refresh_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame^] | 6005 | &data->args.lr_args->range, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6006 | data->inode)) |
| 6007 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 6008 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6009 | case -NFS4ERR_ADMIN_REVOKED: |
| 6010 | case -NFS4ERR_DELEG_REVOKED: |
| 6011 | case -NFS4ERR_EXPIRED: |
| 6012 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6013 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 6014 | case -NFS4ERR_WRONG_CRED: |
| 6015 | data->args.lr_args = NULL; |
| 6016 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6017 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6018 | } |
| 6019 | } |
| 6020 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6021 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6022 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6023 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 6024 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6025 | case -NFS4ERR_ADMIN_REVOKED: |
| 6026 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6027 | case -NFS4ERR_EXPIRED: |
| 6028 | nfs4_free_revoked_stateid(data->res.server, |
| 6029 | data->args.stateid, |
| 6030 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6031 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6032 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6033 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 6034 | task->tk_status = 0; |
| 6035 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6036 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6037 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 6038 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 6039 | task->tk_status = 0; |
| 6040 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6041 | case -NFS4ERR_ACCESS: |
| 6042 | if (data->args.bitmask) { |
| 6043 | data->args.bitmask = NULL; |
| 6044 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6045 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 6046 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6047 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6048 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 6049 | task->tk_status = nfs4_async_handle_exception(task, |
| 6050 | data->res.server, task->tk_status, |
| 6051 | &exception); |
| 6052 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6053 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 6054 | } |
| 6055 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 6056 | return; |
| 6057 | lr_restart: |
| 6058 | data->res.lr_ret = 0; |
| 6059 | out_restart: |
| 6060 | task->tk_status = 0; |
| 6061 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | static void nfs4_delegreturn_release(void *calldata) |
| 6065 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6066 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6067 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 6068 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6069 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6070 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6071 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 6072 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 6073 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 6074 | nfs_iput_and_deactive(inode); |
| 6075 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6076 | kfree(calldata); |
| 6077 | } |
| 6078 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6079 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 6080 | { |
| 6081 | struct nfs4_delegreturndata *d_data; |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6082 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6083 | |
| 6084 | d_data = (struct nfs4_delegreturndata *)data; |
| 6085 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6086 | 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] | 6087 | return; |
| 6088 | |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 6089 | lo = d_data->args.lr_args ? d_data->args.lr_args->layout : NULL; |
| 6090 | if (lo && !pnfs_layout_is_valid(lo)) { |
| 6091 | d_data->args.lr_args = NULL; |
| 6092 | d_data->res.lr_res = NULL; |
| 6093 | } |
| 6094 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6095 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6096 | &d_data->args.seq_args, |
| 6097 | &d_data->res.seq_res, |
| 6098 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6099 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6100 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 6101 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 6102 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6103 | .rpc_call_done = nfs4_delegreturn_done, |
| 6104 | .rpc_release = nfs4_delegreturn_release, |
| 6105 | }; |
| 6106 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6107 | static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6108 | { |
| 6109 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6110 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6111 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6112 | struct rpc_message msg = { |
| 6113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6114 | .rpc_cred = cred, |
| 6115 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6116 | struct rpc_task_setup task_setup_data = { |
| 6117 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6118 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6119 | .callback_ops = &nfs4_delegreturn_ops, |
| 6120 | .flags = RPC_TASK_ASYNC, |
| 6121 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6122 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6123 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6124 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6125 | if (data == NULL) |
| 6126 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6127 | 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] | 6128 | |
| 6129 | nfs4_state_protect(server->nfs_client, |
| 6130 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6131 | &task_setup_data.rpc_client, &msg); |
| 6132 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6133 | data->args.fhandle = &data->fh; |
| 6134 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6135 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6136 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6137 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6138 | data->res.fattr = &data->fattr; |
| 6139 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6140 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6141 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6142 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6143 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6144 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6145 | 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] | 6146 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6147 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6148 | if (data->lr.roc) { |
| 6149 | data->args.lr_args = &data->lr.arg; |
| 6150 | data->res.lr_res = &data->lr.res; |
| 6151 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6152 | } else if (data->lr.roc) { |
| 6153 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6154 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6155 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6156 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6157 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6158 | msg.rpc_argp = &data->args; |
| 6159 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6160 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6161 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6162 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6163 | if (!issync) |
| 6164 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6165 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6166 | if (status != 0) |
| 6167 | goto out; |
| 6168 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6169 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6170 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6171 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6174 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | { |
| 6176 | struct nfs_server *server = NFS_SERVER(inode); |
| 6177 | struct nfs4_exception exception = { }; |
| 6178 | int err; |
| 6179 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6180 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6181 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6182 | switch (err) { |
| 6183 | case -NFS4ERR_STALE_STATEID: |
| 6184 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | case 0: |
| 6186 | return 0; |
| 6187 | } |
| 6188 | err = nfs4_handle_exception(server, err, &exception); |
| 6189 | } while (exception.retry); |
| 6190 | return err; |
| 6191 | } |
| 6192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6194 | { |
| 6195 | struct inode *inode = state->inode; |
| 6196 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6197 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6198 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6200 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6201 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6202 | struct nfs_lockt_res res = { |
| 6203 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | }; |
| 6205 | struct rpc_message msg = { |
| 6206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6207 | .rpc_argp = &arg, |
| 6208 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | .rpc_cred = state->owner->so_cred, |
| 6210 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6211 | struct nfs4_lock_state *lsp; |
| 6212 | int status; |
| 6213 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6214 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6215 | status = nfs4_set_lock_state(state, request); |
| 6216 | if (status != 0) |
| 6217 | goto out; |
| 6218 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6219 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6220 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6221 | 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] | 6222 | switch (status) { |
| 6223 | case 0: |
| 6224 | request->fl_type = F_UNLCK; |
| 6225 | break; |
| 6226 | case -NFS4ERR_DENIED: |
| 6227 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6229 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6230 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6231 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | return status; |
| 6233 | } |
| 6234 | |
| 6235 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6236 | { |
| 6237 | struct nfs4_exception exception = { }; |
| 6238 | int err; |
| 6239 | |
| 6240 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6241 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6242 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6243 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | &exception); |
| 6245 | } while (exception.retry); |
| 6246 | return err; |
| 6247 | } |
| 6248 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6249 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6250 | struct nfs_locku_args arg; |
| 6251 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6252 | struct nfs4_lock_state *lsp; |
| 6253 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6254 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6255 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6256 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6257 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6258 | }; |
| 6259 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6260 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6261 | struct nfs_open_context *ctx, |
| 6262 | struct nfs4_lock_state *lsp, |
| 6263 | struct nfs_seqid *seqid) |
| 6264 | { |
| 6265 | struct nfs4_unlockdata *p; |
| 6266 | struct inode *inode = lsp->ls_state->inode; |
| 6267 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6268 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6269 | if (p == NULL) |
| 6270 | return NULL; |
| 6271 | p->arg.fh = NFS_FH(inode); |
| 6272 | p->arg.fl = &p->fl; |
| 6273 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6274 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6275 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6276 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6277 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6278 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6279 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6280 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6281 | p->server = NFS_SERVER(inode); |
| 6282 | return p; |
| 6283 | } |
| 6284 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6285 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6286 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6287 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6288 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6289 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6290 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6291 | put_nfs_open_context(calldata->ctx); |
| 6292 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6295 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6296 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6297 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6298 | struct nfs4_exception exception = { |
| 6299 | .inode = calldata->lsp->ls_state->inode, |
| 6300 | .stateid = &calldata->arg.stateid, |
| 6301 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6302 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6303 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6304 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6305 | switch (task->tk_status) { |
| 6306 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6307 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6308 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6309 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6310 | &calldata->res.stateid)) |
| 6311 | break; |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6312 | /* Fall through */ |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6313 | case -NFS4ERR_ADMIN_REVOKED: |
| 6314 | case -NFS4ERR_EXPIRED: |
| 6315 | nfs4_free_revoked_stateid(calldata->server, |
| 6316 | &calldata->arg.stateid, |
| 6317 | task->tk_msg.rpc_cred); |
Gustavo A. R. Silva | 01e03bd | 2018-07-31 21:18:44 -0500 | [diff] [blame] | 6318 | /* Fall through */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6319 | case -NFS4ERR_BAD_STATEID: |
| 6320 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6321 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6322 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6323 | &calldata->lsp->ls_stateid)) |
| 6324 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6325 | break; |
| 6326 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6327 | task->tk_status = nfs4_async_handle_exception(task, |
| 6328 | calldata->server, task->tk_status, |
| 6329 | &exception); |
| 6330 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6331 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6332 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6333 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6334 | } |
| 6335 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6336 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6337 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6338 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6340 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6341 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6342 | return; |
| 6343 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6344 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6345 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6346 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6347 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6348 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6349 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6350 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6351 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6352 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6353 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6354 | &calldata->res.seq_res, |
| 6355 | task) != 0) |
| 6356 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6357 | return; |
| 6358 | out_no_action: |
| 6359 | task->tk_action = NULL; |
| 6360 | out_wait: |
| 6361 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | } |
| 6363 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6364 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6365 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6366 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6367 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6368 | }; |
| 6369 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6370 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6371 | struct nfs_open_context *ctx, |
| 6372 | struct nfs4_lock_state *lsp, |
| 6373 | struct nfs_seqid *seqid) |
| 6374 | { |
| 6375 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6376 | struct rpc_message msg = { |
| 6377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6378 | .rpc_cred = ctx->cred, |
| 6379 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6380 | struct rpc_task_setup task_setup_data = { |
| 6381 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6382 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6383 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6384 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6385 | .flags = RPC_TASK_ASYNC, |
| 6386 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6387 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6388 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6389 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6390 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6391 | /* Ensure this is an unlock - when canceling a lock, the |
| 6392 | * canceled lock is passed in, and it won't be an unlock. |
| 6393 | */ |
| 6394 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6395 | if (fl->fl_flags & FL_CLOSE) |
| 6396 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6397 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6398 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6399 | if (data == NULL) { |
| 6400 | nfs_free_seqid(seqid); |
| 6401 | return ERR_PTR(-ENOMEM); |
| 6402 | } |
| 6403 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6404 | 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] | 6405 | msg.rpc_argp = &data->arg; |
| 6406 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6407 | task_setup_data.callback_data = data; |
| 6408 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6409 | } |
| 6410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6411 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6412 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6413 | struct inode *inode = state->inode; |
| 6414 | struct nfs4_state_owner *sp = state->owner; |
| 6415 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6416 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6417 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6418 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6419 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6420 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6421 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6422 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6423 | status = nfs4_set_lock_state(state, request); |
| 6424 | /* Unlock _before_ we do the RPC call */ |
| 6425 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6426 | /* Exclude nfs_delegation_claim_locks() */ |
| 6427 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6428 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6429 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6430 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6431 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6432 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6433 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6434 | } |
| 6435 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6436 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6437 | if (status != 0) |
| 6438 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6439 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6440 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6441 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6442 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6443 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6444 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6445 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6446 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6447 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6448 | 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] | 6449 | status = PTR_ERR(task); |
| 6450 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6451 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6452 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6453 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6454 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6455 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6456 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6457 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6460 | struct nfs4_lockdata { |
| 6461 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6462 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6463 | struct nfs4_lock_state *lsp; |
| 6464 | struct nfs_open_context *ctx; |
| 6465 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6466 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6467 | int rpc_status; |
| 6468 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6469 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6470 | }; |
| 6471 | |
| 6472 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6473 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6474 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6475 | { |
| 6476 | struct nfs4_lockdata *p; |
| 6477 | struct inode *inode = lsp->ls_state->inode; |
| 6478 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6479 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6480 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6481 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6482 | if (p == NULL) |
| 6483 | return NULL; |
| 6484 | |
| 6485 | p->arg.fh = NFS_FH(inode); |
| 6486 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6487 | 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] | 6488 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6489 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6490 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6491 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6492 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6493 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6494 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6495 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6496 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6497 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6498 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6499 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6500 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6501 | p->ctx = get_nfs_open_context(ctx); |
| 6502 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6503 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6504 | out_free_seqid: |
| 6505 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6506 | out_free: |
| 6507 | kfree(p); |
| 6508 | return NULL; |
| 6509 | } |
| 6510 | |
| 6511 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6512 | { |
| 6513 | struct nfs4_lockdata *data = calldata; |
| 6514 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6515 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6516 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6517 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6518 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6519 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6520 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6521 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6522 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6523 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6524 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6525 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6526 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6527 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6528 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6529 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6530 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6531 | &data->lsp->ls_stateid); |
| 6532 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6533 | if (!nfs4_valid_open_stateid(state)) { |
| 6534 | data->rpc_status = -EBADF; |
| 6535 | task->tk_action = NULL; |
| 6536 | goto out_release_open_seqid; |
| 6537 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6538 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6539 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6540 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6541 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6542 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6543 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6544 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6545 | nfs_release_seqid(data->arg.open_seqid); |
| 6546 | out_release_lock_seqid: |
| 6547 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6548 | out_wait: |
| 6549 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6550 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6551 | } |
| 6552 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6553 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6554 | { |
| 6555 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6556 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6557 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6558 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6559 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6560 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6561 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6562 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6563 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6564 | switch (task->tk_status) { |
| 6565 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6566 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6567 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6568 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6569 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6570 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6571 | break; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6572 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6573 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6574 | if (data->arg.new_lock_owner != 0) { |
| 6575 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6576 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6577 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6578 | goto out_done; |
| 6579 | } else if (nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6580 | goto out_done; |
| 6581 | |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6582 | break; |
| 6583 | case -NFS4ERR_BAD_STATEID: |
| 6584 | case -NFS4ERR_OLD_STATEID: |
| 6585 | case -NFS4ERR_STALE_STATEID: |
| 6586 | case -NFS4ERR_EXPIRED: |
| 6587 | if (data->arg.new_lock_owner != 0) { |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6588 | if (nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6589 | &lsp->ls_state->open_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6590 | goto out_done; |
| 6591 | } else if (nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6592 | &lsp->ls_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6593 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6594 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6595 | if (!data->cancelled) |
| 6596 | rpc_restart_call_prepare(task); |
| 6597 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6598 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | static void nfs4_lock_release(void *calldata) |
| 6602 | { |
| 6603 | struct nfs4_lockdata *data = calldata; |
| 6604 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6605 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6606 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6607 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6608 | struct rpc_task *task; |
| 6609 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6610 | data->arg.lock_seqid); |
| 6611 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6612 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6613 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6614 | } else |
| 6615 | nfs_free_seqid(data->arg.lock_seqid); |
| 6616 | nfs4_put_lock_state(data->lsp); |
| 6617 | put_nfs_open_context(data->ctx); |
| 6618 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6619 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6620 | } |
| 6621 | |
| 6622 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6623 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6624 | .rpc_call_done = nfs4_lock_done, |
| 6625 | .rpc_release = nfs4_lock_release, |
| 6626 | }; |
| 6627 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6628 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6629 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6630 | switch (error) { |
| 6631 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6632 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6633 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6634 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6635 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6636 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6637 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6638 | break; |
| 6639 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6640 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6641 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6642 | }; |
| 6643 | } |
| 6644 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6645 | 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] | 6646 | { |
| 6647 | struct nfs4_lockdata *data; |
| 6648 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6649 | struct rpc_message msg = { |
| 6650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6651 | .rpc_cred = state->owner->so_cred, |
| 6652 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6653 | struct rpc_task_setup task_setup_data = { |
| 6654 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6655 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6656 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6657 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6658 | .flags = RPC_TASK_ASYNC, |
| 6659 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6660 | int ret; |
| 6661 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6662 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6663 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6664 | fl->fl_u.nfs4_fl.owner, |
| 6665 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6666 | if (data == NULL) |
| 6667 | return -ENOMEM; |
| 6668 | if (IS_SETLKW(cmd)) |
| 6669 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6670 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6671 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6672 | msg.rpc_argp = &data->arg; |
| 6673 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6674 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6675 | if (recovery_type > NFS_LOCK_NEW) { |
| 6676 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6677 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6678 | } else |
| 6679 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6680 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6681 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6682 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6683 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6684 | if (ret == 0) { |
| 6685 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6686 | if (ret) |
| 6687 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6688 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6689 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6690 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6691 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6692 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6693 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6694 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6698 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6699 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6700 | struct nfs4_exception exception = { |
| 6701 | .inode = state->inode, |
| 6702 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6703 | int err; |
| 6704 | |
| 6705 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6706 | /* Cache the lock if possible... */ |
| 6707 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6708 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6709 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6710 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6711 | break; |
| 6712 | nfs4_handle_exception(server, err, &exception); |
| 6713 | } while (exception.retry); |
| 6714 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6718 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6719 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6720 | struct nfs4_exception exception = { |
| 6721 | .inode = state->inode, |
| 6722 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6723 | int err; |
| 6724 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6725 | err = nfs4_set_lock_state(state, request); |
| 6726 | if (err != 0) |
| 6727 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6728 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6729 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6730 | return 0; |
| 6731 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6732 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6733 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6734 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6735 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6736 | switch (err) { |
| 6737 | default: |
| 6738 | goto out; |
| 6739 | case -NFS4ERR_GRACE: |
| 6740 | case -NFS4ERR_DELAY: |
| 6741 | nfs4_handle_exception(server, err, &exception); |
| 6742 | err = 0; |
| 6743 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6744 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6745 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6746 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6747 | } |
| 6748 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6749 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6750 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6751 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6752 | struct nfs4_lock_state *lsp; |
| 6753 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6754 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6755 | status = nfs4_set_lock_state(state, request); |
| 6756 | if (status != 0) |
| 6757 | return status; |
| 6758 | lsp = request->fl_u.nfs4_fl.owner; |
| 6759 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6760 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6761 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6762 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6763 | } |
| 6764 | #endif |
| 6765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6766 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6767 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6768 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6769 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6770 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6771 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6772 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6773 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6774 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6775 | if (status < 0) |
| 6776 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6777 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6778 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6779 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6780 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6781 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6782 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6783 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6784 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6785 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6786 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6787 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6788 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6789 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6790 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6791 | out: |
| 6792 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | return status; |
| 6794 | } |
| 6795 | |
| 6796 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6797 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6798 | struct nfs4_exception exception = { |
| 6799 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6800 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6801 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6802 | int err; |
| 6803 | |
| 6804 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6805 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6806 | if (err == -NFS4ERR_DENIED) |
| 6807 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6808 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6809 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6810 | } while (exception.retry); |
| 6811 | return err; |
| 6812 | } |
| 6813 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6814 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6815 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6816 | |
| 6817 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6818 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6819 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6820 | { |
| 6821 | int status = -ERESTARTSYS; |
| 6822 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6823 | |
| 6824 | while(!signalled()) { |
| 6825 | status = nfs4_proc_setlk(state, cmd, request); |
| 6826 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6827 | break; |
| 6828 | freezable_schedule_timeout_interruptible(timeout); |
| 6829 | timeout *= 2; |
| 6830 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6831 | status = -ERESTARTSYS; |
| 6832 | } |
| 6833 | return status; |
| 6834 | } |
| 6835 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6836 | #ifdef CONFIG_NFS_V4_1 |
| 6837 | struct nfs4_lock_waiter { |
| 6838 | struct task_struct *task; |
| 6839 | struct inode *inode; |
| 6840 | struct nfs_lowner *owner; |
| 6841 | bool notified; |
| 6842 | }; |
| 6843 | |
| 6844 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6845 | 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] | 6846 | { |
| 6847 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6848 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6849 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6850 | /* NULL key means to wake up everyone */ |
| 6851 | if (key) { |
| 6852 | struct cb_notify_lock_args *cbnl = key; |
| 6853 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6854 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6855 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6856 | /* Only wake if the callback was for the same owner. */ |
| 6857 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6858 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6859 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6860 | /* Make sure it's for the right inode */ |
| 6861 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6862 | return 0; |
| 6863 | |
| 6864 | waiter->notified = true; |
| 6865 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6866 | |
| 6867 | /* override "private" so we can use default_wake_function */ |
| 6868 | wait->private = waiter->task; |
| 6869 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6870 | wait->private = waiter; |
| 6871 | return ret; |
| 6872 | } |
| 6873 | |
| 6874 | static int |
| 6875 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6876 | { |
| 6877 | int status = -ERESTARTSYS; |
| 6878 | unsigned long flags; |
| 6879 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6880 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6881 | struct nfs_client *clp = server->nfs_client; |
| 6882 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6883 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6884 | .id = lsp->ls_seqid.owner_id, |
| 6885 | .s_dev = server->s_dev }; |
| 6886 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6887 | .inode = state->inode, |
| 6888 | .owner = &owner, |
| 6889 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6890 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6891 | |
| 6892 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6893 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6894 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6895 | |
| 6896 | init_wait(&wait); |
| 6897 | wait.private = &waiter; |
| 6898 | wait.func = nfs4_wake_lock_waiter; |
| 6899 | add_wait_queue(q, &wait); |
| 6900 | |
| 6901 | while(!signalled()) { |
Jeff Layton | 41a7462 | 2018-03-18 08:37:01 -0400 | [diff] [blame] | 6902 | waiter.notified = false; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6903 | status = nfs4_proc_setlk(state, cmd, request); |
| 6904 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6905 | break; |
| 6906 | |
| 6907 | status = -ERESTARTSYS; |
| 6908 | spin_lock_irqsave(&q->lock, flags); |
| 6909 | if (waiter.notified) { |
| 6910 | spin_unlock_irqrestore(&q->lock, flags); |
| 6911 | continue; |
| 6912 | } |
| 6913 | set_current_state(TASK_INTERRUPTIBLE); |
| 6914 | spin_unlock_irqrestore(&q->lock, flags); |
| 6915 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6916 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6917 | } |
| 6918 | |
| 6919 | finish_wait(q, &wait); |
| 6920 | return status; |
| 6921 | } |
| 6922 | #else /* !CONFIG_NFS_V4_1 */ |
| 6923 | static inline int |
| 6924 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6925 | { |
| 6926 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6927 | } |
| 6928 | #endif |
| 6929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6930 | static int |
| 6931 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6932 | { |
| 6933 | struct nfs_open_context *ctx; |
| 6934 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6935 | int status; |
| 6936 | |
| 6937 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6938 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6939 | state = ctx->state; |
| 6940 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6941 | if (IS_GETLK(cmd)) { |
| 6942 | if (state != NULL) |
| 6943 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6944 | return 0; |
| 6945 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6946 | |
| 6947 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6948 | return -EINVAL; |
| 6949 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6950 | if (request->fl_type == F_UNLCK) { |
| 6951 | if (state != NULL) |
| 6952 | return nfs4_proc_unlck(state, cmd, request); |
| 6953 | return 0; |
| 6954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6955 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6956 | if (state == NULL) |
| 6957 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6958 | |
| 6959 | if ((request->fl_flags & FL_POSIX) && |
| 6960 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6961 | return -ENOLCK; |
| 6962 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6963 | /* |
| 6964 | * Don't rely on the VFS having checked the file open mode, |
| 6965 | * since it won't do this for flock() locks. |
| 6966 | */ |
| 6967 | switch (request->fl_type) { |
| 6968 | case F_RDLCK: |
| 6969 | if (!(filp->f_mode & FMODE_READ)) |
| 6970 | return -EBADF; |
| 6971 | break; |
| 6972 | case F_WRLCK: |
| 6973 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6974 | return -EBADF; |
| 6975 | } |
| 6976 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6977 | status = nfs4_set_lock_state(state, request); |
| 6978 | if (status != 0) |
| 6979 | return status; |
| 6980 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6981 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6984 | 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] | 6985 | { |
| 6986 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6987 | int err; |
| 6988 | |
| 6989 | err = nfs4_set_lock_state(state, fl); |
| 6990 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6991 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6992 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 6993 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6994 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6995 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6996 | struct nfs_release_lockowner_data { |
| 6997 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6998 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6999 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7000 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7001 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7002 | }; |
| 7003 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7004 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 7005 | { |
| 7006 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7007 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7008 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 7009 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7010 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7011 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 7015 | { |
| 7016 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7017 | struct nfs_server *server = data->server; |
| 7018 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7019 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7020 | |
| 7021 | switch (task->tk_status) { |
| 7022 | case 0: |
| 7023 | renew_lease(server, data->timestamp); |
| 7024 | break; |
| 7025 | case -NFS4ERR_STALE_CLIENTID: |
| 7026 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 7027 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 7028 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7029 | case -NFS4ERR_LEASE_MOVED: |
| 7030 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 7031 | if (nfs4_async_handle_error(task, server, |
| 7032 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 7033 | rpc_restart_call_prepare(task); |
| 7034 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7035 | } |
| 7036 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7037 | static void nfs4_release_lockowner_release(void *calldata) |
| 7038 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7039 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7040 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7041 | kfree(calldata); |
| 7042 | } |
| 7043 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7044 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7045 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 7046 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7047 | .rpc_release = nfs4_release_lockowner_release, |
| 7048 | }; |
| 7049 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7050 | static void |
| 7051 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7052 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7053 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7054 | struct rpc_message msg = { |
| 7055 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 7056 | }; |
| 7057 | |
| 7058 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7059 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7060 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7061 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 7062 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 7063 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7064 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 7065 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7066 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 7067 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 7068 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 7069 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 7070 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 7071 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7072 | 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] | 7073 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 7074 | } |
| 7075 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7076 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 7077 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7078 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7079 | struct dentry *unused, struct inode *inode, |
| 7080 | const char *key, const void *buf, |
| 7081 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7082 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7083 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7084 | } |
| 7085 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7086 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7087 | struct dentry *unused, struct inode *inode, |
| 7088 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7089 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7090 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7093 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7094 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 7095 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7098 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7099 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7100 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7101 | struct dentry *unused, struct inode *inode, |
| 7102 | const char *key, const void *buf, |
| 7103 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7104 | { |
| 7105 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 7106 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7107 | |
| 7108 | return -EOPNOTSUPP; |
| 7109 | } |
| 7110 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 7111 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7112 | struct dentry *unused, struct inode *inode, |
| 7113 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7114 | { |
| 7115 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7116 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7117 | return -EOPNOTSUPP; |
| 7118 | } |
| 7119 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7120 | static ssize_t |
| 7121 | 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] | 7122 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7123 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7124 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7125 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7126 | len = security_inode_listsecurity(inode, list, list_len); |
| 7127 | if (list_len && len > list_len) |
| 7128 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7129 | } |
| 7130 | return len; |
| 7131 | } |
| 7132 | |
| 7133 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7134 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7135 | .get = nfs4_xattr_get_nfs4_label, |
| 7136 | .set = nfs4_xattr_set_nfs4_label, |
| 7137 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7138 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7139 | #else |
| 7140 | |
| 7141 | static ssize_t |
| 7142 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7143 | { |
| 7144 | return 0; |
| 7145 | } |
| 7146 | |
| 7147 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7148 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7149 | /* |
| 7150 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7151 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7152 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7153 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7154 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7155 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7156 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7157 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7158 | return; |
| 7159 | |
| 7160 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7161 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7162 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7163 | fattr->nlink = 2; |
| 7164 | } |
| 7165 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7166 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7167 | const struct qstr *name, |
| 7168 | struct nfs4_fs_locations *fs_locations, |
| 7169 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7170 | { |
| 7171 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7172 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7173 | struct nfs4_fs_locations_arg args = { |
| 7174 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7175 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7176 | .page = page, |
| 7177 | .bitmask = bitmask, |
| 7178 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7179 | struct nfs4_fs_locations_res res = { |
| 7180 | .fs_locations = fs_locations, |
| 7181 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7182 | struct rpc_message msg = { |
| 7183 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7184 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7185 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7186 | }; |
| 7187 | int status; |
| 7188 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7189 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7190 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7191 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7192 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7193 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7194 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7195 | * is not supported */ |
| 7196 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7197 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7198 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7199 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7200 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7201 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7202 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7203 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7204 | 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] | 7205 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7206 | return status; |
| 7207 | } |
| 7208 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7209 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7210 | const struct qstr *name, |
| 7211 | struct nfs4_fs_locations *fs_locations, |
| 7212 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7213 | { |
| 7214 | struct nfs4_exception exception = { }; |
| 7215 | int err; |
| 7216 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7217 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7218 | fs_locations, page); |
| 7219 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7220 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7221 | &exception); |
| 7222 | } while (exception.retry); |
| 7223 | return err; |
| 7224 | } |
| 7225 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7226 | /* |
| 7227 | * This operation also signals the server that this client is |
| 7228 | * performing migration recovery. The server can stop returning |
| 7229 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7230 | * appended to this compound to identify the client ID which is |
| 7231 | * performing recovery. |
| 7232 | */ |
| 7233 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7234 | struct nfs4_fs_locations *locations, |
| 7235 | struct page *page, struct rpc_cred *cred) |
| 7236 | { |
| 7237 | struct nfs_server *server = NFS_SERVER(inode); |
| 7238 | struct rpc_clnt *clnt = server->client; |
| 7239 | u32 bitmask[2] = { |
| 7240 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7241 | }; |
| 7242 | struct nfs4_fs_locations_arg args = { |
| 7243 | .clientid = server->nfs_client->cl_clientid, |
| 7244 | .fh = NFS_FH(inode), |
| 7245 | .page = page, |
| 7246 | .bitmask = bitmask, |
| 7247 | .migration = 1, /* skip LOOKUP */ |
| 7248 | .renew = 1, /* append RENEW */ |
| 7249 | }; |
| 7250 | struct nfs4_fs_locations_res res = { |
| 7251 | .fs_locations = locations, |
| 7252 | .migration = 1, |
| 7253 | .renew = 1, |
| 7254 | }; |
| 7255 | struct rpc_message msg = { |
| 7256 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7257 | .rpc_argp = &args, |
| 7258 | .rpc_resp = &res, |
| 7259 | .rpc_cred = cred, |
| 7260 | }; |
| 7261 | unsigned long now = jiffies; |
| 7262 | int status; |
| 7263 | |
| 7264 | nfs_fattr_init(&locations->fattr); |
| 7265 | locations->server = server; |
| 7266 | locations->nlocations = 0; |
| 7267 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7268 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7269 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7270 | &args.seq_args, &res.seq_res); |
| 7271 | if (status) |
| 7272 | return status; |
| 7273 | |
| 7274 | renew_lease(server, now); |
| 7275 | return 0; |
| 7276 | } |
| 7277 | |
| 7278 | #ifdef CONFIG_NFS_V4_1 |
| 7279 | |
| 7280 | /* |
| 7281 | * This operation also signals the server that this client is |
| 7282 | * performing migration recovery. The server can stop asserting |
| 7283 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7284 | * performing this operation is identified in the SEQUENCE |
| 7285 | * operation in this compound. |
| 7286 | * |
| 7287 | * When the client supports GETATTR(fs_locations_info), it can |
| 7288 | * be plumbed in here. |
| 7289 | */ |
| 7290 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7291 | struct nfs4_fs_locations *locations, |
| 7292 | struct page *page, struct rpc_cred *cred) |
| 7293 | { |
| 7294 | struct nfs_server *server = NFS_SERVER(inode); |
| 7295 | struct rpc_clnt *clnt = server->client; |
| 7296 | u32 bitmask[2] = { |
| 7297 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7298 | }; |
| 7299 | struct nfs4_fs_locations_arg args = { |
| 7300 | .fh = NFS_FH(inode), |
| 7301 | .page = page, |
| 7302 | .bitmask = bitmask, |
| 7303 | .migration = 1, /* skip LOOKUP */ |
| 7304 | }; |
| 7305 | struct nfs4_fs_locations_res res = { |
| 7306 | .fs_locations = locations, |
| 7307 | .migration = 1, |
| 7308 | }; |
| 7309 | struct rpc_message msg = { |
| 7310 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7311 | .rpc_argp = &args, |
| 7312 | .rpc_resp = &res, |
| 7313 | .rpc_cred = cred, |
| 7314 | }; |
| 7315 | int status; |
| 7316 | |
| 7317 | nfs_fattr_init(&locations->fattr); |
| 7318 | locations->server = server; |
| 7319 | locations->nlocations = 0; |
| 7320 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7321 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7322 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7323 | &args.seq_args, &res.seq_res); |
| 7324 | if (status == NFS4_OK && |
| 7325 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7326 | status = -NFS4ERR_LEASE_MOVED; |
| 7327 | return status; |
| 7328 | } |
| 7329 | |
| 7330 | #endif /* CONFIG_NFS_V4_1 */ |
| 7331 | |
| 7332 | /** |
| 7333 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7334 | * @inode: inode on FSID that is migrating |
| 7335 | * @locations: result of query |
| 7336 | * @page: buffer |
| 7337 | * @cred: credential to use for this operation |
| 7338 | * |
| 7339 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7340 | * operation failed, or a negative errno if a local error occurred. |
| 7341 | * |
| 7342 | * On success, "locations" is filled in, but if the server has |
| 7343 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7344 | * asserted. |
| 7345 | * |
| 7346 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7347 | * from this client that require migration recovery. |
| 7348 | */ |
| 7349 | int nfs4_proc_get_locations(struct inode *inode, |
| 7350 | struct nfs4_fs_locations *locations, |
| 7351 | struct page *page, struct rpc_cred *cred) |
| 7352 | { |
| 7353 | struct nfs_server *server = NFS_SERVER(inode); |
| 7354 | struct nfs_client *clp = server->nfs_client; |
| 7355 | const struct nfs4_mig_recovery_ops *ops = |
| 7356 | clp->cl_mvops->mig_recovery_ops; |
| 7357 | struct nfs4_exception exception = { }; |
| 7358 | int status; |
| 7359 | |
| 7360 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7361 | (unsigned long long)server->fsid.major, |
| 7362 | (unsigned long long)server->fsid.minor, |
| 7363 | clp->cl_hostname); |
| 7364 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7365 | |
| 7366 | do { |
| 7367 | status = ops->get_locations(inode, locations, page, cred); |
| 7368 | if (status != -NFS4ERR_DELAY) |
| 7369 | break; |
| 7370 | nfs4_handle_exception(server, status, &exception); |
| 7371 | } while (exception.retry); |
| 7372 | return status; |
| 7373 | } |
| 7374 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7375 | /* |
| 7376 | * This operation also signals the server that this client is |
| 7377 | * performing "lease moved" recovery. The server can stop |
| 7378 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7379 | * is appended to this compound to identify the client ID which is |
| 7380 | * performing recovery. |
| 7381 | */ |
| 7382 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7383 | { |
| 7384 | struct nfs_server *server = NFS_SERVER(inode); |
| 7385 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7386 | struct rpc_clnt *clnt = server->client; |
| 7387 | struct nfs4_fsid_present_arg args = { |
| 7388 | .fh = NFS_FH(inode), |
| 7389 | .clientid = clp->cl_clientid, |
| 7390 | .renew = 1, /* append RENEW */ |
| 7391 | }; |
| 7392 | struct nfs4_fsid_present_res res = { |
| 7393 | .renew = 1, |
| 7394 | }; |
| 7395 | struct rpc_message msg = { |
| 7396 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7397 | .rpc_argp = &args, |
| 7398 | .rpc_resp = &res, |
| 7399 | .rpc_cred = cred, |
| 7400 | }; |
| 7401 | unsigned long now = jiffies; |
| 7402 | int status; |
| 7403 | |
| 7404 | res.fh = nfs_alloc_fhandle(); |
| 7405 | if (res.fh == NULL) |
| 7406 | return -ENOMEM; |
| 7407 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7408 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7409 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7410 | &args.seq_args, &res.seq_res); |
| 7411 | nfs_free_fhandle(res.fh); |
| 7412 | if (status) |
| 7413 | return status; |
| 7414 | |
| 7415 | do_renew_lease(clp, now); |
| 7416 | return 0; |
| 7417 | } |
| 7418 | |
| 7419 | #ifdef CONFIG_NFS_V4_1 |
| 7420 | |
| 7421 | /* |
| 7422 | * This operation also signals the server that this client is |
| 7423 | * performing "lease moved" recovery. The server can stop asserting |
| 7424 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7425 | * this operation is identified in the SEQUENCE operation in this |
| 7426 | * compound. |
| 7427 | */ |
| 7428 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7429 | { |
| 7430 | struct nfs_server *server = NFS_SERVER(inode); |
| 7431 | struct rpc_clnt *clnt = server->client; |
| 7432 | struct nfs4_fsid_present_arg args = { |
| 7433 | .fh = NFS_FH(inode), |
| 7434 | }; |
| 7435 | struct nfs4_fsid_present_res res = { |
| 7436 | }; |
| 7437 | struct rpc_message msg = { |
| 7438 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7439 | .rpc_argp = &args, |
| 7440 | .rpc_resp = &res, |
| 7441 | .rpc_cred = cred, |
| 7442 | }; |
| 7443 | int status; |
| 7444 | |
| 7445 | res.fh = nfs_alloc_fhandle(); |
| 7446 | if (res.fh == NULL) |
| 7447 | return -ENOMEM; |
| 7448 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7449 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7450 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7451 | &args.seq_args, &res.seq_res); |
| 7452 | nfs_free_fhandle(res.fh); |
| 7453 | if (status == NFS4_OK && |
| 7454 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7455 | status = -NFS4ERR_LEASE_MOVED; |
| 7456 | return status; |
| 7457 | } |
| 7458 | |
| 7459 | #endif /* CONFIG_NFS_V4_1 */ |
| 7460 | |
| 7461 | /** |
| 7462 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7463 | * @inode: inode on FSID to check |
| 7464 | * @cred: credential to use for this operation |
| 7465 | * |
| 7466 | * Server indicates whether the FSID is present, moved, or not |
| 7467 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7468 | * condition for this client ID. |
| 7469 | * |
| 7470 | * Returns NFS4_OK if the FSID is present on this server, |
| 7471 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7472 | * NFS4ERR code if some error occurred on the server, or a |
| 7473 | * negative errno if a local failure occurred. |
| 7474 | */ |
| 7475 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7476 | { |
| 7477 | struct nfs_server *server = NFS_SERVER(inode); |
| 7478 | struct nfs_client *clp = server->nfs_client; |
| 7479 | const struct nfs4_mig_recovery_ops *ops = |
| 7480 | clp->cl_mvops->mig_recovery_ops; |
| 7481 | struct nfs4_exception exception = { }; |
| 7482 | int status; |
| 7483 | |
| 7484 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7485 | (unsigned long long)server->fsid.major, |
| 7486 | (unsigned long long)server->fsid.minor, |
| 7487 | clp->cl_hostname); |
| 7488 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7489 | |
| 7490 | do { |
| 7491 | status = ops->fsid_present(inode, cred); |
| 7492 | if (status != -NFS4ERR_DELAY) |
| 7493 | break; |
| 7494 | nfs4_handle_exception(server, status, &exception); |
| 7495 | } while (exception.retry); |
| 7496 | return status; |
| 7497 | } |
| 7498 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7499 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7500 | * If 'use_integrity' is true and the state managment nfs_client |
| 7501 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7502 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7503 | * Considerations sections. Otherwise, just use the user cred with the |
| 7504 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7505 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7506 | 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] | 7507 | { |
| 7508 | int status; |
| 7509 | struct nfs4_secinfo_arg args = { |
| 7510 | .dir_fh = NFS_FH(dir), |
| 7511 | .name = name, |
| 7512 | }; |
| 7513 | struct nfs4_secinfo_res res = { |
| 7514 | .flavors = flavors, |
| 7515 | }; |
| 7516 | struct rpc_message msg = { |
| 7517 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7518 | .rpc_argp = &args, |
| 7519 | .rpc_resp = &res, |
| 7520 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7521 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7522 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7523 | |
| 7524 | if (use_integrity) { |
| 7525 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7526 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7527 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7528 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7529 | |
| 7530 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7531 | |
| 7532 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7533 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7534 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7535 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7536 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7537 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7538 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7539 | if (cred) |
| 7540 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7541 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7542 | return status; |
| 7543 | } |
| 7544 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7545 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7546 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7547 | { |
| 7548 | struct nfs4_exception exception = { }; |
| 7549 | int err; |
| 7550 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7551 | err = -NFS4ERR_WRONGSEC; |
| 7552 | |
| 7553 | /* try to use integrity protection with machine cred */ |
| 7554 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7555 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7556 | |
| 7557 | /* |
| 7558 | * if unable to use integrity protection, or SECINFO with |
| 7559 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7560 | * disallowed by spec, but exists in deployed servers) use |
| 7561 | * the current filesystem's rpc_client and the user cred. |
| 7562 | */ |
| 7563 | if (err == -NFS4ERR_WRONGSEC) |
| 7564 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7565 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7566 | trace_nfs4_secinfo(dir, name, err); |
| 7567 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7568 | &exception); |
| 7569 | } while (exception.retry); |
| 7570 | return err; |
| 7571 | } |
| 7572 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7573 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7574 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7575 | * Check the exchange flags returned by the server for invalid flags, having |
| 7576 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7577 | * DS flags set. |
| 7578 | */ |
| 7579 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7580 | { |
| 7581 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7582 | goto out_inval; |
| 7583 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7584 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7585 | goto out_inval; |
| 7586 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7587 | goto out_inval; |
| 7588 | return NFS_OK; |
| 7589 | out_inval: |
| 7590 | return -NFS4ERR_INVAL; |
| 7591 | } |
| 7592 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7593 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7594 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7595 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7596 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7597 | if (a->server_scope_sz != b->server_scope_sz) |
| 7598 | return false; |
| 7599 | 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] | 7600 | } |
| 7601 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7602 | static void |
| 7603 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7604 | { |
| 7605 | } |
| 7606 | |
| 7607 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7608 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7609 | }; |
| 7610 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7611 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7612 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7613 | * |
| 7614 | * The 4.1 client currently uses the same TCP connection for the |
| 7615 | * fore and backchannel. |
| 7616 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7617 | static |
| 7618 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7619 | struct rpc_xprt *xprt, |
| 7620 | struct nfs_client *clp, |
| 7621 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7622 | { |
| 7623 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7624 | struct nfs41_bind_conn_to_session_args args = { |
| 7625 | .client = clp, |
| 7626 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7627 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7628 | struct nfs41_bind_conn_to_session_res res; |
| 7629 | struct rpc_message msg = { |
| 7630 | .rpc_proc = |
| 7631 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7632 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7633 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7634 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7635 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7636 | struct rpc_task_setup task_setup_data = { |
| 7637 | .rpc_client = clnt, |
| 7638 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7639 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7640 | .rpc_message = &msg, |
| 7641 | .flags = RPC_TASK_TIMEOUT, |
| 7642 | }; |
| 7643 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7644 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7645 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7646 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7647 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7648 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7649 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7650 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7651 | args.dir = NFS4_CDFC4_FORE; |
| 7652 | |
| 7653 | task = rpc_run_task(&task_setup_data); |
| 7654 | if (!IS_ERR(task)) { |
| 7655 | status = task->tk_status; |
| 7656 | rpc_put_task(task); |
| 7657 | } else |
| 7658 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7659 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7660 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7661 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7662 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7663 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7664 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7665 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7666 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7667 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7668 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7669 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7670 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7671 | 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] | 7672 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7673 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7674 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7675 | } |
| 7676 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7677 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7678 | return status; |
| 7679 | } |
| 7680 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7681 | struct rpc_bind_conn_calldata { |
| 7682 | struct nfs_client *clp; |
| 7683 | struct rpc_cred *cred; |
| 7684 | }; |
| 7685 | |
| 7686 | static int |
| 7687 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7688 | struct rpc_xprt *xprt, |
| 7689 | void *calldata) |
| 7690 | { |
| 7691 | struct rpc_bind_conn_calldata *p = calldata; |
| 7692 | |
| 7693 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7694 | } |
| 7695 | |
| 7696 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7697 | { |
| 7698 | struct rpc_bind_conn_calldata data = { |
| 7699 | .clp = clp, |
| 7700 | .cred = cred, |
| 7701 | }; |
| 7702 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7703 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7704 | } |
| 7705 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7706 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7707 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7708 | * 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] | 7709 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7710 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7711 | .how = SP4_MACH_CRED, |
| 7712 | .enforce.u.words = { |
| 7713 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7714 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7715 | 1 << (OP_CREATE_SESSION - 32) | |
| 7716 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7717 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7718 | }, |
| 7719 | .allow.u.words = { |
| 7720 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7721 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7722 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7723 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7724 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7725 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7726 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7727 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7728 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7729 | 1 << (OP_FREE_STATEID - 32) | |
| 7730 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7731 | } |
| 7732 | }; |
| 7733 | |
| 7734 | /* |
| 7735 | * Select the state protection mode for client `clp' given the server results |
| 7736 | * from exchange_id in `sp'. |
| 7737 | * |
| 7738 | * Returns 0 on success, negative errno otherwise. |
| 7739 | */ |
| 7740 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7741 | struct nfs41_state_protection *sp) |
| 7742 | { |
| 7743 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7744 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7745 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7746 | 1 << (OP_CREATE_SESSION - 32) | |
| 7747 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7748 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7749 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7750 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7751 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7752 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7753 | |
| 7754 | if (sp->how == SP4_MACH_CRED) { |
| 7755 | /* Print state protect result */ |
| 7756 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7757 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7758 | if (test_bit(i, sp->enforce.u.longs)) |
| 7759 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7760 | if (test_bit(i, sp->allow.u.longs)) |
| 7761 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7762 | } |
| 7763 | |
| 7764 | /* make sure nothing is on enforce list that isn't supported */ |
| 7765 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7766 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7767 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7768 | ret = -EINVAL; |
| 7769 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7770 | } |
| 7771 | } |
| 7772 | |
| 7773 | /* |
| 7774 | * Minimal mode - state operations are allowed to use machine |
| 7775 | * credential. Note this already happens by default, so the |
| 7776 | * client doesn't have to do anything more than the negotiation. |
| 7777 | * |
| 7778 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7779 | * we're already using the machine cred for exchange_id |
| 7780 | * and will never use a different cred. |
| 7781 | */ |
| 7782 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7783 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7784 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7785 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7786 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7787 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7788 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7789 | } else { |
| 7790 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7791 | ret = -EINVAL; |
| 7792 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7793 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7794 | |
| 7795 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7796 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7797 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7798 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7799 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7800 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7801 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7802 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7803 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7804 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7805 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7806 | } |
| 7807 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7808 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7809 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7810 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7811 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7812 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7813 | |
| 7814 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7815 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7816 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7817 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7818 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7819 | |
| 7820 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7821 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7822 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7826 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7827 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7828 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7829 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7830 | out: |
| 7831 | clp->cl_sp4_flags = flags; |
Wei Yongjun | 72bf75c | 2018-08-02 05:42:04 +0000 | [diff] [blame] | 7832 | return ret; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7833 | } |
| 7834 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7835 | struct nfs41_exchange_id_data { |
| 7836 | struct nfs41_exchange_id_res res; |
| 7837 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7838 | }; |
| 7839 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7840 | static void nfs4_exchange_id_release(void *data) |
| 7841 | { |
| 7842 | struct nfs41_exchange_id_data *cdata = |
| 7843 | (struct nfs41_exchange_id_data *)data; |
| 7844 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7845 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7846 | kfree(cdata->res.impl_id); |
| 7847 | kfree(cdata->res.server_scope); |
| 7848 | kfree(cdata->res.server_owner); |
| 7849 | kfree(cdata); |
| 7850 | } |
| 7851 | |
| 7852 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7853 | .rpc_release = nfs4_exchange_id_release, |
| 7854 | }; |
| 7855 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7856 | /* |
| 7857 | * _nfs4_proc_exchange_id() |
| 7858 | * |
| 7859 | * Wrapper for EXCHANGE_ID operation. |
| 7860 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7861 | static struct rpc_task * |
| 7862 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7863 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7864 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7865 | struct rpc_message msg = { |
| 7866 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7867 | .rpc_cred = cred, |
| 7868 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7869 | struct rpc_task_setup task_setup_data = { |
| 7870 | .rpc_client = clp->cl_rpcclient, |
| 7871 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7872 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7873 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7874 | }; |
| 7875 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7876 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7877 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7878 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7879 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7880 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7881 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7882 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7883 | if (!calldata) |
| 7884 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7885 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7886 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7887 | |
| 7888 | status = nfs4_init_uniform_client_string(clp); |
| 7889 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7890 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7891 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7892 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7893 | GFP_NOFS); |
| 7894 | status = -ENOMEM; |
| 7895 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7896 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7897 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7898 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7899 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7900 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7901 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7902 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7903 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7904 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7905 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7906 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7907 | switch (sp4_how) { |
| 7908 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7909 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7910 | break; |
| 7911 | |
| 7912 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7913 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7914 | break; |
| 7915 | |
| 7916 | default: |
| 7917 | /* unsupported! */ |
| 7918 | WARN_ON_ONCE(1); |
| 7919 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7920 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7921 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7922 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7923 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7924 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7925 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7926 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7927 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7928 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7929 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7930 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7931 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7932 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7933 | #endif |
| 7934 | msg.rpc_argp = &calldata->args; |
| 7935 | msg.rpc_resp = &calldata->res; |
| 7936 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7937 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7938 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7939 | |
| 7940 | out_impl_id: |
| 7941 | kfree(calldata->res.impl_id); |
| 7942 | out_server_scope: |
| 7943 | kfree(calldata->res.server_scope); |
| 7944 | out_server_owner: |
| 7945 | kfree(calldata->res.server_owner); |
| 7946 | out_calldata: |
| 7947 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7948 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7949 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7950 | return ERR_PTR(status); |
| 7951 | } |
| 7952 | |
| 7953 | /* |
| 7954 | * _nfs4_proc_exchange_id() |
| 7955 | * |
| 7956 | * Wrapper for EXCHANGE_ID operation. |
| 7957 | */ |
| 7958 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7959 | u32 sp4_how) |
| 7960 | { |
| 7961 | struct rpc_task *task; |
| 7962 | struct nfs41_exchange_id_args *argp; |
| 7963 | struct nfs41_exchange_id_res *resp; |
| 7964 | int status; |
| 7965 | |
| 7966 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7967 | if (IS_ERR(task)) |
| 7968 | return PTR_ERR(task); |
| 7969 | |
| 7970 | argp = task->tk_msg.rpc_argp; |
| 7971 | resp = task->tk_msg.rpc_resp; |
| 7972 | status = task->tk_status; |
| 7973 | if (status != 0) |
| 7974 | goto out; |
| 7975 | |
| 7976 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7977 | if (status != 0) |
| 7978 | goto out; |
| 7979 | |
| 7980 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7981 | if (status != 0) |
| 7982 | goto out; |
| 7983 | |
| 7984 | clp->cl_clientid = resp->clientid; |
| 7985 | clp->cl_exchange_flags = resp->flags; |
| 7986 | clp->cl_seqid = resp->seqid; |
| 7987 | /* Client ID is not confirmed */ |
| 7988 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7989 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7990 | &clp->cl_session->session_state); |
| 7991 | |
| 7992 | if (clp->cl_serverscope != NULL && |
| 7993 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7994 | resp->server_scope)) { |
| 7995 | dprintk("%s: server_scope mismatch detected\n", |
| 7996 | __func__); |
| 7997 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7998 | } |
| 7999 | |
| 8000 | swap(clp->cl_serverowner, resp->server_owner); |
| 8001 | swap(clp->cl_serverscope, resp->server_scope); |
| 8002 | swap(clp->cl_implid, resp->impl_id); |
| 8003 | |
| 8004 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 8005 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 8006 | sizeof(clp->cl_confirm.data)); |
| 8007 | out: |
| 8008 | trace_nfs4_exchange_id(clp, status); |
| 8009 | rpc_put_task(task); |
| 8010 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 8011 | } |
| 8012 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8013 | /* |
| 8014 | * nfs4_proc_exchange_id() |
| 8015 | * |
| 8016 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 8017 | * |
| 8018 | * Since the clientid has expired, all compounds using sessions |
| 8019 | * associated with the stale clientid will be returning |
| 8020 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 8021 | * be in some phase of session reset. |
| 8022 | * |
| 8023 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 8024 | */ |
| 8025 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 8026 | { |
| 8027 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 8028 | int status; |
| 8029 | |
| 8030 | /* try SP4_MACH_CRED if krb5i/p */ |
| 8031 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 8032 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8033 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8034 | if (!status) |
| 8035 | return 0; |
| 8036 | } |
| 8037 | |
| 8038 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8039 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 8040 | } |
| 8041 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8042 | /** |
| 8043 | * nfs4_test_session_trunk |
| 8044 | * |
| 8045 | * This is an add_xprt_test() test function called from |
| 8046 | * rpc_clnt_setup_test_and_add_xprt. |
| 8047 | * |
| 8048 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 8049 | * and is dereferrenced in nfs4_exchange_id_release |
| 8050 | * |
| 8051 | * Upon success, add the new transport to the rpc_clnt |
| 8052 | * |
| 8053 | * @clnt: struct rpc_clnt to get new transport |
| 8054 | * @xprt: the rpc_xprt to test |
| 8055 | * @data: call data for _nfs4_proc_exchange_id. |
| 8056 | */ |
| 8057 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 8058 | void *data) |
| 8059 | { |
| 8060 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8061 | struct rpc_task *task; |
| 8062 | int status; |
| 8063 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8064 | u32 sp4_how; |
| 8065 | |
| 8066 | dprintk("--> %s try %s\n", __func__, |
| 8067 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 8068 | |
| 8069 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 8070 | |
| 8071 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 8072 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 8073 | if (IS_ERR(task)) |
| 8074 | return PTR_ERR(task); |
| 8075 | |
| 8076 | status = task->tk_status; |
| 8077 | if (status == 0) |
| 8078 | status = nfs4_detect_session_trunking(adata->clp, |
| 8079 | task->tk_msg.rpc_resp, xprt); |
| 8080 | |
| 8081 | rpc_put_task(task); |
| 8082 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 8083 | } |
| 8084 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 8085 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8086 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 8087 | struct rpc_cred *cred) |
| 8088 | { |
| 8089 | struct rpc_message msg = { |
| 8090 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 8091 | .rpc_argp = clp, |
| 8092 | .rpc_cred = cred, |
| 8093 | }; |
| 8094 | int status; |
| 8095 | |
| 8096 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8097 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8098 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 8099 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8100 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 8101 | return status; |
| 8102 | } |
| 8103 | |
| 8104 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 8105 | struct rpc_cred *cred) |
| 8106 | { |
| 8107 | unsigned int loop; |
| 8108 | int ret; |
| 8109 | |
| 8110 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 8111 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 8112 | switch (ret) { |
| 8113 | case -NFS4ERR_DELAY: |
| 8114 | case -NFS4ERR_CLIENTID_BUSY: |
| 8115 | ssleep(1); |
| 8116 | break; |
| 8117 | default: |
| 8118 | return ret; |
| 8119 | } |
| 8120 | } |
| 8121 | return 0; |
| 8122 | } |
| 8123 | |
| 8124 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8125 | { |
| 8126 | struct rpc_cred *cred; |
| 8127 | int ret = 0; |
| 8128 | |
| 8129 | if (clp->cl_mvops->minor_version < 1) |
| 8130 | goto out; |
| 8131 | if (clp->cl_exchange_flags == 0) |
| 8132 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8133 | if (clp->cl_preserve_clid) |
| 8134 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8135 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8136 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 8137 | if (cred) |
| 8138 | put_rpccred(cred); |
| 8139 | switch (ret) { |
| 8140 | case 0: |
| 8141 | case -NFS4ERR_STALE_CLIENTID: |
| 8142 | clp->cl_exchange_flags = 0; |
| 8143 | } |
| 8144 | out: |
| 8145 | return ret; |
| 8146 | } |
| 8147 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8148 | struct nfs4_get_lease_time_data { |
| 8149 | struct nfs4_get_lease_time_args *args; |
| 8150 | struct nfs4_get_lease_time_res *res; |
| 8151 | struct nfs_client *clp; |
| 8152 | }; |
| 8153 | |
| 8154 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8155 | void *calldata) |
| 8156 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8157 | struct nfs4_get_lease_time_data *data = |
| 8158 | (struct nfs4_get_lease_time_data *)calldata; |
| 8159 | |
| 8160 | dprintk("--> %s\n", __func__); |
| 8161 | /* just setup sequence, do not trigger session recovery |
| 8162 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8163 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8164 | &data->args->la_seq_args, |
| 8165 | &data->res->lr_seq_res, |
| 8166 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8167 | dprintk("<-- %s\n", __func__); |
| 8168 | } |
| 8169 | |
| 8170 | /* |
| 8171 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8172 | * from sequence operation or clientid errors. |
| 8173 | */ |
| 8174 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8175 | { |
| 8176 | struct nfs4_get_lease_time_data *data = |
| 8177 | (struct nfs4_get_lease_time_data *)calldata; |
| 8178 | |
| 8179 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8180 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 8181 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8182 | switch (task->tk_status) { |
| 8183 | case -NFS4ERR_DELAY: |
| 8184 | case -NFS4ERR_GRACE: |
| 8185 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8186 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8187 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8188 | /* fall through */ |
| 8189 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8190 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8191 | return; |
| 8192 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8193 | dprintk("<-- %s\n", __func__); |
| 8194 | } |
| 8195 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8196 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8197 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8198 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8199 | }; |
| 8200 | |
| 8201 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8202 | { |
| 8203 | struct rpc_task *task; |
| 8204 | struct nfs4_get_lease_time_args args; |
| 8205 | struct nfs4_get_lease_time_res res = { |
| 8206 | .lr_fsinfo = fsinfo, |
| 8207 | }; |
| 8208 | struct nfs4_get_lease_time_data data = { |
| 8209 | .args = &args, |
| 8210 | .res = &res, |
| 8211 | .clp = clp, |
| 8212 | }; |
| 8213 | struct rpc_message msg = { |
| 8214 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8215 | .rpc_argp = &args, |
| 8216 | .rpc_resp = &res, |
| 8217 | }; |
| 8218 | struct rpc_task_setup task_setup = { |
| 8219 | .rpc_client = clp->cl_rpcclient, |
| 8220 | .rpc_message = &msg, |
| 8221 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8222 | .callback_data = &data, |
| 8223 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8224 | }; |
| 8225 | int status; |
| 8226 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8227 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8228 | task = rpc_run_task(&task_setup); |
| 8229 | |
| 8230 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8231 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8232 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8233 | status = task->tk_status; |
| 8234 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8235 | return status; |
| 8236 | } |
| 8237 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8238 | /* |
| 8239 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8240 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8241 | * use them. |
| 8242 | * |
| 8243 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8244 | * always set csa_cachethis to FALSE because the current implementation |
| 8245 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8246 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8247 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8248 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8249 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8250 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8251 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8252 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8253 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8254 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8255 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8256 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8257 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8258 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8259 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8260 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8261 | |
| 8262 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8263 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8264 | __func__, |
| 8265 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8266 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8267 | |
| 8268 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8269 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8270 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8271 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8272 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 62421cd | 2018-08-11 11:52:39 -0400 | [diff] [blame] | 8273 | args->bc_attrs.max_reqs = max_t(unsigned short, max_session_cb_slots, 1); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8274 | |
| 8275 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8276 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8277 | __func__, |
| 8278 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8279 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8280 | args->bc_attrs.max_reqs); |
| 8281 | } |
| 8282 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8283 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8284 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8285 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8286 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8287 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8288 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8289 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8290 | return -EINVAL; |
| 8291 | /* |
| 8292 | * Our requested max_ops is the minimum we need; we're not |
| 8293 | * prepared to break up compounds into smaller pieces than that. |
| 8294 | * So, no point even trying to continue if the server won't |
| 8295 | * cooperate: |
| 8296 | */ |
| 8297 | if (rcvd->max_ops < sent->max_ops) |
| 8298 | return -EINVAL; |
| 8299 | if (rcvd->max_reqs == 0) |
| 8300 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8301 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8302 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8303 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8304 | } |
| 8305 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8306 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8307 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8308 | { |
| 8309 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8310 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8311 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8312 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8313 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8314 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8315 | return -EINVAL; |
| 8316 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8317 | return -EINVAL; |
| 8318 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8319 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8320 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8321 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8322 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8323 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8324 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8325 | return 0; |
| 8326 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8327 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8328 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8329 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8330 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8331 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8332 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8333 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8334 | if (ret) |
| 8335 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8336 | return nfs4_verify_back_channel_attrs(args, res); |
| 8337 | } |
| 8338 | |
| 8339 | static void nfs4_update_session(struct nfs4_session *session, |
| 8340 | struct nfs41_create_session_res *res) |
| 8341 | { |
| 8342 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8343 | /* Mark client id and session as being confirmed */ |
| 8344 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8345 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8346 | session->flags = res->flags; |
| 8347 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8348 | if (res->flags & SESSION4_BACK_CHAN) |
| 8349 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8350 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8351 | } |
| 8352 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8353 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8354 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8355 | { |
| 8356 | struct nfs4_session *session = clp->cl_session; |
| 8357 | struct nfs41_create_session_args args = { |
| 8358 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8359 | .clientid = clp->cl_clientid, |
| 8360 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8361 | .cb_program = NFS4_CALLBACK, |
| 8362 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8363 | struct nfs41_create_session_res res; |
| 8364 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8365 | struct rpc_message msg = { |
| 8366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8367 | .rpc_argp = &args, |
| 8368 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8369 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8370 | }; |
| 8371 | int status; |
| 8372 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8373 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8374 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8375 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8376 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8377 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8378 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8379 | switch (status) { |
| 8380 | case -NFS4ERR_STALE_CLIENTID: |
| 8381 | case -NFS4ERR_DELAY: |
| 8382 | case -ETIMEDOUT: |
| 8383 | case -EACCES: |
| 8384 | case -EAGAIN: |
| 8385 | goto out; |
| 8386 | }; |
| 8387 | |
| 8388 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8389 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8390 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8391 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8392 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8393 | if (status) |
| 8394 | goto out; |
| 8395 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8396 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8397 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8398 | return status; |
| 8399 | } |
| 8400 | |
| 8401 | /* |
| 8402 | * Issues a CREATE_SESSION operation to the server. |
| 8403 | * It is the responsibility of the caller to verify the session is |
| 8404 | * expired before calling this routine. |
| 8405 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8406 | int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8407 | { |
| 8408 | int status; |
| 8409 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8410 | struct nfs4_session *session = clp->cl_session; |
| 8411 | |
| 8412 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8413 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8414 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8415 | if (status) |
| 8416 | goto out; |
| 8417 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8418 | /* Init or reset the session slot tables */ |
| 8419 | status = nfs4_setup_session_slot_tables(session); |
| 8420 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8421 | if (status) |
| 8422 | goto out; |
| 8423 | |
| 8424 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8425 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8426 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8427 | out: |
| 8428 | dprintk("<-- %s\n", __func__); |
| 8429 | return status; |
| 8430 | } |
| 8431 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8432 | /* |
| 8433 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8434 | * The caller must serialize access to this routine. |
| 8435 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8436 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8437 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8438 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8439 | struct rpc_message msg = { |
| 8440 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8441 | .rpc_argp = session, |
| 8442 | .rpc_cred = cred, |
| 8443 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8444 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8445 | |
| 8446 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8447 | |
| 8448 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8449 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8450 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8451 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8452 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8453 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8454 | |
| 8455 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8456 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8457 | "Session has been destroyed regardless...\n", status); |
| 8458 | |
| 8459 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8460 | return status; |
| 8461 | } |
| 8462 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8463 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8464 | * Renew the cl_session lease. |
| 8465 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8466 | struct nfs4_sequence_data { |
| 8467 | struct nfs_client *clp; |
| 8468 | struct nfs4_sequence_args args; |
| 8469 | struct nfs4_sequence_res res; |
| 8470 | }; |
| 8471 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8472 | static void nfs41_sequence_release(void *data) |
| 8473 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8474 | struct nfs4_sequence_data *calldata = data; |
| 8475 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8476 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8477 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8478 | nfs4_schedule_state_renewal(clp); |
| 8479 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8480 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8481 | } |
| 8482 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8483 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8484 | { |
| 8485 | switch(task->tk_status) { |
| 8486 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8487 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8488 | return -EAGAIN; |
| 8489 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8490 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8491 | } |
| 8492 | return 0; |
| 8493 | } |
| 8494 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8495 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8496 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8497 | struct nfs4_sequence_data *calldata = data; |
| 8498 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8499 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8500 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8501 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8502 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8503 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8504 | if (task->tk_status < 0) { |
| 8505 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8506 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8507 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8508 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8509 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8510 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8511 | return; |
| 8512 | } |
| 8513 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8514 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8515 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8516 | dprintk("<-- %s\n", __func__); |
| 8517 | } |
| 8518 | |
| 8519 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8520 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8521 | struct nfs4_sequence_data *calldata = data; |
| 8522 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8523 | struct nfs4_sequence_args *args; |
| 8524 | struct nfs4_sequence_res *res; |
| 8525 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8526 | args = task->tk_msg.rpc_argp; |
| 8527 | res = task->tk_msg.rpc_resp; |
| 8528 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8529 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8530 | } |
| 8531 | |
| 8532 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8533 | .rpc_call_done = nfs41_sequence_call_done, |
| 8534 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8535 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8536 | }; |
| 8537 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8538 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8539 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8540 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8541 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8542 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8543 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8544 | struct rpc_message msg = { |
| 8545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8546 | .rpc_cred = cred, |
| 8547 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8548 | struct rpc_task_setup task_setup_data = { |
| 8549 | .rpc_client = clp->cl_rpcclient, |
| 8550 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8551 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8552 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8553 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8554 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8555 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8556 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8557 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8558 | goto out_err; |
| 8559 | |
| 8560 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8561 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8562 | if (calldata == NULL) |
| 8563 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8564 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8565 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8566 | msg.rpc_argp = &calldata->args; |
| 8567 | msg.rpc_resp = &calldata->res; |
| 8568 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8569 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8570 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8571 | ret = rpc_run_task(&task_setup_data); |
| 8572 | if (IS_ERR(ret)) |
| 8573 | goto out_err; |
| 8574 | return ret; |
| 8575 | out_put_clp: |
| 8576 | nfs_put_client(clp); |
| 8577 | out_err: |
| 8578 | nfs41_release_slot(slot); |
| 8579 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8580 | } |
| 8581 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8582 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8583 | { |
| 8584 | struct rpc_task *task; |
| 8585 | int ret = 0; |
| 8586 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8587 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8588 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8589 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8590 | if (IS_ERR(task)) |
| 8591 | ret = PTR_ERR(task); |
| 8592 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8593 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8594 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8595 | return ret; |
| 8596 | } |
| 8597 | |
| 8598 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8599 | { |
| 8600 | struct rpc_task *task; |
| 8601 | int ret; |
| 8602 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8603 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8604 | if (IS_ERR(task)) { |
| 8605 | ret = PTR_ERR(task); |
| 8606 | goto out; |
| 8607 | } |
| 8608 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8609 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8610 | ret = task->tk_status; |
| 8611 | rpc_put_task(task); |
| 8612 | out: |
| 8613 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8614 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8615 | } |
| 8616 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8617 | struct nfs4_reclaim_complete_data { |
| 8618 | struct nfs_client *clp; |
| 8619 | struct nfs41_reclaim_complete_args arg; |
| 8620 | struct nfs41_reclaim_complete_res res; |
| 8621 | }; |
| 8622 | |
| 8623 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8624 | { |
| 8625 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8626 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8627 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8628 | &calldata->arg.seq_args, |
| 8629 | &calldata->res.seq_res, |
| 8630 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8631 | } |
| 8632 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8633 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8634 | { |
| 8635 | switch(task->tk_status) { |
| 8636 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8637 | wake_up_all(&clp->cl_lock_waitq); |
| 8638 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8639 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8640 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8641 | break; |
| 8642 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8643 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8644 | /* fall through */ |
| 8645 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8646 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8647 | case -NFS4ERR_BADSESSION: |
| 8648 | case -NFS4ERR_DEADSESSION: |
| 8649 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8650 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8651 | task->tk_status); |
| 8652 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8653 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8654 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8655 | } |
| 8656 | return 0; |
| 8657 | } |
| 8658 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8659 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8660 | { |
| 8661 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8662 | struct nfs_client *clp = calldata->clp; |
| 8663 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8664 | |
| 8665 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8666 | if (!nfs41_sequence_done(task, res)) |
| 8667 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8668 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8669 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8670 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8671 | rpc_restart_call_prepare(task); |
| 8672 | return; |
| 8673 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8674 | dprintk("<-- %s\n", __func__); |
| 8675 | } |
| 8676 | |
| 8677 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8678 | { |
| 8679 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8680 | |
| 8681 | kfree(calldata); |
| 8682 | } |
| 8683 | |
| 8684 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8685 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8686 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8687 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8688 | }; |
| 8689 | |
| 8690 | /* |
| 8691 | * Issue a global reclaim complete. |
| 8692 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8693 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8694 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8695 | { |
| 8696 | struct nfs4_reclaim_complete_data *calldata; |
| 8697 | struct rpc_task *task; |
| 8698 | struct rpc_message msg = { |
| 8699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8700 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8701 | }; |
| 8702 | struct rpc_task_setup task_setup_data = { |
| 8703 | .rpc_client = clp->cl_rpcclient, |
| 8704 | .rpc_message = &msg, |
| 8705 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8706 | .flags = RPC_TASK_ASYNC, |
| 8707 | }; |
| 8708 | int status = -ENOMEM; |
| 8709 | |
| 8710 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8711 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8712 | if (calldata == NULL) |
| 8713 | goto out; |
| 8714 | calldata->clp = clp; |
| 8715 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8716 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8717 | 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] | 8718 | msg.rpc_argp = &calldata->arg; |
| 8719 | msg.rpc_resp = &calldata->res; |
| 8720 | task_setup_data.callback_data = calldata; |
| 8721 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8722 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8723 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8724 | goto out; |
| 8725 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8726 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8727 | if (status == 0) |
| 8728 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8729 | rpc_put_task(task); |
| 8730 | out: |
| 8731 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8732 | return status; |
| 8733 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8734 | |
| 8735 | static void |
| 8736 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8737 | { |
| 8738 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8739 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8740 | |
| 8741 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8742 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8743 | &lgp->res.seq_res, task); |
| 8744 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8745 | } |
| 8746 | |
| 8747 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8748 | { |
| 8749 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8750 | |
| 8751 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8752 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8753 | dprintk("<-- %s\n", __func__); |
| 8754 | } |
| 8755 | |
| 8756 | static int |
| 8757 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8758 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8759 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8760 | struct inode *inode = lgp->args.inode; |
| 8761 | struct nfs_server *server = NFS_SERVER(inode); |
| 8762 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8763 | int nfs4err = task->tk_status; |
| 8764 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8765 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8766 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8767 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8768 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8769 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 8770 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8771 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8772 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8773 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8774 | |
| 8775 | /* |
| 8776 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8777 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8778 | * retry go inband. |
| 8779 | */ |
| 8780 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8781 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8782 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8783 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8784 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8785 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8786 | */ |
| 8787 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8788 | status = -EOVERFLOW; |
| 8789 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8790 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8791 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8792 | * (or clients) writing to the same RAID stripe except when |
| 8793 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8794 | * |
| 8795 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8796 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8797 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8798 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8799 | if (lgp->args.minlength == 0) { |
| 8800 | status = -EOVERFLOW; |
| 8801 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8802 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8803 | status = -EBUSY; |
| 8804 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8805 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8806 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8807 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8808 | case -NFS4ERR_DELEG_REVOKED: |
| 8809 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8810 | case -NFS4ERR_EXPIRED: |
| 8811 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8812 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8813 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8814 | lo = NFS_I(inode)->layout; |
| 8815 | /* If the open stateid was bad, then recover it. */ |
| 8816 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8817 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8818 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8819 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8820 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8821 | break; |
| 8822 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8823 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8824 | /* |
| 8825 | * Mark the bad layout state as invalid, then retry |
| 8826 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8827 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8828 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8829 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8830 | pnfs_free_lseg_list(&head); |
| 8831 | status = -EAGAIN; |
| 8832 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8833 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8834 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8835 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8836 | if (!status) { |
| 8837 | if (exception->retry) |
| 8838 | status = -EAGAIN; |
| 8839 | else |
| 8840 | status = err; |
| 8841 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8842 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8843 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8844 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8845 | } |
| 8846 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8847 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8848 | { |
| 8849 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8850 | return nfs_page_array_len(0, max_resp_sz); |
| 8851 | } |
| 8852 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8853 | static void nfs4_layoutget_release(void *calldata) |
| 8854 | { |
| 8855 | struct nfs4_layoutget *lgp = calldata; |
| 8856 | |
| 8857 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8858 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 8859 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8860 | dprintk("<-- %s\n", __func__); |
| 8861 | } |
| 8862 | |
| 8863 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8864 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8865 | .rpc_call_done = nfs4_layoutget_done, |
| 8866 | .rpc_release = nfs4_layoutget_release, |
| 8867 | }; |
| 8868 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8869 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8870 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8871 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8872 | struct inode *inode = lgp->args.inode; |
| 8873 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8874 | struct rpc_task *task; |
| 8875 | struct rpc_message msg = { |
| 8876 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8877 | .rpc_argp = &lgp->args, |
| 8878 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8879 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8880 | }; |
| 8881 | struct rpc_task_setup task_setup_data = { |
| 8882 | .rpc_client = server->client, |
| 8883 | .rpc_message = &msg, |
| 8884 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8885 | .callback_data = lgp, |
| 8886 | .flags = RPC_TASK_ASYNC, |
| 8887 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8888 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8889 | struct nfs4_exception exception = { |
| 8890 | .inode = inode, |
| 8891 | .timeout = *timeout, |
| 8892 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8893 | int status = 0; |
| 8894 | |
| 8895 | dprintk("--> %s\n", __func__); |
| 8896 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8897 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8898 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8899 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8900 | 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] | 8901 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8902 | task = rpc_run_task(&task_setup_data); |
| 8903 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8904 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8905 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8906 | if (status != 0) |
| 8907 | goto out; |
| 8908 | |
| 8909 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8910 | if (task->tk_status < 0 || lgp->res.layoutp->len == 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8911 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8912 | *timeout = exception.timeout; |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame] | 8913 | } else |
| 8914 | lseg = pnfs_layout_process(lgp); |
| 8915 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8916 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8917 | &lgp->args.range, |
| 8918 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8919 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8920 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8921 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8922 | rpc_put_task(task); |
| 8923 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8924 | if (status) |
| 8925 | return ERR_PTR(status); |
| 8926 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8927 | } |
| 8928 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8929 | static void |
| 8930 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8931 | { |
| 8932 | struct nfs4_layoutreturn *lrp = calldata; |
| 8933 | |
| 8934 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8935 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8936 | &lrp->args.seq_args, |
| 8937 | &lrp->res.seq_res, |
| 8938 | task); |
Trond Myklebust | c8bf707 | 2018-06-15 16:31:02 -0400 | [diff] [blame] | 8939 | if (!pnfs_layout_is_valid(lrp->args.layout)) |
| 8940 | rpc_exit(task, 0); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8944 | { |
| 8945 | struct nfs4_layoutreturn *lrp = calldata; |
| 8946 | struct nfs_server *server; |
| 8947 | |
| 8948 | dprintk("--> %s\n", __func__); |
| 8949 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8950 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8951 | return; |
| 8952 | |
| 8953 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8954 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8955 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | c16467d | 2018-07-29 22:39:15 -0400 | [diff] [blame] | 8956 | if (nfs4_layoutreturn_refresh_stateid(&lrp->args.stateid, |
Trond Myklebust | ecf8402 | 2018-08-15 21:35:46 -0400 | [diff] [blame^] | 8957 | &lrp->args.range, |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8958 | lrp->args.inode)) |
| 8959 | goto out_restart; |
| 8960 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8961 | default: |
| 8962 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8963 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8964 | case 0: |
| 8965 | break; |
| 8966 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8967 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8968 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8969 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8970 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8971 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8972 | return; |
| 8973 | out_restart: |
| 8974 | task->tk_status = 0; |
| 8975 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8976 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8977 | } |
| 8978 | |
| 8979 | static void nfs4_layoutreturn_release(void *calldata) |
| 8980 | { |
| 8981 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8982 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8983 | |
| 8984 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8985 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8986 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8987 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8988 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8989 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8990 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8991 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8992 | kfree(calldata); |
| 8993 | dprintk("<-- %s\n", __func__); |
| 8994 | } |
| 8995 | |
| 8996 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8997 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8998 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8999 | .rpc_release = nfs4_layoutreturn_release, |
| 9000 | }; |
| 9001 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9002 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9003 | { |
| 9004 | struct rpc_task *task; |
| 9005 | struct rpc_message msg = { |
| 9006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 9007 | .rpc_argp = &lrp->args, |
| 9008 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 9009 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9010 | }; |
| 9011 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 9012 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9013 | .rpc_message = &msg, |
| 9014 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 9015 | .callback_data = lrp, |
| 9016 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 9017 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9018 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 9019 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 9020 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 9021 | &task_setup_data.rpc_client, &msg); |
| 9022 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9023 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9024 | if (!sync) { |
| 9025 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 9026 | if (!lrp->inode) { |
| 9027 | nfs4_layoutreturn_release(lrp); |
| 9028 | return -EAGAIN; |
| 9029 | } |
| 9030 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 9031 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9032 | 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] | 9033 | task = rpc_run_task(&task_setup_data); |
| 9034 | if (IS_ERR(task)) |
| 9035 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 9036 | if (sync) |
| 9037 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9038 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 9039 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9040 | rpc_put_task(task); |
| 9041 | return status; |
| 9042 | } |
| 9043 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9044 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9045 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9046 | struct pnfs_device *pdev, |
| 9047 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9048 | { |
| 9049 | struct nfs4_getdeviceinfo_args args = { |
| 9050 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9051 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 9052 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9053 | }; |
| 9054 | struct nfs4_getdeviceinfo_res res = { |
| 9055 | .pdev = pdev, |
| 9056 | }; |
| 9057 | struct rpc_message msg = { |
| 9058 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 9059 | .rpc_argp = &args, |
| 9060 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9061 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9062 | }; |
| 9063 | int status; |
| 9064 | |
| 9065 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 9066 | 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] | 9067 | if (res.notification & ~args.notify_types) |
| 9068 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 9069 | if (res.notification != args.notify_types) |
| 9070 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 9071 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9072 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9073 | |
| 9074 | return status; |
| 9075 | } |
| 9076 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9077 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 9078 | struct pnfs_device *pdev, |
| 9079 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9080 | { |
| 9081 | struct nfs4_exception exception = { }; |
| 9082 | int err; |
| 9083 | |
| 9084 | do { |
| 9085 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 9086 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 9087 | &exception); |
| 9088 | } while (exception.retry); |
| 9089 | return err; |
| 9090 | } |
| 9091 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 9092 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9093 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 9094 | { |
| 9095 | struct nfs4_layoutcommit_data *data = calldata; |
| 9096 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9097 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9098 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 9099 | &data->args.seq_args, |
| 9100 | &data->res.seq_res, |
| 9101 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9102 | } |
| 9103 | |
| 9104 | static void |
| 9105 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 9106 | { |
| 9107 | struct nfs4_layoutcommit_data *data = calldata; |
| 9108 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 9109 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 9110 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9111 | return; |
| 9112 | |
| 9113 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9114 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 9115 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 9116 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 9117 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9118 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9119 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9120 | break; |
| 9121 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9122 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9123 | rpc_restart_call_prepare(task); |
| 9124 | return; |
| 9125 | } |
| 9126 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9127 | } |
| 9128 | |
| 9129 | static void nfs4_layoutcommit_release(void *calldata) |
| 9130 | { |
| 9131 | struct nfs4_layoutcommit_data *data = calldata; |
| 9132 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9133 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9134 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9135 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9136 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9137 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9138 | kfree(data); |
| 9139 | } |
| 9140 | |
| 9141 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9142 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9143 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9144 | .rpc_release = nfs4_layoutcommit_release, |
| 9145 | }; |
| 9146 | |
| 9147 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9148 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9149 | { |
| 9150 | struct rpc_message msg = { |
| 9151 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9152 | .rpc_argp = &data->args, |
| 9153 | .rpc_resp = &data->res, |
| 9154 | .rpc_cred = data->cred, |
| 9155 | }; |
| 9156 | struct rpc_task_setup task_setup_data = { |
| 9157 | .task = &data->task, |
| 9158 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9159 | .rpc_message = &msg, |
| 9160 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9161 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9162 | }; |
| 9163 | struct rpc_task *task; |
| 9164 | int status = 0; |
| 9165 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9166 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9167 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9168 | data->args.lastbytewritten, |
| 9169 | data->args.inode->i_ino); |
| 9170 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9171 | if (!sync) { |
| 9172 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9173 | if (data->inode == NULL) { |
| 9174 | nfs4_layoutcommit_release(data); |
| 9175 | return -EAGAIN; |
| 9176 | } |
| 9177 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9178 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9179 | 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] | 9180 | task = rpc_run_task(&task_setup_data); |
| 9181 | if (IS_ERR(task)) |
| 9182 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9183 | if (sync) |
| 9184 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9185 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9186 | dprintk("%s: status %d\n", __func__, status); |
| 9187 | rpc_put_task(task); |
| 9188 | return status; |
| 9189 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9190 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9191 | /** |
| 9192 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9193 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9194 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9195 | static int |
| 9196 | _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] | 9197 | struct nfs_fsinfo *info, |
| 9198 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9199 | { |
| 9200 | struct nfs41_secinfo_no_name_args args = { |
| 9201 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9202 | }; |
| 9203 | struct nfs4_secinfo_res res = { |
| 9204 | .flavors = flavors, |
| 9205 | }; |
| 9206 | struct rpc_message msg = { |
| 9207 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9208 | .rpc_argp = &args, |
| 9209 | .rpc_resp = &res, |
| 9210 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9211 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9212 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9213 | int status; |
| 9214 | |
| 9215 | if (use_integrity) { |
| 9216 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9217 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9218 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9219 | } |
| 9220 | |
| 9221 | dprintk("--> %s\n", __func__); |
| 9222 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9223 | &res.seq_res, 0); |
| 9224 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9225 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9226 | if (cred) |
| 9227 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9228 | |
| 9229 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9230 | } |
| 9231 | |
| 9232 | static int |
| 9233 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9234 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9235 | { |
| 9236 | struct nfs4_exception exception = { }; |
| 9237 | int err; |
| 9238 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9239 | /* first try using integrity protection */ |
| 9240 | err = -NFS4ERR_WRONGSEC; |
| 9241 | |
| 9242 | /* try to use integrity protection with machine cred */ |
| 9243 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9244 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9245 | flavors, true); |
| 9246 | |
| 9247 | /* |
| 9248 | * if unable to use integrity protection, or SECINFO with |
| 9249 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9250 | * disallowed by spec, but exists in deployed servers) use |
| 9251 | * the current filesystem's rpc_client and the user cred. |
| 9252 | */ |
| 9253 | if (err == -NFS4ERR_WRONGSEC) |
| 9254 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9255 | flavors, false); |
| 9256 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9257 | switch (err) { |
| 9258 | case 0: |
| 9259 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9260 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9261 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9262 | default: |
| 9263 | err = nfs4_handle_exception(server, err, &exception); |
| 9264 | } |
| 9265 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9266 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9267 | return err; |
| 9268 | } |
| 9269 | |
| 9270 | static int |
| 9271 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9272 | struct nfs_fsinfo *info) |
| 9273 | { |
| 9274 | int err; |
| 9275 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9276 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9277 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9278 | struct nfs4_secinfo4 *secinfo; |
| 9279 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9280 | |
| 9281 | page = alloc_page(GFP_KERNEL); |
| 9282 | if (!page) { |
| 9283 | err = -ENOMEM; |
| 9284 | goto out; |
| 9285 | } |
| 9286 | |
| 9287 | flavors = page_address(page); |
| 9288 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9289 | |
| 9290 | /* |
| 9291 | * Fall back on "guess and check" method if |
| 9292 | * the server doesn't support SECINFO_NO_NAME |
| 9293 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9294 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9295 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9296 | goto out_freepage; |
| 9297 | } |
| 9298 | if (err) |
| 9299 | goto out_freepage; |
| 9300 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9301 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9302 | secinfo = &flavors->flavors[i]; |
| 9303 | |
| 9304 | switch (secinfo->flavor) { |
| 9305 | case RPC_AUTH_NULL: |
| 9306 | case RPC_AUTH_UNIX: |
| 9307 | case RPC_AUTH_GSS: |
| 9308 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9309 | &secinfo->flavor_info); |
| 9310 | break; |
| 9311 | default: |
| 9312 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9313 | break; |
| 9314 | } |
| 9315 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9316 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9317 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9318 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9319 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9320 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9321 | info, flavor); |
| 9322 | if (!err) |
| 9323 | break; |
| 9324 | } |
| 9325 | } |
| 9326 | |
| 9327 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9328 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9329 | |
| 9330 | out_freepage: |
| 9331 | put_page(page); |
| 9332 | if (err == -EACCES) |
| 9333 | return -EPERM; |
| 9334 | out: |
| 9335 | return err; |
| 9336 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9337 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9338 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9339 | nfs4_stateid *stateid, |
| 9340 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9341 | { |
| 9342 | int status; |
| 9343 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9344 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9345 | }; |
| 9346 | struct nfs41_test_stateid_res res; |
| 9347 | struct rpc_message msg = { |
| 9348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9349 | .rpc_argp = &args, |
| 9350 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9351 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9352 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9353 | struct rpc_clnt *rpc_client = server->client; |
| 9354 | |
| 9355 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9356 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9357 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9358 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9359 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9360 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9361 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9362 | if (status != NFS_OK) { |
| 9363 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9364 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9365 | } |
| 9366 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9367 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9368 | } |
| 9369 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9370 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9371 | int err, struct nfs4_exception *exception) |
| 9372 | { |
| 9373 | exception->retry = 0; |
| 9374 | switch(err) { |
| 9375 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9376 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9377 | nfs4_handle_exception(server, err, exception); |
| 9378 | break; |
| 9379 | case -NFS4ERR_BADSESSION: |
| 9380 | case -NFS4ERR_BADSLOT: |
| 9381 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9382 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9383 | case -NFS4ERR_DEADSESSION: |
| 9384 | nfs4_do_handle_exception(server, err, exception); |
| 9385 | } |
| 9386 | } |
| 9387 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9388 | /** |
| 9389 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9390 | * |
| 9391 | * @server: server / transport on which to perform the operation |
| 9392 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9393 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9394 | * |
| 9395 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9396 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9397 | * failed or the state ID is not currently valid. |
| 9398 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9399 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9400 | nfs4_stateid *stateid, |
| 9401 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9402 | { |
| 9403 | struct nfs4_exception exception = { }; |
| 9404 | int err; |
| 9405 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9406 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9407 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9408 | } while (exception.retry); |
| 9409 | return err; |
| 9410 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9411 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9412 | struct nfs_free_stateid_data { |
| 9413 | struct nfs_server *server; |
| 9414 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9415 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9416 | }; |
| 9417 | |
| 9418 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9419 | { |
| 9420 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9421 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9422 | &data->args.seq_args, |
| 9423 | &data->res.seq_res, |
| 9424 | task); |
| 9425 | } |
| 9426 | |
| 9427 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9428 | { |
| 9429 | struct nfs_free_stateid_data *data = calldata; |
| 9430 | |
| 9431 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9432 | |
| 9433 | switch (task->tk_status) { |
| 9434 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9435 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9436 | rpc_restart_call_prepare(task); |
| 9437 | } |
| 9438 | } |
| 9439 | |
| 9440 | static void nfs41_free_stateid_release(void *calldata) |
| 9441 | { |
| 9442 | kfree(calldata); |
| 9443 | } |
| 9444 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9445 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9446 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9447 | .rpc_call_done = nfs41_free_stateid_done, |
| 9448 | .rpc_release = nfs41_free_stateid_release, |
| 9449 | }; |
| 9450 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9451 | /** |
| 9452 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9453 | * |
| 9454 | * @server: server / transport on which to perform the operation |
| 9455 | * @stateid: state ID to release |
| 9456 | * @cred: credential |
| 9457 | * @is_recovery: set to true if this call needs to be privileged |
| 9458 | * |
| 9459 | * Note: this function is always asynchronous. |
| 9460 | */ |
| 9461 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9462 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9463 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9464 | bool privileged) |
| 9465 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9466 | struct rpc_message msg = { |
| 9467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9468 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9469 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9470 | struct rpc_task_setup task_setup = { |
| 9471 | .rpc_client = server->client, |
| 9472 | .rpc_message = &msg, |
| 9473 | .callback_ops = &nfs41_free_stateid_ops, |
| 9474 | .flags = RPC_TASK_ASYNC, |
| 9475 | }; |
| 9476 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9477 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9478 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9479 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9480 | &task_setup.rpc_client, &msg); |
| 9481 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9482 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9483 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9484 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9485 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9486 | data->server = server; |
| 9487 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9488 | |
| 9489 | task_setup.callback_data = data; |
| 9490 | |
| 9491 | msg.rpc_argp = &data->args; |
| 9492 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9493 | 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] | 9494 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9495 | if (IS_ERR(task)) |
| 9496 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9497 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9498 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9499 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9500 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9501 | static void |
| 9502 | 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] | 9503 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9504 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9505 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9506 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9507 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9508 | } |
| 9509 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9510 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9511 | const nfs4_stateid *s2) |
| 9512 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9513 | if (s1->type != s2->type) |
| 9514 | return false; |
| 9515 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9516 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9517 | return false; |
| 9518 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9519 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9520 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9521 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9522 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9523 | } |
| 9524 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9525 | #endif /* CONFIG_NFS_V4_1 */ |
| 9526 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9527 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9528 | const nfs4_stateid *s2) |
| 9529 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9530 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9531 | } |
| 9532 | |
| 9533 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9534 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9535 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9536 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9537 | .recover_open = nfs4_open_reclaim, |
| 9538 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9539 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9540 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9541 | }; |
| 9542 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9543 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9544 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9545 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9546 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9547 | .recover_open = nfs4_open_reclaim, |
| 9548 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9549 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9550 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9551 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9552 | }; |
| 9553 | #endif /* CONFIG_NFS_V4_1 */ |
| 9554 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9555 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9556 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9557 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9558 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9559 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9560 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9561 | }; |
| 9562 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9563 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9564 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9565 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9566 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9567 | .recover_open = nfs41_open_expired, |
| 9568 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9569 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9570 | }; |
| 9571 | #endif /* CONFIG_NFS_V4_1 */ |
| 9572 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9573 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9574 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9575 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9576 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9577 | }; |
| 9578 | |
| 9579 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9580 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9581 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9582 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9583 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9584 | }; |
| 9585 | #endif |
| 9586 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9587 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9588 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9589 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9590 | }; |
| 9591 | |
| 9592 | #if defined(CONFIG_NFS_V4_1) |
| 9593 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9594 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9595 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9596 | }; |
| 9597 | #endif /* CONFIG_NFS_V4_1 */ |
| 9598 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9599 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9600 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9601 | .init_caps = NFS_CAP_READDIRPLUS |
| 9602 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9603 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9604 | .init_client = nfs40_init_client, |
| 9605 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9606 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9607 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9608 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9609 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9610 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9611 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9612 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9613 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9614 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9615 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9616 | }; |
| 9617 | |
| 9618 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9619 | static struct nfs_seqid * |
| 9620 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9621 | { |
| 9622 | return NULL; |
| 9623 | } |
| 9624 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9625 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9626 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9627 | .init_caps = NFS_CAP_READDIRPLUS |
| 9628 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9629 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9630 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9631 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9632 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9633 | .init_client = nfs41_init_client, |
| 9634 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9635 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9636 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9637 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9638 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9639 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9640 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9641 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9642 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9643 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9644 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9645 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9646 | }; |
| 9647 | #endif |
| 9648 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9649 | #if defined(CONFIG_NFS_V4_2) |
| 9650 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9651 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9652 | .init_caps = NFS_CAP_READDIRPLUS |
| 9653 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9654 | | NFS_CAP_POSIX_LOCK |
| 9655 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9656 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9657 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9658 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9659 | | NFS_CAP_COPY |
Olga Kornievskaia | cb95dee | 2018-07-09 15:13:29 -0400 | [diff] [blame] | 9660 | | NFS_CAP_OFFLOAD_CANCEL |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9661 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9662 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9663 | | NFS_CAP_LAYOUTSTATS |
| 9664 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9665 | .init_client = nfs41_init_client, |
| 9666 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9667 | .match_stateid = nfs41_match_stateid, |
| 9668 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9669 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9670 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9671 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9672 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9673 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9674 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9675 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9676 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9677 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9678 | }; |
| 9679 | #endif |
| 9680 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9681 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9682 | [0] = &nfs_v4_0_minor_ops, |
| 9683 | #if defined(CONFIG_NFS_V4_1) |
| 9684 | [1] = &nfs_v4_1_minor_ops, |
| 9685 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9686 | #if defined(CONFIG_NFS_V4_2) |
| 9687 | [2] = &nfs_v4_2_minor_ops, |
| 9688 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9689 | }; |
| 9690 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9691 | 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] | 9692 | { |
| 9693 | ssize_t error, error2; |
| 9694 | |
| 9695 | error = generic_listxattr(dentry, list, size); |
| 9696 | if (error < 0) |
| 9697 | return error; |
| 9698 | if (list) { |
| 9699 | list += error; |
| 9700 | size -= error; |
| 9701 | } |
| 9702 | |
| 9703 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9704 | if (error2 < 0) |
| 9705 | return error2; |
| 9706 | return error + error2; |
| 9707 | } |
| 9708 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9709 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9710 | .create = nfs_create, |
| 9711 | .lookup = nfs_lookup, |
| 9712 | .atomic_open = nfs_atomic_open, |
| 9713 | .link = nfs_link, |
| 9714 | .unlink = nfs_unlink, |
| 9715 | .symlink = nfs_symlink, |
| 9716 | .mkdir = nfs_mkdir, |
| 9717 | .rmdir = nfs_rmdir, |
| 9718 | .mknod = nfs_mknod, |
| 9719 | .rename = nfs_rename, |
| 9720 | .permission = nfs_permission, |
| 9721 | .getattr = nfs_getattr, |
| 9722 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9723 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9724 | }; |
| 9725 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9726 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9727 | .permission = nfs_permission, |
| 9728 | .getattr = nfs_getattr, |
| 9729 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9730 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9731 | }; |
| 9732 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9733 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9734 | .version = 4, /* protocol version */ |
| 9735 | .dentry_ops = &nfs4_dentry_operations, |
| 9736 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9737 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9738 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9739 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9740 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9741 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9742 | .getattr = nfs4_proc_getattr, |
| 9743 | .setattr = nfs4_proc_setattr, |
| 9744 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9745 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9746 | .access = nfs4_proc_access, |
| 9747 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9748 | .create = nfs4_proc_create, |
| 9749 | .remove = nfs4_proc_remove, |
| 9750 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9751 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9752 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9753 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9754 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9755 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9756 | .link = nfs4_proc_link, |
| 9757 | .symlink = nfs4_proc_symlink, |
| 9758 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9759 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9760 | .readdir = nfs4_proc_readdir, |
| 9761 | .mknod = nfs4_proc_mknod, |
| 9762 | .statfs = nfs4_proc_statfs, |
| 9763 | .fsinfo = nfs4_proc_fsinfo, |
| 9764 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9765 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9766 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9767 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9768 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9769 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9770 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9771 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9772 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9773 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9774 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9775 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9776 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9777 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9778 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9779 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9780 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9781 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9782 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9783 | .create_server = nfs4_create_server, |
| 9784 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9785 | }; |
| 9786 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9787 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9788 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9789 | .list = nfs4_xattr_list_nfs4_acl, |
| 9790 | .get = nfs4_xattr_get_nfs4_acl, |
| 9791 | .set = nfs4_xattr_set_nfs4_acl, |
| 9792 | }; |
| 9793 | |
| 9794 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9795 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9796 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9797 | &nfs4_xattr_nfs4_label_handler, |
| 9798 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9799 | NULL |
| 9800 | }; |
| 9801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9802 | /* |
| 9803 | * Local variables: |
| 9804 | * c-basic-offset: 8 |
| 9805 | * End: |
| 9806 | */ |