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 | } |
| 452 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 453 | if (inode) { |
| 454 | int err; |
| 455 | |
| 456 | err = nfs_async_inode_return_delegation(inode, |
| 457 | stateid); |
| 458 | if (err == 0) |
| 459 | goto wait_on_recovery; |
| 460 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 461 | exception->retry = 1; |
| 462 | break; |
| 463 | } |
| 464 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 465 | if (state == NULL) |
| 466 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 467 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 468 | if (ret < 0) |
| 469 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 470 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 471 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 472 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 473 | nfs4_schedule_lease_recovery(clp); |
| 474 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 475 | case -NFS4ERR_MOVED: |
| 476 | ret = nfs4_schedule_migration_recovery(server); |
| 477 | if (ret < 0) |
| 478 | break; |
| 479 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 480 | case -NFS4ERR_LEASE_MOVED: |
| 481 | nfs4_schedule_lease_moved_recovery(clp); |
| 482 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 483 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 484 | case -NFS4ERR_BADSESSION: |
| 485 | case -NFS4ERR_BADSLOT: |
| 486 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 487 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 488 | case -NFS4ERR_DEADSESSION: |
| 489 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 490 | case -NFS4ERR_SEQ_MISORDERED: |
| 491 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 492 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 493 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 494 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 495 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 496 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 497 | if (exception->timeout > HZ) { |
| 498 | /* We have retried a decent amount, time to |
| 499 | * fail |
| 500 | */ |
| 501 | ret = -EBUSY; |
| 502 | break; |
| 503 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 504 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 505 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 506 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 507 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 508 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 509 | exception->delay = 1; |
| 510 | return 0; |
| 511 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 512 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 513 | case -NFS4ERR_OLD_STATEID: |
| 514 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 515 | break; |
| 516 | case -NFS4ERR_BADOWNER: |
| 517 | /* The following works around a Linux server bug! */ |
| 518 | case -NFS4ERR_BADNAME: |
| 519 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 520 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 521 | exception->retry = 1; |
| 522 | printk(KERN_WARNING "NFS: v4 server %s " |
| 523 | "does not accept raw " |
| 524 | "uid/gids. " |
| 525 | "Reenabling the idmapper.\n", |
| 526 | server->nfs_client->cl_hostname); |
| 527 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 528 | } |
| 529 | /* We failed to handle the error */ |
| 530 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 531 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 532 | exception->recovering = 1; |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* This is the error handling routine for processes that are allowed |
| 537 | * to sleep. |
| 538 | */ |
| 539 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 540 | { |
| 541 | struct nfs_client *clp = server->nfs_client; |
| 542 | int ret; |
| 543 | |
| 544 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 545 | if (exception->delay) { |
| 546 | ret = nfs4_delay(server->client, &exception->timeout); |
| 547 | goto out_retry; |
| 548 | } |
| 549 | if (exception->recovering) { |
| 550 | ret = nfs4_wait_clnt_recover(clp); |
| 551 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 552 | return -EIO; |
| 553 | goto out_retry; |
| 554 | } |
| 555 | return ret; |
| 556 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 557 | if (ret == 0) |
| 558 | exception->retry = 1; |
| 559 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 560 | } |
| 561 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 562 | static int |
| 563 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 564 | int errorcode, struct nfs4_exception *exception) |
| 565 | { |
| 566 | struct nfs_client *clp = server->nfs_client; |
| 567 | int ret; |
| 568 | |
| 569 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 570 | if (exception->delay) { |
| 571 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 572 | goto out_retry; |
| 573 | } |
| 574 | if (exception->recovering) { |
| 575 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 576 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 577 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 578 | goto out_retry; |
| 579 | } |
| 580 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 581 | ret = -EIO; |
| 582 | return ret; |
| 583 | out_retry: |
| 584 | if (ret == 0) |
| 585 | exception->retry = 1; |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | static int |
| 590 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 591 | struct nfs4_state *state, long *timeout) |
| 592 | { |
| 593 | struct nfs4_exception exception = { |
| 594 | .state = state, |
| 595 | }; |
| 596 | |
| 597 | if (task->tk_status >= 0) |
| 598 | return 0; |
| 599 | if (timeout) |
| 600 | exception.timeout = *timeout; |
| 601 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 602 | task->tk_status, |
| 603 | &exception); |
| 604 | if (exception.delay && timeout) |
| 605 | *timeout = exception.timeout; |
| 606 | if (exception.retry) |
| 607 | return -EAGAIN; |
| 608 | return 0; |
| 609 | } |
| 610 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 611 | /* |
| 612 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 613 | * or 'false' otherwise. |
| 614 | */ |
| 615 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 616 | { |
| 617 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 618 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 619 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 620 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 621 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | spin_lock(&clp->cl_lock); |
| 624 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 625 | clp->cl_last_renewal = timestamp; |
| 626 | spin_unlock(&clp->cl_lock); |
| 627 | } |
| 628 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 629 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 630 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 631 | struct nfs_client *clp = server->nfs_client; |
| 632 | |
| 633 | if (!nfs4_has_session(clp)) |
| 634 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 637 | struct nfs4_call_sync_data { |
| 638 | const struct nfs_server *seq_server; |
| 639 | struct nfs4_sequence_args *seq_args; |
| 640 | struct nfs4_sequence_res *seq_res; |
| 641 | }; |
| 642 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 643 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 644 | struct nfs4_sequence_res *res, int cache_reply, |
| 645 | int privileged) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 646 | { |
| 647 | args->sa_slot = NULL; |
| 648 | args->sa_cache_this = cache_reply; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 649 | args->sa_privileged = privileged; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 650 | |
| 651 | res->sr_slot = NULL; |
| 652 | } |
| 653 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 654 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 655 | { |
| 656 | struct nfs4_slot *slot = res->sr_slot; |
| 657 | struct nfs4_slot_table *tbl; |
| 658 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 659 | tbl = slot->table; |
| 660 | spin_lock(&tbl->slot_tbl_lock); |
| 661 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 662 | nfs4_free_slot(tbl, slot); |
| 663 | spin_unlock(&tbl->slot_tbl_lock); |
| 664 | |
| 665 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int nfs40_sequence_done(struct rpc_task *task, |
| 669 | struct nfs4_sequence_res *res) |
| 670 | { |
| 671 | if (res->sr_slot != NULL) |
| 672 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 673 | return 1; |
| 674 | } |
| 675 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 676 | #if defined(CONFIG_NFS_V4_1) |
| 677 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 678 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 679 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 680 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 681 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 682 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 683 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 684 | if (!slot) |
| 685 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 686 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 687 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 688 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 689 | /* Bump the slot sequence number */ |
| 690 | if (slot->seq_done) |
| 691 | slot->seq_nr++; |
| 692 | slot->seq_done = 0; |
| 693 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 694 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 695 | /* Be nice to the server: try to ensure that the last transmitted |
| 696 | * value for highest_user_slotid <= target_highest_slotid |
| 697 | */ |
| 698 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 699 | send_new_highest_used_slotid = true; |
| 700 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 701 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 702 | send_new_highest_used_slotid = false; |
| 703 | goto out_unlock; |
| 704 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 706 | |
| 707 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 708 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 709 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 710 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 711 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 712 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 713 | if (waitqueue_active(&tbl->slot_waitq)) |
| 714 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 717 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 718 | { |
| 719 | nfs41_release_slot(res->sr_slot); |
| 720 | res->sr_slot = NULL; |
| 721 | } |
| 722 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 723 | static int nfs41_sequence_process(struct rpc_task *task, |
| 724 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 725 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 726 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 727 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 728 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 729 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 730 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 731 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 732 | if (slot == NULL) |
| 733 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 734 | /* don't increment the sequence number if the task wasn't sent */ |
| 735 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 736 | goto out; |
| 737 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 738 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 739 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 740 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 741 | if (res->sr_status != -NFS4ERR_DELAY) |
| 742 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 743 | interrupted = true; |
| 744 | } |
| 745 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 746 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 747 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 748 | switch (res->sr_status) { |
| 749 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 750 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 751 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 752 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 753 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 754 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 755 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 756 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 757 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 758 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 759 | case 1: |
| 760 | /* |
| 761 | * sr_status remains 1 if an RPC level error occurred. |
| 762 | * The server may or may not have processed the sequence |
| 763 | * operation.. |
| 764 | * Mark the slot as having hosted an interrupted RPC call. |
| 765 | */ |
| 766 | slot->interrupted = 1; |
| 767 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 768 | case -NFS4ERR_DELAY: |
| 769 | /* The server detected a resend of the RPC call and |
| 770 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 771 | * of RFC5661. |
| 772 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 773 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 774 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 775 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 776 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 778 | case -NFS4ERR_BADSLOT: |
| 779 | /* |
| 780 | * The slot id we used was probably retired. Try again |
| 781 | * using a different slot id. |
| 782 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 783 | if (slot->seq_nr < slot->table->target_highest_slotid) |
| 784 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 785 | goto retry_nowait; |
| 786 | case -NFS4ERR_SEQ_MISORDERED: |
| 787 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 788 | * Was the last operation on this sequence interrupted? |
| 789 | * If so, retry after bumping the sequence number. |
| 790 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 791 | if (interrupted) |
| 792 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 793 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 794 | * Could this slot have been previously retired? |
| 795 | * If so, then the server may be expecting seq_nr = 1! |
| 796 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 797 | if (slot->seq_nr != 1) { |
| 798 | slot->seq_nr = 1; |
| 799 | goto retry_nowait; |
| 800 | } |
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 | case -NFS4ERR_SEQ_FALSE_RETRY: |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 803 | if (interrupted) |
| 804 | goto retry_new_seq; |
| 805 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 806 | default: |
| 807 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 808 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 809 | } |
| 810 | out: |
| 811 | /* The session may be reset by one of the error handlers. */ |
| 812 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 813 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 814 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 815 | session_recover: |
| 816 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 817 | goto retry_nowait; |
| 818 | retry_new_seq: |
| 819 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 820 | retry_nowait: |
| 821 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 822 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 823 | task->tk_status = 0; |
| 824 | ret = 0; |
| 825 | } |
| 826 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 827 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 828 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 829 | goto out; |
| 830 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 831 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 832 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 833 | |
| 834 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 835 | { |
| 836 | if (!nfs41_sequence_process(task, res)) |
| 837 | return 0; |
| 838 | if (res->sr_slot != NULL) |
| 839 | nfs41_sequence_free_slot(res); |
| 840 | return 1; |
| 841 | |
| 842 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 844 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 845 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 846 | { |
| 847 | if (res->sr_slot == NULL) |
| 848 | return 1; |
| 849 | if (res->sr_slot->table->session != NULL) |
| 850 | return nfs41_sequence_process(task, res); |
| 851 | return nfs40_sequence_done(task, res); |
| 852 | } |
| 853 | |
| 854 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 855 | { |
| 856 | if (res->sr_slot != NULL) { |
| 857 | if (res->sr_slot->table->session != NULL) |
| 858 | nfs41_sequence_free_slot(res); |
| 859 | else |
| 860 | nfs40_sequence_free_slot(res); |
| 861 | } |
| 862 | } |
| 863 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 864 | 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] | 865 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 866 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 867 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 868 | if (!res->sr_slot->table->session) |
| 869 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 870 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 871 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 872 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 873 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 874 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 875 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 876 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 878 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 879 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 880 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 881 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 882 | } |
| 883 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 884 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 885 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 886 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 887 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 888 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 889 | } |
| 890 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 891 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 892 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 893 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 894 | }; |
| 895 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 896 | static void |
| 897 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 898 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 899 | { |
| 900 | struct rpc_task *task; |
| 901 | |
| 902 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 903 | if (!IS_ERR(task)) |
| 904 | rpc_put_task_async(task); |
| 905 | } |
| 906 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 907 | #else /* !CONFIG_NFS_V4_1 */ |
| 908 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 909 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 910 | { |
| 911 | return nfs40_sequence_done(task, res); |
| 912 | } |
| 913 | |
| 914 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 915 | { |
| 916 | if (res->sr_slot != NULL) |
| 917 | nfs40_sequence_free_slot(res); |
| 918 | } |
| 919 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 920 | int nfs4_sequence_done(struct rpc_task *task, |
| 921 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 922 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 923 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 924 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 925 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 926 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 927 | static void |
| 928 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 929 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 930 | { |
| 931 | WARN_ON_ONCE(1); |
| 932 | slot->interrupted = 0; |
| 933 | } |
| 934 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 935 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 936 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 937 | static |
| 938 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 939 | struct nfs4_sequence_res *res, |
| 940 | struct nfs4_slot *slot) |
| 941 | { |
| 942 | if (!slot) |
| 943 | return; |
| 944 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 945 | args->sa_slot = slot; |
| 946 | |
| 947 | res->sr_slot = slot; |
| 948 | res->sr_timestamp = jiffies; |
| 949 | res->sr_status_flags = 0; |
| 950 | res->sr_status = 1; |
| 951 | |
| 952 | } |
| 953 | |
| 954 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 955 | struct nfs4_sequence_args *args, |
| 956 | struct nfs4_sequence_res *res, |
| 957 | struct rpc_task *task) |
| 958 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 959 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 960 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 961 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 962 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 963 | /* slot already allocated? */ |
| 964 | if (res->sr_slot != NULL) |
| 965 | goto out_start; |
| 966 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 967 | if (session) { |
| 968 | tbl = &session->fc_slot_table; |
| 969 | task->tk_timeout = 0; |
| 970 | } |
| 971 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 972 | for (;;) { |
| 973 | spin_lock(&tbl->slot_tbl_lock); |
| 974 | /* The state manager will wait until the slot table is empty */ |
| 975 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 976 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 977 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 978 | slot = nfs4_alloc_slot(tbl); |
| 979 | if (IS_ERR(slot)) { |
| 980 | /* Try again in 1/4 second */ |
| 981 | if (slot == ERR_PTR(-ENOMEM)) |
| 982 | task->tk_timeout = HZ >> 2; |
| 983 | goto out_sleep; |
| 984 | } |
| 985 | spin_unlock(&tbl->slot_tbl_lock); |
| 986 | |
| 987 | if (likely(!slot->interrupted)) |
| 988 | break; |
| 989 | nfs4_sequence_process_interrupted(client, |
| 990 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 991 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 992 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 993 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 994 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 995 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 996 | out_start: |
| 997 | rpc_call_start(task); |
| 998 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 999 | |
| 1000 | out_sleep: |
| 1001 | if (args->sa_privileged) |
| 1002 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 1003 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 1004 | else |
| 1005 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1006 | spin_unlock(&tbl->slot_tbl_lock); |
| 1007 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1008 | } |
| 1009 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1010 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1011 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1012 | { |
| 1013 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1014 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1015 | data->seq_args, data->seq_res, task); |
| 1016 | } |
| 1017 | |
| 1018 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1019 | { |
| 1020 | struct nfs4_call_sync_data *data = calldata; |
| 1021 | nfs4_sequence_done(task, data->seq_res); |
| 1022 | } |
| 1023 | |
| 1024 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1025 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1026 | .rpc_call_done = nfs40_call_sync_done, |
| 1027 | }; |
| 1028 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1029 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1030 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1031 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1032 | struct nfs4_sequence_args *args, |
| 1033 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1034 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1035 | int ret; |
| 1036 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1037 | struct nfs_client *clp = server->nfs_client; |
| 1038 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1039 | .seq_server = server, |
| 1040 | .seq_args = args, |
| 1041 | .seq_res = res, |
| 1042 | }; |
| 1043 | struct rpc_task_setup task_setup = { |
| 1044 | .rpc_client = clnt, |
| 1045 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1046 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1047 | .callback_data = &data |
| 1048 | }; |
| 1049 | |
| 1050 | task = rpc_run_task(&task_setup); |
| 1051 | if (IS_ERR(task)) |
| 1052 | ret = PTR_ERR(task); |
| 1053 | else { |
| 1054 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1055 | rpc_put_task(task); |
| 1056 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1057 | return ret; |
| 1058 | } |
| 1059 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1060 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1061 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1062 | struct rpc_message *msg, |
| 1063 | struct nfs4_sequence_args *args, |
| 1064 | struct nfs4_sequence_res *res, |
| 1065 | int cache_reply) |
| 1066 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1067 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1068 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1071 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1072 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
| 1074 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1075 | |
| 1076 | spin_lock(&dir->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1077 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1078 | | NFS_INO_INVALID_MTIME |
| 1079 | | NFS_INO_INVALID_DATA; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1080 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1081 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1082 | nfsi->attrtimeo_timestamp = jiffies; |
| 1083 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1085 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1086 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1087 | NFS_INO_INVALID_ACL; |
| 1088 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1089 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1090 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1091 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1092 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | spin_unlock(&dir->i_lock); |
| 1094 | } |
| 1095 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1096 | struct nfs4_open_createattrs { |
| 1097 | struct nfs4_label *label; |
| 1098 | struct iattr *sattr; |
| 1099 | const __u32 verf[2]; |
| 1100 | }; |
| 1101 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1102 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1103 | int err, struct nfs4_exception *exception) |
| 1104 | { |
| 1105 | if (err != -EINVAL) |
| 1106 | return false; |
| 1107 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1108 | return false; |
| 1109 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1110 | exception->retry = 1; |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1114 | static u32 |
| 1115 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1116 | fmode_t fmode, int openflags) |
| 1117 | { |
| 1118 | u32 res = 0; |
| 1119 | |
| 1120 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1121 | case FMODE_READ: |
| 1122 | res = NFS4_SHARE_ACCESS_READ; |
| 1123 | break; |
| 1124 | case FMODE_WRITE: |
| 1125 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1126 | break; |
| 1127 | case FMODE_READ|FMODE_WRITE: |
| 1128 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1129 | } |
| 1130 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1131 | goto out; |
| 1132 | /* Want no delegation if we're using O_DIRECT */ |
| 1133 | if (openflags & O_DIRECT) |
| 1134 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1135 | out: |
| 1136 | return res; |
| 1137 | } |
| 1138 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1139 | static enum open_claim_type4 |
| 1140 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1141 | enum open_claim_type4 claim) |
| 1142 | { |
| 1143 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1144 | return claim; |
| 1145 | switch (claim) { |
| 1146 | default: |
| 1147 | return claim; |
| 1148 | case NFS4_OPEN_CLAIM_FH: |
| 1149 | return NFS4_OPEN_CLAIM_NULL; |
| 1150 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1151 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1152 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1153 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1154 | } |
| 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
| 1157 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1158 | { |
| 1159 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1160 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | p->o_res.seqid = p->o_arg.seqid; |
| 1162 | p->c_res.seqid = p->c_arg.seqid; |
| 1163 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1164 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1165 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1166 | 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] | 1167 | } |
| 1168 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1169 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1170 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1171 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1172 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1173 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1174 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1175 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1176 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1178 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1179 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1180 | struct nfs4_opendata *p; |
| 1181 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1182 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | if (p == NULL) |
| 1184 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1185 | |
| 1186 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1187 | if (IS_ERR(p->f_label)) |
| 1188 | goto err_free_p; |
| 1189 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1190 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1191 | if (IS_ERR(p->a_label)) |
| 1192 | goto err_free_f; |
| 1193 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1194 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1195 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1196 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1197 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1198 | nfs_sb_active(dentry->d_sb); |
| 1199 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | p->dir = parent; |
| 1201 | p->owner = sp; |
| 1202 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1203 | p->o_arg.open_flags = flags; |
| 1204 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1205 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1206 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1207 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1208 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1209 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1210 | * will return permission denied for all bits until close */ |
| 1211 | if (!(flags & O_EXCL)) { |
| 1212 | /* ask server to check for all possible rights as results |
| 1213 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1214 | switch (p->o_arg.claim) { |
| 1215 | default: |
| 1216 | break; |
| 1217 | case NFS4_OPEN_CLAIM_NULL: |
| 1218 | case NFS4_OPEN_CLAIM_FH: |
| 1219 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1220 | NFS4_ACCESS_MODIFY | |
| 1221 | NFS4_ACCESS_EXTEND | |
| 1222 | NFS4_ACCESS_EXECUTE; |
| 1223 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1224 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1225 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1226 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1227 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1228 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1229 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1230 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1231 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1232 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1233 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1234 | case NFS4_OPEN_CLAIM_NULL: |
| 1235 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1236 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1237 | p->o_arg.fh = NFS_FH(dir); |
| 1238 | break; |
| 1239 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1240 | case NFS4_OPEN_CLAIM_FH: |
| 1241 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1242 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1243 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1244 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1245 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1247 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1248 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1249 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1250 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1251 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1252 | p->c_arg.fh = &p->o_res.fh; |
| 1253 | p->c_arg.stateid = &p->o_res.stateid; |
| 1254 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1255 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1256 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1257 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1258 | |
| 1259 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1260 | nfs4_label_free(p->a_label); |
| 1261 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1262 | nfs4_label_free(p->f_label); |
| 1263 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1264 | kfree(p); |
| 1265 | err: |
| 1266 | dput(parent); |
| 1267 | return NULL; |
| 1268 | } |
| 1269 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1270 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1271 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1272 | struct nfs4_opendata *p = container_of(kref, |
| 1273 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1274 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1275 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1276 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1278 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1279 | if (p->state != NULL) |
| 1280 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1281 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1282 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1283 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1284 | nfs4_label_free(p->f_label); |
| 1285 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1286 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1287 | dput(p->dentry); |
| 1288 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1289 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1290 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1291 | kfree(p); |
| 1292 | } |
| 1293 | |
| 1294 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1295 | { |
| 1296 | if (p != NULL) |
| 1297 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1300 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1301 | fmode_t fmode) |
| 1302 | { |
| 1303 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1304 | case FMODE_READ|FMODE_WRITE: |
| 1305 | return state->n_rdwr != 0; |
| 1306 | case FMODE_WRITE: |
| 1307 | return state->n_wronly != 0; |
| 1308 | case FMODE_READ: |
| 1309 | return state->n_rdonly != 0; |
| 1310 | } |
| 1311 | WARN_ON_ONCE(1); |
| 1312 | return false; |
| 1313 | } |
| 1314 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1315 | 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] | 1316 | { |
| 1317 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1319 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1320 | goto out; |
| 1321 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1322 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1323 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1324 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1325 | break; |
| 1326 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1327 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1328 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1329 | break; |
| 1330 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1331 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1332 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1333 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1334 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1335 | return ret; |
| 1336 | } |
| 1337 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1338 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1339 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1340 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1341 | if (delegation == NULL) |
| 1342 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1343 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1344 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1345 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1346 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1347 | switch (claim) { |
| 1348 | case NFS4_OPEN_CLAIM_NULL: |
| 1349 | case NFS4_OPEN_CLAIM_FH: |
| 1350 | break; |
| 1351 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1352 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1353 | break; |
| 1354 | default: |
| 1355 | return 0; |
| 1356 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1357 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1358 | return 1; |
| 1359 | } |
| 1360 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1361 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1362 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1363 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1364 | case FMODE_WRITE: |
| 1365 | state->n_wronly++; |
| 1366 | break; |
| 1367 | case FMODE_READ: |
| 1368 | state->n_rdonly++; |
| 1369 | break; |
| 1370 | case FMODE_READ|FMODE_WRITE: |
| 1371 | state->n_rdwr++; |
| 1372 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1373 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1376 | #ifdef CONFIG_NFS_V4_1 |
| 1377 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1378 | { |
| 1379 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1380 | return true; |
| 1381 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1382 | return true; |
| 1383 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1384 | return true; |
| 1385 | return false; |
| 1386 | } |
| 1387 | #endif /* CONFIG_NFS_V4_1 */ |
| 1388 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1389 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1390 | { |
| 1391 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1392 | wake_up_all(&state->waitq); |
| 1393 | } |
| 1394 | |
| 1395 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1396 | const nfs4_stateid *stateid) |
| 1397 | { |
| 1398 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1399 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1400 | |
| 1401 | if (stateid_seqid == state_seqid + 1U || |
| 1402 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1403 | nfs_state_log_update_open_stateid(state); |
| 1404 | else |
| 1405 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1406 | } |
| 1407 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1408 | 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] | 1409 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1410 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1411 | bool need_recover = false; |
| 1412 | |
| 1413 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1414 | need_recover = true; |
| 1415 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1416 | need_recover = true; |
| 1417 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1418 | need_recover = true; |
| 1419 | if (need_recover) |
| 1420 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1421 | } |
| 1422 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1423 | /* |
| 1424 | * Check for whether or not the caller may update the open stateid |
| 1425 | * to the value passed in by stateid. |
| 1426 | * |
| 1427 | * Note: This function relies heavily on the server implementing |
| 1428 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1429 | * correctly. |
| 1430 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1431 | * are then incremented on every state transition. |
| 1432 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1433 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1434 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1435 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1436 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1437 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1438 | if (stateid->seqid == cpu_to_be32(1)) |
| 1439 | nfs_state_log_update_open_stateid(state); |
| 1440 | else |
| 1441 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1442 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1443 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1444 | |
| 1445 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1446 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1447 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1448 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1449 | return false; |
| 1450 | } |
| 1451 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1452 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1453 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1454 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1455 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1456 | if (state->n_wronly) |
| 1457 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1458 | if (state->n_rdonly) |
| 1459 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1460 | if (state->n_rdwr) |
| 1461 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1462 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1463 | } |
| 1464 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1465 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1466 | nfs4_stateid *stateid, fmode_t fmode) |
| 1467 | { |
| 1468 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1469 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1470 | case FMODE_WRITE: |
| 1471 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1472 | break; |
| 1473 | case FMODE_READ: |
| 1474 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1475 | break; |
| 1476 | case 0: |
| 1477 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1478 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1479 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1480 | } |
| 1481 | if (stateid == NULL) |
| 1482 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1483 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1484 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1485 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1486 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1487 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1488 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1489 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1490 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1491 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1492 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1493 | out: |
| 1494 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1497 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1498 | nfs4_stateid *arg_stateid, |
| 1499 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1500 | { |
| 1501 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1502 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1503 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1504 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1505 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1506 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1507 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1508 | } |
| 1509 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1510 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1511 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1512 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1513 | DEFINE_WAIT(wait); |
| 1514 | int status = 0; |
| 1515 | for (;;) { |
| 1516 | |
| 1517 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1518 | return; |
| 1519 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1520 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1521 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1522 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1523 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1524 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1525 | break; |
| 1526 | |
| 1527 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1528 | /* |
| 1529 | * Ensure we process the state changes in the same order |
| 1530 | * in which the server processed them by delaying the |
| 1531 | * update of the stateid until we are in sequence. |
| 1532 | */ |
| 1533 | write_sequnlock(&state->seqlock); |
| 1534 | spin_unlock(&state->owner->so_lock); |
| 1535 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1536 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1537 | if (!signal_pending(current)) { |
| 1538 | if (schedule_timeout(5*HZ) == 0) |
| 1539 | status = -EAGAIN; |
| 1540 | else |
| 1541 | status = 0; |
| 1542 | } else |
| 1543 | status = -EINTR; |
| 1544 | finish_wait(&state->waitq, &wait); |
| 1545 | rcu_read_lock(); |
| 1546 | spin_lock(&state->owner->so_lock); |
| 1547 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1548 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1549 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1550 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1551 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1552 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1553 | nfs_test_and_clear_all_open_stateid(state); |
| 1554 | } |
| 1555 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1556 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1557 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1558 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1559 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1560 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1563 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1564 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1565 | fmode_t fmode, |
| 1566 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1568 | /* |
| 1569 | * Protect the call to nfs4_state_set_mode_locked and |
| 1570 | * serialise the stateid update |
| 1571 | */ |
| 1572 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1573 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1574 | switch (fmode) { |
| 1575 | case FMODE_READ: |
| 1576 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1577 | break; |
| 1578 | case FMODE_WRITE: |
| 1579 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1580 | break; |
| 1581 | case FMODE_READ|FMODE_WRITE: |
| 1582 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1583 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1584 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1585 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1589 | const nfs4_stateid *deleg_stateid, |
| 1590 | fmode_t fmode) |
| 1591 | { |
| 1592 | /* |
| 1593 | * Protect the call to nfs4_state_set_mode_locked and |
| 1594 | * serialise the stateid update |
| 1595 | */ |
| 1596 | write_seqlock(&state->seqlock); |
| 1597 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1598 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1599 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1602 | static int update_open_stateid(struct nfs4_state *state, |
| 1603 | const nfs4_stateid *open_stateid, |
| 1604 | const nfs4_stateid *delegation, |
| 1605 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1606 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1607 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1608 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1609 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1610 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1611 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1612 | int ret = 0; |
| 1613 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1614 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1615 | |
| 1616 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1617 | spin_lock(&state->owner->so_lock); |
| 1618 | if (open_stateid != NULL) { |
| 1619 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1620 | ret = 1; |
| 1621 | } |
| 1622 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1623 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1624 | if (deleg_cur == NULL) |
| 1625 | goto no_delegation; |
| 1626 | |
| 1627 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1628 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1629 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1630 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1631 | goto no_delegation_unlock; |
| 1632 | |
| 1633 | if (delegation == NULL) |
| 1634 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1635 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1636 | goto no_delegation_unlock; |
| 1637 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1638 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1639 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1640 | ret = 1; |
| 1641 | no_delegation_unlock: |
| 1642 | spin_unlock(&deleg_cur->lock); |
| 1643 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1644 | if (ret) |
| 1645 | update_open_stateflags(state, fmode); |
| 1646 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1647 | rcu_read_unlock(); |
| 1648 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1649 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1650 | nfs4_schedule_state_manager(clp); |
| 1651 | if (freeme.type != 0) |
| 1652 | nfs4_test_and_free_stateid(server, &freeme, |
| 1653 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1654 | |
| 1655 | return ret; |
| 1656 | } |
| 1657 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1658 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1659 | const nfs4_stateid *stateid) |
| 1660 | { |
| 1661 | struct nfs4_state *state = lsp->ls_state; |
| 1662 | bool ret = false; |
| 1663 | |
| 1664 | spin_lock(&state->state_lock); |
| 1665 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1666 | goto out_noupdate; |
| 1667 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1668 | goto out_noupdate; |
| 1669 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1670 | ret = true; |
| 1671 | out_noupdate: |
| 1672 | spin_unlock(&state->state_lock); |
| 1673 | return ret; |
| 1674 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1675 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1676 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1677 | { |
| 1678 | struct nfs_delegation *delegation; |
| 1679 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1680 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | rcu_read_lock(); |
| 1682 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1683 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1684 | rcu_read_unlock(); |
| 1685 | return; |
| 1686 | } |
| 1687 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1688 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1689 | } |
| 1690 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1691 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1692 | { |
| 1693 | struct nfs4_state *state = opendata->state; |
| 1694 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1695 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1696 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1697 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1698 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1699 | nfs4_stateid stateid; |
| 1700 | int ret = -EAGAIN; |
| 1701 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1702 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1703 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1704 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1705 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1706 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1707 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1708 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1709 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1710 | rcu_read_lock(); |
| 1711 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1712 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1713 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1714 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1715 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1716 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1717 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1718 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1719 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1720 | if (!opendata->is_recover) { |
| 1721 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1722 | if (ret != 0) |
| 1723 | goto out; |
| 1724 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1725 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1726 | |
| 1727 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1728 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1729 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1730 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1731 | out: |
| 1732 | return ERR_PTR(ret); |
| 1733 | out_return_state: |
| 1734 | atomic_inc(&state->count); |
| 1735 | return state; |
| 1736 | } |
| 1737 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1738 | static void |
| 1739 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1740 | { |
| 1741 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1742 | struct nfs_delegation *delegation; |
| 1743 | int delegation_flags = 0; |
| 1744 | |
| 1745 | rcu_read_lock(); |
| 1746 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1747 | if (delegation) |
| 1748 | delegation_flags = delegation->flags; |
| 1749 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1750 | switch (data->o_arg.claim) { |
| 1751 | default: |
| 1752 | break; |
| 1753 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1754 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1755 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1756 | "returning a delegation for " |
| 1757 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1758 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1759 | return; |
| 1760 | } |
| 1761 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1762 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1763 | data->owner->so_cred, |
| 1764 | data->o_res.delegation_type, |
| 1765 | &data->o_res.delegation, |
| 1766 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1767 | else |
| 1768 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1769 | data->owner->so_cred, |
| 1770 | data->o_res.delegation_type, |
| 1771 | &data->o_res.delegation, |
| 1772 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | /* |
| 1776 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1777 | * and update the nfs4_state. |
| 1778 | */ |
| 1779 | static struct nfs4_state * |
| 1780 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1781 | { |
| 1782 | struct inode *inode = data->state->inode; |
| 1783 | struct nfs4_state *state = data->state; |
| 1784 | int ret; |
| 1785 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1786 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1787 | if (data->rpc_status) |
| 1788 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1789 | /* cached opens have already been processed */ |
| 1790 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1791 | } |
| 1792 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1793 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1794 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1795 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1796 | |
| 1797 | if (data->o_res.delegation_type != 0) |
| 1798 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1799 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1800 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1801 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1802 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1803 | |
| 1804 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1805 | } |
| 1806 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1807 | static struct inode * |
| 1808 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1809 | { |
| 1810 | struct inode *inode; |
| 1811 | |
| 1812 | switch (data->o_arg.claim) { |
| 1813 | case NFS4_OPEN_CLAIM_NULL: |
| 1814 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1815 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1816 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1817 | return ERR_PTR(-EAGAIN); |
| 1818 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1819 | &data->f_attr, data->f_label); |
| 1820 | break; |
| 1821 | default: |
| 1822 | inode = d_inode(data->dentry); |
| 1823 | ihold(inode); |
| 1824 | nfs_refresh_inode(inode, &data->f_attr); |
| 1825 | } |
| 1826 | return inode; |
| 1827 | } |
| 1828 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1829 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1830 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1831 | { |
| 1832 | struct nfs4_state *state; |
| 1833 | struct inode *inode; |
| 1834 | |
| 1835 | inode = nfs4_opendata_get_inode(data); |
| 1836 | if (IS_ERR(inode)) |
| 1837 | return ERR_CAST(inode); |
| 1838 | if (data->state != NULL && data->state->inode == inode) { |
| 1839 | state = data->state; |
| 1840 | atomic_inc(&state->count); |
| 1841 | } else |
| 1842 | state = nfs4_get_open_state(inode, data->owner); |
| 1843 | iput(inode); |
| 1844 | if (state == NULL) |
| 1845 | state = ERR_PTR(-ENOMEM); |
| 1846 | return state; |
| 1847 | } |
| 1848 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1849 | static struct nfs4_state * |
| 1850 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1851 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1852 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1853 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1854 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1855 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1856 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1857 | goto out; |
| 1858 | } |
| 1859 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1860 | state = nfs4_opendata_find_nfs4_state(data); |
| 1861 | if (IS_ERR(state)) |
| 1862 | goto out; |
| 1863 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1864 | if (data->o_res.delegation_type != 0) |
| 1865 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1866 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1867 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1868 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1869 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1870 | return state; |
| 1871 | } |
| 1872 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1873 | static struct nfs4_state * |
| 1874 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1875 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1876 | struct nfs4_state *ret; |
| 1877 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1878 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1879 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1880 | else |
| 1881 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1882 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1883 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1884 | } |
| 1885 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1886 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1887 | { |
| 1888 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1889 | struct nfs_open_context *ctx; |
| 1890 | |
| 1891 | spin_lock(&state->inode->i_lock); |
| 1892 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1893 | if (ctx->state != state) |
| 1894 | continue; |
| 1895 | get_nfs_open_context(ctx); |
| 1896 | spin_unlock(&state->inode->i_lock); |
| 1897 | return ctx; |
| 1898 | } |
| 1899 | spin_unlock(&state->inode->i_lock); |
| 1900 | return ERR_PTR(-ENOENT); |
| 1901 | } |
| 1902 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1903 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1904 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1905 | { |
| 1906 | struct nfs4_opendata *opendata; |
| 1907 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1908 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1909 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1910 | if (opendata == NULL) |
| 1911 | return ERR_PTR(-ENOMEM); |
| 1912 | opendata->state = state; |
| 1913 | atomic_inc(&state->count); |
| 1914 | return opendata; |
| 1915 | } |
| 1916 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1917 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1918 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1919 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1920 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1921 | int ret; |
| 1922 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1923 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1924 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1925 | opendata->o_arg.open_flags = 0; |
| 1926 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1927 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1928 | NFS_SB(opendata->dentry->d_sb), |
| 1929 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1930 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1931 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1932 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1933 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1934 | if (ret != 0) |
| 1935 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1936 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1937 | if (IS_ERR(newstate)) |
| 1938 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1939 | if (newstate != opendata->state) |
| 1940 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1941 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1946 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1947 | int ret; |
| 1948 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1949 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1950 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1951 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1952 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1953 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1954 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1955 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1956 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1957 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1958 | if (ret != 0) |
| 1959 | return ret; |
| 1960 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1961 | if (ret != 0) |
| 1962 | return ret; |
| 1963 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1964 | if (ret != 0) |
| 1965 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1966 | /* |
| 1967 | * We may have performed cached opens for all three recoveries. |
| 1968 | * Check if we need to update the current stateid. |
| 1969 | */ |
| 1970 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1971 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1972 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1973 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1974 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1975 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1976 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1977 | return 0; |
| 1978 | } |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | /* |
| 1981 | * OPEN_RECLAIM: |
| 1982 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1984 | 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] | 1985 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1986 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1987 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1988 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | int status; |
| 1990 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1991 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1992 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1993 | if (IS_ERR(opendata)) |
| 1994 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1995 | rcu_read_lock(); |
| 1996 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1997 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1998 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1999 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2000 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2001 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2002 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | return status; |
| 2004 | } |
| 2005 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2006 | 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] | 2007 | { |
| 2008 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2009 | struct nfs4_exception exception = { }; |
| 2010 | int err; |
| 2011 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2012 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2013 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2014 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2015 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2016 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2017 | break; |
| 2018 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | } while (exception.retry); |
| 2020 | return err; |
| 2021 | } |
| 2022 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2023 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2024 | { |
| 2025 | struct nfs_open_context *ctx; |
| 2026 | int ret; |
| 2027 | |
| 2028 | ctx = nfs4_state_find_open_context(state); |
| 2029 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2030 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2031 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2032 | put_nfs_open_context(ctx); |
| 2033 | return ret; |
| 2034 | } |
| 2035 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2036 | 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] | 2037 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2038 | switch (err) { |
| 2039 | default: |
| 2040 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2041 | "%d.\n", __func__, err); |
| 2042 | case 0: |
| 2043 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2044 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2045 | case -ESTALE: |
| 2046 | break; |
| 2047 | case -NFS4ERR_BADSESSION: |
| 2048 | case -NFS4ERR_BADSLOT: |
| 2049 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2050 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2051 | case -NFS4ERR_DEADSESSION: |
| 2052 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2053 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2054 | return -EAGAIN; |
| 2055 | case -NFS4ERR_STALE_CLIENTID: |
| 2056 | case -NFS4ERR_STALE_STATEID: |
| 2057 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2058 | /* Don't recall a delegation if it was lost */ |
| 2059 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2060 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2061 | case -NFS4ERR_MOVED: |
| 2062 | nfs4_schedule_migration_recovery(server); |
| 2063 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2064 | case -NFS4ERR_LEASE_MOVED: |
| 2065 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2066 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2067 | case -NFS4ERR_DELEG_REVOKED: |
| 2068 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2069 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2070 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2071 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2072 | nfs_inode_find_state_and_recover(state->inode, |
| 2073 | stateid); |
| 2074 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2075 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2076 | case -NFS4ERR_DELAY: |
| 2077 | case -NFS4ERR_GRACE: |
| 2078 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2079 | ssleep(1); |
| 2080 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2081 | case -ENOMEM: |
| 2082 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2083 | if (fl) { |
| 2084 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2085 | if (lsp) |
| 2086 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2087 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2088 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2089 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | return err; |
| 2091 | } |
| 2092 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2093 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2094 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2095 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2096 | { |
| 2097 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2098 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2099 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2100 | |
| 2101 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2102 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2103 | if (IS_ERR(opendata)) |
| 2104 | return PTR_ERR(opendata); |
| 2105 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2106 | write_seqlock(&state->seqlock); |
| 2107 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2108 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2109 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2110 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2111 | case FMODE_READ|FMODE_WRITE: |
| 2112 | case FMODE_WRITE: |
| 2113 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2114 | if (err) |
| 2115 | break; |
| 2116 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2117 | if (err) |
| 2118 | break; |
| 2119 | case FMODE_READ: |
| 2120 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2121 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2122 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2123 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2124 | } |
| 2125 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2126 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2127 | { |
| 2128 | struct nfs4_opendata *data = calldata; |
| 2129 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2130 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2131 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2132 | } |
| 2133 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2134 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2135 | { |
| 2136 | struct nfs4_opendata *data = calldata; |
| 2137 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2138 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2139 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2140 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2141 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2142 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2143 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2144 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2145 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2146 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | static void nfs4_open_confirm_release(void *calldata) |
| 2150 | { |
| 2151 | struct nfs4_opendata *data = calldata; |
| 2152 | struct nfs4_state *state = NULL; |
| 2153 | |
| 2154 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2155 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2156 | goto out_free; |
| 2157 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2158 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2159 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2160 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2161 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2162 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2163 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2164 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2168 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2169 | .rpc_call_done = nfs4_open_confirm_done, |
| 2170 | .rpc_release = nfs4_open_confirm_release, |
| 2171 | }; |
| 2172 | |
| 2173 | /* |
| 2174 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2175 | */ |
| 2176 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2177 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2178 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2179 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2180 | struct rpc_message msg = { |
| 2181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2182 | .rpc_argp = &data->c_arg, |
| 2183 | .rpc_resp = &data->c_res, |
| 2184 | .rpc_cred = data->owner->so_cred, |
| 2185 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2186 | struct rpc_task_setup task_setup_data = { |
| 2187 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2188 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | .callback_ops = &nfs4_open_confirm_ops, |
| 2190 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2191 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2192 | .flags = RPC_TASK_ASYNC, |
| 2193 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | int status; |
| 2195 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2196 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2197 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2198 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2199 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2200 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2201 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2202 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2203 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2204 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2205 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2206 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2207 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2208 | smp_wmb(); |
| 2209 | } else |
| 2210 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2211 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | return status; |
| 2213 | } |
| 2214 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2215 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2217 | struct nfs4_opendata *data = calldata; |
| 2218 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2219 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2220 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2221 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2222 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2223 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2224 | /* |
| 2225 | * Check if we still need to send an OPEN call, or if we can use |
| 2226 | * a delegation instead. |
| 2227 | */ |
| 2228 | if (data->state != NULL) { |
| 2229 | struct nfs_delegation *delegation; |
| 2230 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2231 | 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] | 2232 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2233 | rcu_read_lock(); |
| 2234 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2235 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2236 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2237 | rcu_read_unlock(); |
| 2238 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2239 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2240 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2241 | switch (claim) { |
| 2242 | default: |
| 2243 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2244 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2245 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2246 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2247 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2248 | case NFS4_OPEN_CLAIM_FH: |
| 2249 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2250 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2251 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2252 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2253 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2254 | &data->o_res.seq_res, |
| 2255 | task) != 0) |
| 2256 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2257 | |
| 2258 | /* Set the create mode (note dependency on the session type) */ |
| 2259 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2260 | if (data->o_arg.open_flags & O_EXCL) { |
| 2261 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2262 | if (nfs4_has_persistent_session(clp)) |
| 2263 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2264 | else if (clp->cl_mvops->minor_version > 0) |
| 2265 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2266 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2267 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2268 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2269 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2270 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2271 | out_no_action: |
| 2272 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2273 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2274 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2275 | } |
| 2276 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2277 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2278 | { |
| 2279 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2281 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2282 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2283 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2284 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2285 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2286 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2287 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2288 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2289 | case S_IFREG: |
| 2290 | break; |
| 2291 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2292 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2293 | break; |
| 2294 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2295 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2296 | break; |
| 2297 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2298 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2299 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2300 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2301 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2302 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2303 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2304 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2305 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2306 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2307 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2308 | static void nfs4_open_release(void *calldata) |
| 2309 | { |
| 2310 | struct nfs4_opendata *data = calldata; |
| 2311 | struct nfs4_state *state = NULL; |
| 2312 | |
| 2313 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2314 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2315 | goto out_free; |
| 2316 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2317 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | goto out_free; |
| 2319 | /* In case we need an open_confirm, no cleanup! */ |
| 2320 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2321 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2322 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2323 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2324 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2325 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2326 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2330 | .rpc_call_prepare = nfs4_open_prepare, |
| 2331 | .rpc_call_done = nfs4_open_done, |
| 2332 | .rpc_release = nfs4_open_release, |
| 2333 | }; |
| 2334 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2335 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2336 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2337 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2338 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2339 | struct nfs_server *server = NFS_SERVER(dir); |
| 2340 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2341 | struct nfs_openres *o_res = &data->o_res; |
| 2342 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2343 | struct rpc_message msg = { |
| 2344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2345 | .rpc_argp = o_arg, |
| 2346 | .rpc_resp = o_res, |
| 2347 | .rpc_cred = data->owner->so_cred, |
| 2348 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2349 | struct rpc_task_setup task_setup_data = { |
| 2350 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2351 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2352 | .callback_ops = &nfs4_open_ops, |
| 2353 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2354 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2355 | .flags = RPC_TASK_ASYNC, |
| 2356 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2357 | int status; |
| 2358 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2359 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2360 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2361 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2362 | data->cancelled = false; |
| 2363 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2364 | if (!ctx) { |
| 2365 | 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] | 2366 | data->is_recover = true; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2367 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2368 | 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] | 2369 | pnfs_lgopen_prepare(data, ctx); |
| 2370 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2371 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2372 | if (IS_ERR(task)) |
| 2373 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2374 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2375 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2376 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2377 | smp_wmb(); |
| 2378 | } else |
| 2379 | status = data->rpc_status; |
| 2380 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2381 | |
| 2382 | return status; |
| 2383 | } |
| 2384 | |
| 2385 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2386 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2387 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2388 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2389 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2390 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2391 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2392 | if (status != 0 || !data->rpc_done) |
| 2393 | return status; |
| 2394 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2395 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2396 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2397 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2398 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2399 | |
| 2400 | return status; |
| 2401 | } |
| 2402 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2403 | /* |
| 2404 | * Additional permission checks in order to distinguish between an |
| 2405 | * open for read, and an open for execute. This works around the |
| 2406 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2407 | * the same. |
| 2408 | * Note that in the non-execute case, we want to turn off permission |
| 2409 | * checking if we just created a new file (POSIX open() semantics). |
| 2410 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2411 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2412 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2413 | struct nfs4_state *state, fmode_t fmode, |
| 2414 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2415 | { |
| 2416 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2417 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2418 | |
| 2419 | /* access call failed or for some reason the server doesn't |
| 2420 | * support any access modes -- defer access call until later */ |
| 2421 | if (opendata->o_res.access_supported == 0) |
| 2422 | return 0; |
| 2423 | |
| 2424 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2425 | /* |
| 2426 | * Use openflags to check for exec, because fmode won't |
| 2427 | * always have FMODE_EXEC set when file open for exec. |
| 2428 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2429 | if (openflags & __FMODE_EXEC) { |
| 2430 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2431 | if (S_ISDIR(state->inode->i_mode)) |
| 2432 | mask = NFS4_ACCESS_LOOKUP; |
| 2433 | else |
| 2434 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2435 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2436 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2437 | |
| 2438 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2439 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2440 | nfs_access_add_cache(state->inode, &cache); |
| 2441 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2442 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2443 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2444 | return 0; |
| 2445 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2446 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2449 | /* |
| 2450 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2451 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2452 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2453 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2454 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2455 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2456 | struct nfs_server *server = NFS_SERVER(dir); |
| 2457 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2458 | struct nfs_openres *o_res = &data->o_res; |
| 2459 | int status; |
| 2460 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2461 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2462 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2463 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2464 | if (status != 0) { |
| 2465 | if (status == -NFS4ERR_BADNAME && |
| 2466 | !(o_arg->open_flags & O_CREAT)) |
| 2467 | return -ENOENT; |
| 2468 | return status; |
| 2469 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2470 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2471 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2472 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2473 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2474 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2475 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2476 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2477 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2478 | if (data->file_created || |
| 2479 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2480 | update_changeattr(dir, &o_res->cinfo, |
| 2481 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2482 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2483 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2484 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2486 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2488 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2490 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2491 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2492 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2493 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2494 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | /* |
| 2499 | * OPEN_EXPIRED: |
| 2500 | * reclaim state on the server after a network partition. |
| 2501 | * Assumes caller holds the appropriate lock |
| 2502 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2503 | 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] | 2504 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2505 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2506 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2508 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2509 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2510 | if (IS_ERR(opendata)) |
| 2511 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2512 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2513 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2514 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2515 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2516 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2519 | 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] | 2520 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2521 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2522 | struct nfs4_exception exception = { }; |
| 2523 | int err; |
| 2524 | |
| 2525 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2526 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2527 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2528 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2529 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2530 | switch (err) { |
| 2531 | default: |
| 2532 | goto out; |
| 2533 | case -NFS4ERR_GRACE: |
| 2534 | case -NFS4ERR_DELAY: |
| 2535 | nfs4_handle_exception(server, err, &exception); |
| 2536 | err = 0; |
| 2537 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2538 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2539 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2540 | return err; |
| 2541 | } |
| 2542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2544 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2546 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2548 | ctx = nfs4_state_find_open_context(state); |
| 2549 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2550 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2551 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2552 | put_nfs_open_context(ctx); |
| 2553 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2556 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2557 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2558 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2559 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2560 | write_seqlock(&state->seqlock); |
| 2561 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2562 | write_sequnlock(&state->seqlock); |
| 2563 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2564 | } |
| 2565 | |
| 2566 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2567 | { |
| 2568 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2569 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2573 | { |
| 2574 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2575 | nfs40_clear_delegation_stateid(state); |
| 2576 | return nfs4_open_expired(sp, state); |
| 2577 | } |
| 2578 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2579 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2580 | nfs4_stateid *stateid, |
| 2581 | struct rpc_cred *cred) |
| 2582 | { |
| 2583 | return -NFS4ERR_BAD_STATEID; |
| 2584 | } |
| 2585 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2586 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2587 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2588 | nfs4_stateid *stateid, |
| 2589 | struct rpc_cred *cred) |
| 2590 | { |
| 2591 | int status; |
| 2592 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2593 | switch (stateid->type) { |
| 2594 | default: |
| 2595 | break; |
| 2596 | case NFS4_INVALID_STATEID_TYPE: |
| 2597 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2598 | return -NFS4ERR_BAD_STATEID; |
| 2599 | case NFS4_REVOKED_STATEID_TYPE: |
| 2600 | goto out_free; |
| 2601 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2602 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2603 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2604 | switch (status) { |
| 2605 | case -NFS4ERR_EXPIRED: |
| 2606 | case -NFS4ERR_ADMIN_REVOKED: |
| 2607 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2608 | break; |
| 2609 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2610 | return status; |
| 2611 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2612 | out_free: |
| 2613 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2614 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2615 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2616 | } |
| 2617 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2618 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2619 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2620 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2621 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2622 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2623 | struct rpc_cred *cred; |
| 2624 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2625 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2626 | /* Get the delegation credential for use by test/free_stateid */ |
| 2627 | rcu_read_lock(); |
| 2628 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2629 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2630 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2631 | return; |
| 2632 | } |
| 2633 | |
| 2634 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2635 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2636 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2637 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2638 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2639 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2640 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2641 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2642 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2643 | cred = get_rpccred(delegation->cred); |
| 2644 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2645 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2646 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2647 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2648 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2649 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2650 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2654 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2655 | * |
| 2656 | * @state: NFSv4 state for an inode |
| 2657 | * |
| 2658 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2659 | * Otherwise a negative NFS4ERR value is returned. |
| 2660 | */ |
| 2661 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2662 | { |
| 2663 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2664 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2665 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2666 | |
| 2667 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2668 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2669 | |
| 2670 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2671 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2672 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2673 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2674 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2675 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2676 | spin_unlock(&state->state_lock); |
| 2677 | |
| 2678 | nfs4_put_lock_state(prev); |
| 2679 | prev = lsp; |
| 2680 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2681 | status = nfs41_test_and_free_expired_stateid(server, |
| 2682 | &lsp->ls_stateid, |
| 2683 | cred); |
| 2684 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2685 | if (status == -NFS4ERR_EXPIRED || |
| 2686 | status == -NFS4ERR_BAD_STATEID) { |
| 2687 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2688 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2689 | if (!recover_lost_locks) |
| 2690 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2691 | } else if (status != NFS_OK) { |
| 2692 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2693 | nfs4_put_lock_state(prev); |
| 2694 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2695 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2696 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2697 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2698 | } |
| 2699 | spin_unlock(&state->state_lock); |
| 2700 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2701 | out: |
| 2702 | return ret; |
| 2703 | } |
| 2704 | |
| 2705 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2706 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2707 | * |
| 2708 | * @state: NFSv4 state for an inode |
| 2709 | * |
| 2710 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2711 | * Otherwise a negative NFS4ERR value is returned. |
| 2712 | */ |
| 2713 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2714 | { |
| 2715 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2716 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2717 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2718 | int status; |
| 2719 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2720 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2721 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2722 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2723 | return NFS_OK; |
| 2724 | return -NFS4ERR_OPENMODE; |
| 2725 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2726 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2727 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2728 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2729 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2730 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2731 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2732 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2733 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2734 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2735 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2736 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2737 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2738 | if (nfs_open_stateid_recover_openmode(state)) |
| 2739 | return -NFS4ERR_OPENMODE; |
| 2740 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2744 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2745 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2746 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2747 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2748 | status = nfs41_check_expired_locks(state); |
| 2749 | if (status != NFS_OK) |
| 2750 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2751 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2752 | if (status != NFS_OK) |
| 2753 | status = nfs4_open_expired(sp, state); |
| 2754 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2755 | } |
| 2756 | #endif |
| 2757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2759 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2760 | * fields corresponding to attributes that were used to store the verifier. |
| 2761 | * Make sure we clobber those fields in the later setattr call |
| 2762 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2763 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2764 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2765 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2766 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2767 | __u32 attrset[3]; |
| 2768 | unsigned ret; |
| 2769 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2770 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2771 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2772 | attrset[i] = opendata->o_res.attrset[i]; |
| 2773 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2774 | attrset[i] &= ~bitmask[i]; |
| 2775 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2776 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2777 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2778 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2779 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2780 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2781 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2782 | ret |= ATTR_ATIME_SET; |
| 2783 | else |
| 2784 | ret |= ATTR_ATIME; |
| 2785 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2786 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2787 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2788 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2789 | ret |= ATTR_MTIME_SET; |
| 2790 | else |
| 2791 | ret |= ATTR_MTIME; |
| 2792 | } |
| 2793 | |
| 2794 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2795 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2796 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2797 | } |
| 2798 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2799 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2800 | fmode_t fmode, |
| 2801 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2802 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2803 | { |
| 2804 | struct nfs4_state_owner *sp = opendata->owner; |
| 2805 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2806 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2807 | struct nfs4_state *state; |
| 2808 | unsigned int seq; |
| 2809 | int ret; |
| 2810 | |
| 2811 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2812 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2813 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2814 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2815 | goto out; |
| 2816 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2817 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2818 | ret = PTR_ERR(state); |
| 2819 | if (IS_ERR(state)) |
| 2820 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2821 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2822 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2823 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2824 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2825 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2826 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2827 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2828 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2829 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2830 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2831 | alias = d_exact_alias(dentry, state->inode); |
| 2832 | if (!alias) |
| 2833 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2834 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2835 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2836 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2837 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2838 | } |
| 2839 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2840 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2843 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2844 | if (ret != 0) |
| 2845 | goto out; |
| 2846 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2847 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2848 | nfs_inode_attach_open_context(ctx); |
| 2849 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2850 | nfs4_schedule_stateid_recovery(server, state); |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2851 | else |
| 2852 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2853 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2854 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2855 | out: |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2856 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2857 | return ret; |
| 2858 | } |
| 2859 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2860 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2861 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2863 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2864 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2865 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2866 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2867 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | { |
| 2869 | struct nfs4_state_owner *sp; |
| 2870 | struct nfs4_state *state = NULL; |
| 2871 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2872 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2873 | struct dentry *dentry = ctx->dentry; |
| 2874 | struct rpc_cred *cred = ctx->cred; |
| 2875 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2876 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2877 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2878 | struct iattr *sattr = c->sattr; |
| 2879 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2880 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2881 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | |
| 2883 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2885 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2886 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2888 | goto out_err; |
| 2889 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2890 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2891 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2892 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2893 | if (d_really_is_positive(dentry)) |
| 2894 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2895 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2896 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2897 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2898 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2899 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2900 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2901 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2903 | if (label) { |
| 2904 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2905 | if (IS_ERR(olabel)) { |
| 2906 | status = PTR_ERR(olabel); |
| 2907 | goto err_opendata_put; |
| 2908 | } |
| 2909 | } |
| 2910 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2911 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2912 | if (!opendata->f_attr.mdsthreshold) { |
| 2913 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2914 | if (!opendata->f_attr.mdsthreshold) |
| 2915 | goto err_free_label; |
| 2916 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2917 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2918 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2919 | if (d_really_is_positive(dentry)) |
| 2920 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2921 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2922 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2923 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2924 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2925 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2926 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2927 | 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] | 2928 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2929 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2930 | /* |
| 2931 | * send create attributes which was not set by open |
| 2932 | * with an extra setattr. |
| 2933 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2934 | if (attrs || label) { |
| 2935 | unsigned ia_old = sattr->ia_valid; |
| 2936 | |
| 2937 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2938 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2939 | status = nfs4_do_setattr(state->inode, cred, |
| 2940 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2941 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2942 | if (status == 0) { |
| 2943 | nfs_setattr_update_inode(state->inode, sattr, |
| 2944 | opendata->o_res.f_attr); |
| 2945 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2946 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2947 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2948 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2949 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2950 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2951 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2952 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2953 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2954 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2955 | opendata->f_attr.mdsthreshold = NULL; |
| 2956 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2957 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2958 | nfs4_label_free(olabel); |
| 2959 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2960 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2963 | err_free_label: |
| 2964 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2965 | err_opendata_put: |
| 2966 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2967 | err_put_state_owner: |
| 2968 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | return status; |
| 2971 | } |
| 2972 | |
| 2973 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2974 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2975 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2976 | int flags, |
| 2977 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2978 | struct nfs4_label *label, |
| 2979 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2981 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | struct nfs4_exception exception = { }; |
| 2983 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2984 | struct nfs4_open_createattrs c = { |
| 2985 | .label = label, |
| 2986 | .sattr = sattr, |
| 2987 | .verf = { |
| 2988 | [0] = (__u32)jiffies, |
| 2989 | [1] = (__u32)current->pid, |
| 2990 | }, |
| 2991 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | int status; |
| 2993 | |
| 2994 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2995 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2996 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2997 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | if (status == 0) |
| 2999 | break; |
| 3000 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3001 | * book-keeping w.r.t. state-changing operations |
| 3002 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3003 | * It is actually a sign of a bug on the client or on the server. |
| 3004 | * |
| 3005 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3006 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | * have unhashed the old state_owner for us, and that we can |
| 3008 | * therefore safely retry using a new one. We should still warn |
| 3009 | * the user though... |
| 3010 | */ |
| 3011 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3012 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3013 | " returned a bad sequence-id error!\n", |
| 3014 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | exception.retry = 1; |
| 3016 | continue; |
| 3017 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3018 | /* |
| 3019 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3020 | * state before it received the OPEN_CONFIRM. |
| 3021 | * Recover by retrying the request as per the discussion |
| 3022 | * on Page 181 of RFC3530. |
| 3023 | */ |
| 3024 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3025 | exception.retry = 1; |
| 3026 | continue; |
| 3027 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3028 | if (status == -EAGAIN) { |
| 3029 | /* We must have found a delegation */ |
| 3030 | exception.retry = 1; |
| 3031 | continue; |
| 3032 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3033 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3034 | continue; |
| 3035 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | status, &exception)); |
| 3037 | } while (exception.retry); |
| 3038 | return res; |
| 3039 | } |
| 3040 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3041 | static int _nfs4_do_setattr(struct inode *inode, |
| 3042 | struct nfs_setattrargs *arg, |
| 3043 | struct nfs_setattrres *res, |
| 3044 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3045 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3046 | { |
| 3047 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3048 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3049 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3050 | .rpc_argp = arg, |
| 3051 | .rpc_resp = res, |
| 3052 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3053 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3054 | struct rpc_cred *delegation_cred = NULL; |
| 3055 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3056 | bool truncate; |
| 3057 | int status; |
| 3058 | |
| 3059 | nfs_fattr_init(res->fattr); |
| 3060 | |
| 3061 | /* Servers should only apply open mode checks for file size changes */ |
| 3062 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3063 | if (!truncate) |
| 3064 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3065 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3066 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3067 | /* Use that stateid */ |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3068 | } else if (ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3069 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3070 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3071 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3072 | l_ctx = nfs_get_lock_context(ctx); |
| 3073 | if (IS_ERR(l_ctx)) |
| 3074 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3075 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3076 | &arg->stateid, &delegation_cred); |
| 3077 | nfs_put_lock_context(l_ctx); |
| 3078 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3079 | return -EBADF; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3080 | } else { |
| 3081 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3082 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3083 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3084 | if (delegation_cred) |
| 3085 | msg.rpc_cred = delegation_cred; |
| 3086 | |
| 3087 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3088 | |
| 3089 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3090 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3091 | renew_lease(server, timestamp); |
| 3092 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3093 | return status; |
| 3094 | } |
| 3095 | |
| 3096 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3097 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3098 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3099 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3101 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3102 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3103 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3104 | struct nfs_setattrargs arg = { |
| 3105 | .fh = NFS_FH(inode), |
| 3106 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3108 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3109 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3110 | }; |
| 3111 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3113 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3115 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3116 | struct nfs4_exception exception = { |
| 3117 | .state = state, |
| 3118 | .inode = inode, |
| 3119 | .stateid = &arg.stateid, |
| 3120 | }; |
| 3121 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3124 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3125 | nfs4_bitmask(server, olabel), |
| 3126 | inode); |
| 3127 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3128 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3129 | switch (err) { |
| 3130 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3131 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3132 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3133 | "applying open mode checks to " |
| 3134 | "a SETATTR that is not " |
| 3135 | "changing file size.\n", |
| 3136 | server->nfs_client->cl_hostname); |
| 3137 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3138 | if (state && !(state->state & FMODE_WRITE)) { |
| 3139 | err = -EBADF; |
| 3140 | if (sattr->ia_valid & ATTR_OPEN) |
| 3141 | err = -EACCES; |
| 3142 | goto out; |
| 3143 | } |
| 3144 | } |
| 3145 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3147 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | return err; |
| 3149 | } |
| 3150 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3151 | static bool |
| 3152 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3153 | { |
| 3154 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3155 | return false; |
| 3156 | |
| 3157 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3158 | } |
| 3159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | struct nfs4_closedata { |
| 3161 | struct inode *inode; |
| 3162 | struct nfs4_state *state; |
| 3163 | struct nfs_closeargs arg; |
| 3164 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3165 | struct { |
| 3166 | struct nfs4_layoutreturn_args arg; |
| 3167 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3168 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3169 | u32 roc_barrier; |
| 3170 | bool roc; |
| 3171 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3172 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3173 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | }; |
| 3175 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3176 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3177 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3178 | struct nfs4_closedata *calldata = data; |
| 3179 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3180 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3181 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3182 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3183 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3184 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3185 | nfs4_put_open_state(calldata->state); |
| 3186 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3187 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3188 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3189 | kfree(calldata); |
| 3190 | } |
| 3191 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3192 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3194 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3197 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3198 | struct nfs4_exception exception = { |
| 3199 | .state = state, |
| 3200 | .inode = calldata->inode, |
| 3201 | .stateid = &calldata->arg.stateid, |
| 3202 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3204 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3205 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3206 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3207 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3208 | |
| 3209 | /* Handle Layoutreturn errors */ |
| 3210 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3211 | switch (calldata->res.lr_ret) { |
| 3212 | default: |
| 3213 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3214 | break; |
| 3215 | case 0: |
| 3216 | calldata->arg.lr_args = NULL; |
| 3217 | calldata->res.lr_res = NULL; |
| 3218 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3219 | case -NFS4ERR_OLD_STATEID: |
| 3220 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3221 | calldata->inode)) |
| 3222 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3223 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3224 | case -NFS4ERR_ADMIN_REVOKED: |
| 3225 | case -NFS4ERR_DELEG_REVOKED: |
| 3226 | case -NFS4ERR_EXPIRED: |
| 3227 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3228 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3229 | case -NFS4ERR_WRONG_CRED: |
| 3230 | calldata->arg.lr_args = NULL; |
| 3231 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3232 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3233 | } |
| 3234 | } |
| 3235 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3236 | /* 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] | 3237 | * the state_owner. we keep this around to process errors |
| 3238 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | switch (task->tk_status) { |
| 3240 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3241 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3242 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3243 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3244 | case -NFS4ERR_ACCESS: |
| 3245 | if (calldata->arg.bitmask != NULL) { |
| 3246 | calldata->arg.bitmask = NULL; |
| 3247 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3248 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3249 | |
| 3250 | } |
| 3251 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3252 | case -NFS4ERR_OLD_STATEID: |
| 3253 | /* Did we race with OPEN? */ |
| 3254 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3255 | state)) |
| 3256 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3257 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3258 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3260 | case -NFS4ERR_EXPIRED: |
| 3261 | nfs4_free_revoked_stateid(server, |
| 3262 | &calldata->arg.stateid, |
| 3263 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3264 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3265 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3266 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3268 | task->tk_status = nfs4_async_handle_exception(task, |
| 3269 | server, task->tk_status, &exception); |
| 3270 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3271 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3273 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3274 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3275 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3276 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3277 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3278 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3279 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3280 | return; |
| 3281 | lr_restart: |
| 3282 | calldata->res.lr_ret = 0; |
| 3283 | out_restart: |
| 3284 | task->tk_status = 0; |
| 3285 | rpc_restart_call_prepare(task); |
| 3286 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3289 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3291 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3292 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3293 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3294 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3295 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3296 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3297 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3298 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3299 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3300 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3301 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3302 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3303 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3304 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3305 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3306 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3307 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3308 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3309 | if (state->n_rdonly == 0) |
| 3310 | call_close |= is_rdonly; |
| 3311 | else if (is_rdonly) |
| 3312 | calldata->arg.fmode |= FMODE_READ; |
| 3313 | if (state->n_wronly == 0) |
| 3314 | call_close |= is_wronly; |
| 3315 | else if (is_wronly) |
| 3316 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3317 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3318 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3319 | } else if (is_rdwr) |
| 3320 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3321 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3322 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3323 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3324 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3325 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3326 | |
| 3327 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3328 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3329 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3330 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3331 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3332 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3333 | nfs_release_seqid(calldata->arg.seqid); |
| 3334 | goto out_wait; |
| 3335 | } |
| 3336 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3337 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3338 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3339 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3340 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3341 | /* Close-to-open cache consistency revalidation */ |
| 3342 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3343 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3344 | else |
| 3345 | calldata->arg.bitmask = NULL; |
| 3346 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3347 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3348 | calldata->arg.share_access = |
| 3349 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3350 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3351 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3352 | if (calldata->res.fattr == NULL) |
| 3353 | calldata->arg.bitmask = NULL; |
| 3354 | else if (calldata->arg.bitmask == NULL) |
| 3355 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3356 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3357 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3358 | &calldata->arg.seq_args, |
| 3359 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3360 | task) != 0) |
| 3361 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3362 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3363 | return; |
| 3364 | out_no_action: |
| 3365 | task->tk_action = NULL; |
| 3366 | out_wait: |
| 3367 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3370 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3371 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3372 | .rpc_call_done = nfs4_close_done, |
| 3373 | .rpc_release = nfs4_free_closedata, |
| 3374 | }; |
| 3375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | /* |
| 3377 | * It is possible for data to be read/written from a mem-mapped file |
| 3378 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3379 | * This means that we can't safely call nfsv4 close on a file until |
| 3380 | * the inode is cleared. This in turn means that we are not good |
| 3381 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3382 | * share state even when we are done with one of the three share |
| 3383 | * stateid's in the inode. |
| 3384 | * |
| 3385 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3386 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3387 | 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] | 3388 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3389 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3390 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3392 | struct nfs4_state_owner *sp = state->owner; |
| 3393 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3394 | struct rpc_message msg = { |
| 3395 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3396 | .rpc_cred = state->owner->so_cred, |
| 3397 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3398 | struct rpc_task_setup task_setup_data = { |
| 3399 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3400 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3401 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3402 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3403 | .flags = RPC_TASK_ASYNC, |
| 3404 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3405 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3407 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3408 | &task_setup_data.rpc_client, &msg); |
| 3409 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3410 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3412 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3413 | 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] | 3414 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3416 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3417 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3418 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3420 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3421 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3422 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3423 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3424 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3425 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3426 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3427 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3428 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3429 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3430 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3431 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3432 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3433 | if (calldata->lr.roc) { |
| 3434 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3435 | calldata->res.lr_res = &calldata->lr.res; |
| 3436 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3437 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3438 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3439 | msg.rpc_argp = &calldata->arg; |
| 3440 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3441 | task_setup_data.callback_data = calldata; |
| 3442 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3443 | if (IS_ERR(task)) |
| 3444 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3445 | status = 0; |
| 3446 | if (wait) |
| 3447 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3448 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3449 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3450 | out_free_calldata: |
| 3451 | kfree(calldata); |
| 3452 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3453 | nfs4_put_open_state(state); |
| 3454 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3455 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3458 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3459 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3460 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3463 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3464 | |
| 3465 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3467 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3468 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3469 | |
| 3470 | nfs4_label_release_security(label); |
| 3471 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3472 | if (IS_ERR(state)) |
| 3473 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3474 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3477 | 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] | 3478 | { |
| 3479 | if (ctx->state == NULL) |
| 3480 | return; |
| 3481 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3482 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3483 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3484 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3487 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3488 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3489 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3492 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3493 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3494 | struct nfs4_server_caps_arg args = { |
| 3495 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3496 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3497 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | struct nfs4_server_caps_res res = {}; |
| 3499 | struct rpc_message msg = { |
| 3500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3501 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | .rpc_resp = &res, |
| 3503 | }; |
| 3504 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3505 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3507 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3508 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3509 | FATTR4_WORD0_LINK_SUPPORT | |
| 3510 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3511 | FATTR4_WORD0_ACLSUPPORT; |
| 3512 | if (minorversion) |
| 3513 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3514 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3515 | 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] | 3516 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3517 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3518 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3519 | case 0: |
| 3520 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3521 | res.attr_bitmask[2] = 0; |
| 3522 | break; |
| 3523 | case 1: |
| 3524 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3525 | break; |
| 3526 | case 2: |
| 3527 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3530 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3531 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3532 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3533 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3534 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3535 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3536 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3537 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | server->caps |= NFS_CAP_ACLS; |
| 3539 | if (res.has_links != 0) |
| 3540 | server->caps |= NFS_CAP_HARDLINKS; |
| 3541 | if (res.has_symlinks != 0) |
| 3542 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3543 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3544 | server->caps |= NFS_CAP_FILEID; |
| 3545 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3546 | server->caps |= NFS_CAP_MODE; |
| 3547 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3548 | server->caps |= NFS_CAP_NLINK; |
| 3549 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3550 | server->caps |= NFS_CAP_OWNER; |
| 3551 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3552 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3553 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3554 | server->caps |= NFS_CAP_ATIME; |
| 3555 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3556 | server->caps |= NFS_CAP_CTIME; |
| 3557 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3558 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3559 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3560 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3561 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3562 | #endif |
| 3563 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3564 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3565 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3566 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3567 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3568 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3569 | 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] | 3570 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3571 | |
| 3572 | /* Avoid a regression due to buggy server */ |
| 3573 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3574 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3575 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3576 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3579 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | return status; |
| 3583 | } |
| 3584 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3585 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | { |
| 3587 | struct nfs4_exception exception = { }; |
| 3588 | int err; |
| 3589 | do { |
| 3590 | err = nfs4_handle_exception(server, |
| 3591 | _nfs4_server_capabilities(server, fhandle), |
| 3592 | &exception); |
| 3593 | } while (exception.retry); |
| 3594 | return err; |
| 3595 | } |
| 3596 | |
| 3597 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3598 | struct nfs_fsinfo *info) |
| 3599 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3600 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3602 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | }; |
| 3604 | struct nfs4_lookup_res res = { |
| 3605 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3606 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | .fh = fhandle, |
| 3608 | }; |
| 3609 | struct rpc_message msg = { |
| 3610 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3611 | .rpc_argp = &args, |
| 3612 | .rpc_resp = &res, |
| 3613 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3614 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3615 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3616 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3617 | /* |
| 3618 | * Process the label in the upcoming getfattr |
| 3619 | */ |
| 3620 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3621 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3622 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3623 | 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] | 3624 | } |
| 3625 | |
| 3626 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3627 | struct nfs_fsinfo *info) |
| 3628 | { |
| 3629 | struct nfs4_exception exception = { }; |
| 3630 | int err; |
| 3631 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3632 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3633 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3634 | switch (err) { |
| 3635 | case 0: |
| 3636 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3637 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3638 | default: |
| 3639 | err = nfs4_handle_exception(server, err, &exception); |
| 3640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3642 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | return err; |
| 3644 | } |
| 3645 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3646 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3647 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3648 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3649 | struct rpc_auth_create_args auth_args = { |
| 3650 | .pseudoflavor = flavor, |
| 3651 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3652 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3653 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3654 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3655 | if (IS_ERR(auth)) |
| 3656 | return -EACCES; |
| 3657 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3660 | /* |
| 3661 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3662 | * |
| 3663 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3664 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3665 | * |
| 3666 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3667 | * negative errno value. |
| 3668 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3669 | 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] | 3670 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3672 | /* Per 3530bis 15.33.5 */ |
| 3673 | static const rpc_authflavor_t flav_array[] = { |
| 3674 | RPC_AUTH_GSS_KRB5P, |
| 3675 | RPC_AUTH_GSS_KRB5I, |
| 3676 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3677 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3678 | RPC_AUTH_NULL, |
| 3679 | }; |
| 3680 | int status = -EPERM; |
| 3681 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3683 | if (server->auth_info.flavor_len > 0) { |
| 3684 | /* try each flavor specified by user */ |
| 3685 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3686 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3687 | server->auth_info.flavors[i]); |
| 3688 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3689 | continue; |
| 3690 | break; |
| 3691 | } |
| 3692 | } else { |
| 3693 | /* no flavors specified by user, try default list */ |
| 3694 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3695 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3696 | flav_array[i]); |
| 3697 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3698 | continue; |
| 3699 | break; |
| 3700 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3701 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3702 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3703 | /* |
| 3704 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3705 | * to access the mount. It could also mean that we tried to mount |
| 3706 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3707 | * existing mount programs don't handle -EACCES very well so it should |
| 3708 | * be mapped to -EPERM instead. |
| 3709 | */ |
| 3710 | if (status == -EACCES) |
| 3711 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3712 | return status; |
| 3713 | } |
| 3714 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3715 | /** |
| 3716 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3717 | * @server: initialized nfs_server handle |
| 3718 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3719 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3720 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3721 | * |
| 3722 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3723 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3724 | 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] | 3725 | struct nfs_fsinfo *info, |
| 3726 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3727 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3728 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3729 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3730 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3731 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3732 | |
| 3733 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3734 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3735 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | if (status == 0) |
| 3738 | status = nfs4_server_capabilities(server, fhandle); |
| 3739 | if (status == 0) |
| 3740 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3741 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3742 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3745 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3746 | struct nfs_fsinfo *info) |
| 3747 | { |
| 3748 | int error; |
| 3749 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3750 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3751 | |
| 3752 | error = nfs4_server_capabilities(server, mntfh); |
| 3753 | if (error < 0) { |
| 3754 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3755 | return error; |
| 3756 | } |
| 3757 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3758 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3759 | if (IS_ERR(label)) |
| 3760 | return PTR_ERR(label); |
| 3761 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3762 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3763 | if (error < 0) { |
| 3764 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3765 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3769 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3770 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3771 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3772 | err_free_label: |
| 3773 | nfs4_label_free(label); |
| 3774 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3775 | return error; |
| 3776 | } |
| 3777 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3778 | /* |
| 3779 | * Get locations and (maybe) other attributes of a referral. |
| 3780 | * Note that we'll actually follow the referral later when |
| 3781 | * we detect fsid mismatch in inode revalidation |
| 3782 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3783 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3784 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3785 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3786 | { |
| 3787 | int status = -ENOMEM; |
| 3788 | struct page *page = NULL; |
| 3789 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3790 | |
| 3791 | page = alloc_page(GFP_KERNEL); |
| 3792 | if (page == NULL) |
| 3793 | goto out; |
| 3794 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3795 | if (locations == NULL) |
| 3796 | goto out; |
| 3797 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3798 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3799 | if (status != 0) |
| 3800 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3801 | |
| 3802 | /* |
| 3803 | * If the fsid didn't change, this is a migration event, not a |
| 3804 | * referral. Cause us to drop into the exception handler, which |
| 3805 | * will kick off migration recovery. |
| 3806 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3807 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3808 | dprintk("%s: server did not return a different fsid for" |
| 3809 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3810 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3811 | goto out; |
| 3812 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3813 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3814 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3815 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3816 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3817 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3818 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3819 | out: |
| 3820 | if (page) |
| 3821 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3822 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3823 | return status; |
| 3824 | } |
| 3825 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3826 | 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] | 3827 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3828 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3830 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | struct nfs4_getattr_arg args = { |
| 3832 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3833 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | }; |
| 3835 | struct nfs4_getattr_res res = { |
| 3836 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3837 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | .server = server, |
| 3839 | }; |
| 3840 | struct rpc_message msg = { |
| 3841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3842 | .rpc_argp = &args, |
| 3843 | .rpc_resp = &res, |
| 3844 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3845 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3846 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3847 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3848 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3849 | 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] | 3850 | } |
| 3851 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3852 | 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] | 3853 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3854 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | { |
| 3856 | struct nfs4_exception exception = { }; |
| 3857 | int err; |
| 3858 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3859 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3860 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3861 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | &exception); |
| 3863 | } while (exception.retry); |
| 3864 | return err; |
| 3865 | } |
| 3866 | |
| 3867 | /* |
| 3868 | * The file is not closed if it is opened due to the a request to change |
| 3869 | * the size of the file. The open call will not be needed once the |
| 3870 | * VFS layer lookup-intents are implemented. |
| 3871 | * |
| 3872 | * Close is called when the inode is destroyed. |
| 3873 | * If we haven't opened the file for O_WRONLY, we |
| 3874 | * need to in the size_change case to obtain a stateid. |
| 3875 | * |
| 3876 | * Got race? |
| 3877 | * Because OPEN is always done by name in nfsv4, it is |
| 3878 | * possible that we opened a different file by the same |
| 3879 | * name. We can recognize this race condition, but we |
| 3880 | * can't do anything about it besides returning an error. |
| 3881 | * |
| 3882 | * This will be fixed with VFS changes (lookup-intent). |
| 3883 | */ |
| 3884 | static int |
| 3885 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3886 | struct iattr *sattr) |
| 3887 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3888 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3889 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3890 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3891 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | int status; |
| 3893 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3894 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3895 | sattr->ia_valid & ATTR_SIZE && |
| 3896 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3897 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3898 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3899 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3901 | /* Deal with open(O_TRUNC) */ |
| 3902 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3903 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3904 | |
| 3905 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3906 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3907 | return 0; |
| 3908 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3909 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3910 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3911 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3912 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3913 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3914 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3915 | } |
| 3916 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3917 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3918 | if (IS_ERR(label)) |
| 3919 | return PTR_ERR(label); |
| 3920 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3921 | /* Return any delegations if we're going to change ACLs */ |
| 3922 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 3923 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3924 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3925 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3926 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3927 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3928 | nfs_setsecurity(inode, fattr, label); |
| 3929 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3930 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | return status; |
| 3932 | } |
| 3933 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3934 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3935 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3936 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3937 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3938 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3939 | int status; |
| 3940 | struct nfs4_lookup_arg args = { |
| 3941 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3942 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3943 | .name = name, |
| 3944 | }; |
| 3945 | struct nfs4_lookup_res res = { |
| 3946 | .server = server, |
| 3947 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3948 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3949 | .fh = fhandle, |
| 3950 | }; |
| 3951 | struct rpc_message msg = { |
| 3952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3953 | .rpc_argp = &args, |
| 3954 | .rpc_resp = &res, |
| 3955 | }; |
| 3956 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3957 | args.bitmask = nfs4_bitmask(server, label); |
| 3958 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3959 | nfs_fattr_init(fattr); |
| 3960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3962 | 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] | 3963 | dprintk("NFS reply lookup: %d\n", status); |
| 3964 | return status; |
| 3965 | } |
| 3966 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3967 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3968 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3969 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3970 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3971 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3972 | fattr->nlink = 2; |
| 3973 | } |
| 3974 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3975 | 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] | 3976 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3977 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3978 | { |
| 3979 | struct nfs4_exception exception = { }; |
| 3980 | struct rpc_clnt *client = *clnt; |
| 3981 | int err; |
| 3982 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3983 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3984 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3985 | switch (err) { |
| 3986 | case -NFS4ERR_BADNAME: |
| 3987 | err = -ENOENT; |
| 3988 | goto out; |
| 3989 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3990 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3991 | if (err == -NFS4ERR_MOVED) |
| 3992 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3993 | goto out; |
| 3994 | case -NFS4ERR_WRONGSEC: |
| 3995 | err = -EPERM; |
| 3996 | if (client != *clnt) |
| 3997 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3998 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3999 | if (IS_ERR(client)) |
| 4000 | return PTR_ERR(client); |
| 4001 | |
| 4002 | exception.retry = 1; |
| 4003 | break; |
| 4004 | default: |
| 4005 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4006 | } |
| 4007 | } while (exception.retry); |
| 4008 | |
| 4009 | out: |
| 4010 | if (err == 0) |
| 4011 | *clnt = client; |
| 4012 | else if (client != *clnt) |
| 4013 | rpc_shutdown_client(client); |
| 4014 | |
| 4015 | return err; |
| 4016 | } |
| 4017 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4018 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4019 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4020 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4022 | int status; |
| 4023 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4024 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4025 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4026 | if (client != NFS_CLIENT(dir)) { |
| 4027 | rpc_shutdown_client(client); |
| 4028 | nfs_fixup_secinfo_attributes(fattr); |
| 4029 | } |
| 4030 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4033 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4034 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4035 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4036 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4037 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4038 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4039 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4040 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4041 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4042 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4043 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4044 | } |
| 4045 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4046 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4047 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4048 | struct nfs4_label *label) |
| 4049 | { |
| 4050 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4051 | struct nfs_server *server = NFS_SERVER(inode); |
| 4052 | int status; |
| 4053 | struct nfs4_lookupp_arg args = { |
| 4054 | .bitmask = server->attr_bitmask, |
| 4055 | .fh = NFS_FH(inode), |
| 4056 | }; |
| 4057 | struct nfs4_lookupp_res res = { |
| 4058 | .server = server, |
| 4059 | .fattr = fattr, |
| 4060 | .label = label, |
| 4061 | .fh = fhandle, |
| 4062 | }; |
| 4063 | struct rpc_message msg = { |
| 4064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4065 | .rpc_argp = &args, |
| 4066 | .rpc_resp = &res, |
| 4067 | }; |
| 4068 | |
| 4069 | args.bitmask = nfs4_bitmask(server, label); |
| 4070 | |
| 4071 | nfs_fattr_init(fattr); |
| 4072 | |
| 4073 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4074 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4075 | &res.seq_res, 0); |
| 4076 | dprintk("NFS reply lookupp: %d\n", status); |
| 4077 | return status; |
| 4078 | } |
| 4079 | |
| 4080 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4081 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4082 | { |
| 4083 | struct nfs4_exception exception = { }; |
| 4084 | int err; |
| 4085 | do { |
| 4086 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4087 | trace_nfs4_lookupp(inode, err); |
| 4088 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4089 | &exception); |
| 4090 | } while (exception.retry); |
| 4091 | return err; |
| 4092 | } |
| 4093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4095 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4096 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | struct nfs4_accessargs args = { |
| 4098 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4099 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4101 | struct nfs4_accessres res = { |
| 4102 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | struct rpc_message msg = { |
| 4105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4106 | .rpc_argp = &args, |
| 4107 | .rpc_resp = &res, |
| 4108 | .rpc_cred = entry->cred, |
| 4109 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4110 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4112 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4113 | res.fattr = nfs_alloc_fattr(); |
| 4114 | if (res.fattr == NULL) |
| 4115 | return -ENOMEM; |
| 4116 | args.bitmask = server->cache_consistency_bitmask; |
| 4117 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4118 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4119 | 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] | 4120 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4121 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4122 | if (res.fattr) |
| 4123 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4125 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | return status; |
| 4127 | } |
| 4128 | |
| 4129 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4130 | { |
| 4131 | struct nfs4_exception exception = { }; |
| 4132 | int err; |
| 4133 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4134 | err = _nfs4_proc_access(inode, entry); |
| 4135 | trace_nfs4_access(inode, err); |
| 4136 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | &exception); |
| 4138 | } while (exception.retry); |
| 4139 | return err; |
| 4140 | } |
| 4141 | |
| 4142 | /* |
| 4143 | * TODO: For the time being, we don't try to get any attributes |
| 4144 | * along with any of the zero-copy operations READ, READDIR, |
| 4145 | * READLINK, WRITE. |
| 4146 | * |
| 4147 | * In the case of the first three, we want to put the GETATTR |
| 4148 | * after the read-type operation -- this is because it is hard |
| 4149 | * to predict the length of a GETATTR response in v4, and thus |
| 4150 | * align the READ data correctly. This means that the GETATTR |
| 4151 | * may end up partially falling into the page cache, and we should |
| 4152 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4153 | * To do this efficiently, we need to know the total length |
| 4154 | * of data received, which doesn't seem to be available outside |
| 4155 | * of the RPC layer. |
| 4156 | * |
| 4157 | * In the case of WRITE, we also want to put the GETATTR after |
| 4158 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4159 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | * |
| 4161 | * Both of these changes to the XDR layer would in fact be quite |
| 4162 | * minor, but I decided to leave them for a subsequent patch. |
| 4163 | */ |
| 4164 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4165 | unsigned int pgbase, unsigned int pglen) |
| 4166 | { |
| 4167 | struct nfs4_readlink args = { |
| 4168 | .fh = NFS_FH(inode), |
| 4169 | .pgbase = pgbase, |
| 4170 | .pglen = pglen, |
| 4171 | .pages = &page, |
| 4172 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4173 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | struct rpc_message msg = { |
| 4175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4176 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4177 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | }; |
| 4179 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4180 | 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] | 4181 | } |
| 4182 | |
| 4183 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4184 | unsigned int pgbase, unsigned int pglen) |
| 4185 | { |
| 4186 | struct nfs4_exception exception = { }; |
| 4187 | int err; |
| 4188 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4189 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4190 | trace_nfs4_readlink(inode, err); |
| 4191 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | &exception); |
| 4193 | } while (exception.retry); |
| 4194 | return err; |
| 4195 | } |
| 4196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4198 | * 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] | 4199 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | static int |
| 4201 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4202 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4204 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4205 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4206 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | int status = 0; |
| 4209 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4210 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4211 | if (IS_ERR(ctx)) |
| 4212 | return PTR_ERR(ctx); |
| 4213 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4214 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4215 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4216 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4217 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4218 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | if (IS_ERR(state)) { |
| 4220 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4221 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4224 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4225 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | return status; |
| 4227 | } |
| 4228 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4229 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4231 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4232 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4234 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4236 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4237 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4240 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4241 | .rpc_argp = &args, |
| 4242 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4244 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4245 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4246 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4247 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4248 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4249 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | return status; |
| 4251 | } |
| 4252 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4253 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4254 | { |
| 4255 | struct nfs4_exception exception = { }; |
| 4256 | struct inode *inode = d_inode(dentry); |
| 4257 | int err; |
| 4258 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4259 | if (inode) { |
| 4260 | if (inode->i_nlink == 1) |
| 4261 | nfs4_inode_return_delegation(inode); |
| 4262 | else |
| 4263 | nfs4_inode_make_writeable(inode); |
| 4264 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4265 | do { |
| 4266 | err = _nfs4_proc_remove(dir, &dentry->d_name); |
| 4267 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4268 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4269 | &exception); |
| 4270 | } while (exception.retry); |
| 4271 | return err; |
| 4272 | } |
| 4273 | |
| 4274 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | { |
| 4276 | struct nfs4_exception exception = { }; |
| 4277 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4280 | err = _nfs4_proc_remove(dir, name); |
| 4281 | trace_nfs4_remove(dir, name, err); |
| 4282 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | &exception); |
| 4284 | } while (exception.retry); |
| 4285 | return err; |
| 4286 | } |
| 4287 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4288 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4289 | struct dentry *dentry, |
| 4290 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4292 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4293 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4295 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4297 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4298 | |
| 4299 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4300 | |
| 4301 | if (inode) |
| 4302 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4305 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4306 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4307 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4308 | &data->args.seq_args, |
| 4309 | &data->res.seq_res, |
| 4310 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | } |
| 4312 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4313 | 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] | 4314 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4315 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4316 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4317 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4318 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4319 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4320 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4321 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4322 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4323 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4324 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4325 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4328 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4329 | struct dentry *old_dentry, |
| 4330 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4331 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4332 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4333 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4334 | struct inode *old_inode = d_inode(old_dentry); |
| 4335 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4336 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4337 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4338 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4339 | if (new_inode) |
| 4340 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4341 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4342 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4343 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4344 | } |
| 4345 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4346 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4347 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4348 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4349 | &data->args.seq_args, |
| 4350 | &data->res.seq_res, |
| 4351 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4355 | struct inode *new_dir) |
| 4356 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4357 | struct nfs_renamedata *data = task->tk_calldata; |
| 4358 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4359 | |
| 4360 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4361 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4362 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4363 | return 0; |
| 4364 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4365 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4366 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4367 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4368 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4369 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4370 | return 1; |
| 4371 | } |
| 4372 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4373 | 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] | 4374 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4375 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4376 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | struct nfs4_link_arg arg = { |
| 4378 | .fh = NFS_FH(inode), |
| 4379 | .dir_fh = NFS_FH(dir), |
| 4380 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4381 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4383 | struct nfs4_link_res res = { |
| 4384 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4385 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4386 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | struct rpc_message msg = { |
| 4388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4389 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4390 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4392 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4394 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4395 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4396 | goto out; |
| 4397 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4398 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4399 | if (IS_ERR(res.label)) { |
| 4400 | status = PTR_ERR(res.label); |
| 4401 | goto out; |
| 4402 | } |
| 4403 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4404 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4405 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4406 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4407 | 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] | 4408 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4409 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4410 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4411 | if (!status) |
| 4412 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4413 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4414 | |
| 4415 | |
| 4416 | nfs4_label_free(res.label); |
| 4417 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4418 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4419 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | return status; |
| 4421 | } |
| 4422 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4423 | 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] | 4424 | { |
| 4425 | struct nfs4_exception exception = { }; |
| 4426 | int err; |
| 4427 | do { |
| 4428 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4429 | _nfs4_proc_link(inode, dir, name), |
| 4430 | &exception); |
| 4431 | } while (exception.retry); |
| 4432 | return err; |
| 4433 | } |
| 4434 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4435 | struct nfs4_createdata { |
| 4436 | struct rpc_message msg; |
| 4437 | struct nfs4_create_arg arg; |
| 4438 | struct nfs4_create_res res; |
| 4439 | struct nfs_fh fh; |
| 4440 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4441 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4442 | }; |
| 4443 | |
| 4444 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4445 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4446 | { |
| 4447 | struct nfs4_createdata *data; |
| 4448 | |
| 4449 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4450 | if (data != NULL) { |
| 4451 | struct nfs_server *server = NFS_SERVER(dir); |
| 4452 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4453 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4454 | if (IS_ERR(data->label)) |
| 4455 | goto out_free; |
| 4456 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4457 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4458 | data->msg.rpc_argp = &data->arg; |
| 4459 | data->msg.rpc_resp = &data->res; |
| 4460 | data->arg.dir_fh = NFS_FH(dir); |
| 4461 | data->arg.server = server; |
| 4462 | data->arg.name = name; |
| 4463 | data->arg.attrs = sattr; |
| 4464 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4465 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4466 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4467 | data->res.server = server; |
| 4468 | data->res.fh = &data->fh; |
| 4469 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4470 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4471 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4472 | } |
| 4473 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4474 | out_free: |
| 4475 | kfree(data); |
| 4476 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4480 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4481 | 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] | 4482 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4483 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4484 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4485 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4486 | 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] | 4487 | } |
| 4488 | return status; |
| 4489 | } |
| 4490 | |
| 4491 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4492 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4493 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4494 | kfree(data); |
| 4495 | } |
| 4496 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4497 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4498 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4499 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4501 | struct nfs4_createdata *data; |
| 4502 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4504 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4505 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4506 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4507 | status = -ENOMEM; |
| 4508 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4509 | if (data == NULL) |
| 4510 | goto out; |
| 4511 | |
| 4512 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4513 | data->arg.u.symlink.pages = &page; |
| 4514 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4515 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4517 | status = nfs4_do_create(dir, dentry, data); |
| 4518 | |
| 4519 | nfs4_free_createdata(data); |
| 4520 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | return status; |
| 4522 | } |
| 4523 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4524 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4525 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | { |
| 4527 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4528 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4530 | |
| 4531 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4534 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4535 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4536 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | &exception); |
| 4538 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4539 | |
| 4540 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | return err; |
| 4542 | } |
| 4543 | |
| 4544 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4545 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4547 | struct nfs4_createdata *data; |
| 4548 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4550 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4551 | if (data == NULL) |
| 4552 | goto out; |
| 4553 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4554 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4555 | status = nfs4_do_create(dir, dentry, data); |
| 4556 | |
| 4557 | nfs4_free_createdata(data); |
| 4558 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | return status; |
| 4560 | } |
| 4561 | |
| 4562 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4563 | struct iattr *sattr) |
| 4564 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4565 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4567 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4569 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4570 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4571 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4572 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4573 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4575 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4576 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4577 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | &exception); |
| 4579 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4580 | nfs4_label_release_security(label); |
| 4581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | return err; |
| 4583 | } |
| 4584 | |
| 4585 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4586 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4588 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | struct nfs4_readdir_arg args = { |
| 4590 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4591 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | .pgbase = 0, |
| 4593 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4594 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4595 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | }; |
| 4597 | struct nfs4_readdir_res res; |
| 4598 | struct rpc_message msg = { |
| 4599 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4600 | .rpc_argp = &args, |
| 4601 | .rpc_resp = &res, |
| 4602 | .rpc_cred = cred, |
| 4603 | }; |
| 4604 | int status; |
| 4605 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4606 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4607 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4608 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4609 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4611 | 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] | 4612 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4613 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4614 | status += args.pgbase; |
| 4615 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4616 | |
| 4617 | nfs_invalidate_atime(dir); |
| 4618 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4619 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | return status; |
| 4621 | } |
| 4622 | |
| 4623 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4624 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | { |
| 4626 | struct nfs4_exception exception = { }; |
| 4627 | int err; |
| 4628 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4629 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4630 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4631 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4632 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | &exception); |
| 4634 | } while (exception.retry); |
| 4635 | return err; |
| 4636 | } |
| 4637 | |
| 4638 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4639 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4641 | struct nfs4_createdata *data; |
| 4642 | int mode = sattr->ia_mode; |
| 4643 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4645 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4646 | if (data == NULL) |
| 4647 | goto out; |
| 4648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4650 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4652 | data->arg.ftype = NF4BLK; |
| 4653 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4654 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } |
| 4656 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4657 | data->arg.ftype = NF4CHR; |
| 4658 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4659 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4660 | } else if (!S_ISSOCK(mode)) { |
| 4661 | status = -EINVAL; |
| 4662 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4664 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4665 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4666 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4667 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4668 | nfs4_free_createdata(data); |
| 4669 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | return status; |
| 4671 | } |
| 4672 | |
| 4673 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4674 | struct iattr *sattr, dev_t rdev) |
| 4675 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4676 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4678 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4680 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4681 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4682 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4683 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4684 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4686 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4687 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4688 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | &exception); |
| 4690 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4691 | |
| 4692 | nfs4_label_release_security(label); |
| 4693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | return err; |
| 4695 | } |
| 4696 | |
| 4697 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4698 | struct nfs_fsstat *fsstat) |
| 4699 | { |
| 4700 | struct nfs4_statfs_arg args = { |
| 4701 | .fh = fhandle, |
| 4702 | .bitmask = server->attr_bitmask, |
| 4703 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4704 | struct nfs4_statfs_res res = { |
| 4705 | .fsstat = fsstat, |
| 4706 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | struct rpc_message msg = { |
| 4708 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4709 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4710 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | }; |
| 4712 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4713 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4714 | 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] | 4715 | } |
| 4716 | |
| 4717 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4718 | { |
| 4719 | struct nfs4_exception exception = { }; |
| 4720 | int err; |
| 4721 | do { |
| 4722 | err = nfs4_handle_exception(server, |
| 4723 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4724 | &exception); |
| 4725 | } while (exception.retry); |
| 4726 | return err; |
| 4727 | } |
| 4728 | |
| 4729 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4730 | struct nfs_fsinfo *fsinfo) |
| 4731 | { |
| 4732 | struct nfs4_fsinfo_arg args = { |
| 4733 | .fh = fhandle, |
| 4734 | .bitmask = server->attr_bitmask, |
| 4735 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4736 | struct nfs4_fsinfo_res res = { |
| 4737 | .fsinfo = fsinfo, |
| 4738 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | struct rpc_message msg = { |
| 4740 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4741 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4742 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | }; |
| 4744 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4745 | 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] | 4746 | } |
| 4747 | |
| 4748 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4749 | { |
| 4750 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4751 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | int err; |
| 4753 | |
| 4754 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4755 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4756 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4757 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4758 | nfs4_set_lease_period(server->nfs_client, |
| 4759 | fsinfo->lease_time * HZ, |
| 4760 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4761 | break; |
| 4762 | } |
| 4763 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | } while (exception.retry); |
| 4765 | return err; |
| 4766 | } |
| 4767 | |
| 4768 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4769 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4770 | int error; |
| 4771 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4772 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4773 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4774 | if (error == 0) { |
| 4775 | /* block layout checks this! */ |
| 4776 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4777 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4778 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4779 | |
| 4780 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4784 | struct nfs_pathconf *pathconf) |
| 4785 | { |
| 4786 | struct nfs4_pathconf_arg args = { |
| 4787 | .fh = fhandle, |
| 4788 | .bitmask = server->attr_bitmask, |
| 4789 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4790 | struct nfs4_pathconf_res res = { |
| 4791 | .pathconf = pathconf, |
| 4792 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | struct rpc_message msg = { |
| 4794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4795 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4796 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | }; |
| 4798 | |
| 4799 | /* None of the pathconf attributes are mandatory to implement */ |
| 4800 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4801 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4802 | return 0; |
| 4803 | } |
| 4804 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4805 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4806 | 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] | 4807 | } |
| 4808 | |
| 4809 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4810 | struct nfs_pathconf *pathconf) |
| 4811 | { |
| 4812 | struct nfs4_exception exception = { }; |
| 4813 | int err; |
| 4814 | |
| 4815 | do { |
| 4816 | err = nfs4_handle_exception(server, |
| 4817 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4818 | &exception); |
| 4819 | } while (exception.retry); |
| 4820 | return err; |
| 4821 | } |
| 4822 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4823 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4824 | const struct nfs_open_context *ctx, |
| 4825 | const struct nfs_lock_context *l_ctx, |
| 4826 | fmode_t fmode) |
| 4827 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4828 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4829 | } |
| 4830 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4831 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4832 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4833 | const struct nfs_open_context *ctx, |
| 4834 | const struct nfs_lock_context *l_ctx, |
| 4835 | fmode_t fmode) |
| 4836 | { |
| 4837 | nfs4_stateid current_stateid; |
| 4838 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4839 | /* If the current stateid represents a lost lock, then exit */ |
| 4840 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4841 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4842 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4843 | } |
| 4844 | |
| 4845 | static bool nfs4_error_stateid_expired(int err) |
| 4846 | { |
| 4847 | switch (err) { |
| 4848 | case -NFS4ERR_DELEG_REVOKED: |
| 4849 | case -NFS4ERR_ADMIN_REVOKED: |
| 4850 | case -NFS4ERR_BAD_STATEID: |
| 4851 | case -NFS4ERR_STALE_STATEID: |
| 4852 | case -NFS4ERR_OLD_STATEID: |
| 4853 | case -NFS4ERR_OPENMODE: |
| 4854 | case -NFS4ERR_EXPIRED: |
| 4855 | return true; |
| 4856 | } |
| 4857 | return false; |
| 4858 | } |
| 4859 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4860 | 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] | 4861 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4862 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4864 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4865 | if (task->tk_status < 0) { |
| 4866 | struct nfs4_exception exception = { |
| 4867 | .inode = hdr->inode, |
| 4868 | .state = hdr->args.context->state, |
| 4869 | .stateid = &hdr->args.stateid, |
| 4870 | }; |
| 4871 | task->tk_status = nfs4_async_handle_exception(task, |
| 4872 | server, task->tk_status, &exception); |
| 4873 | if (exception.retry) { |
| 4874 | rpc_restart_call_prepare(task); |
| 4875 | return -EAGAIN; |
| 4876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4880 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4881 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4884 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4885 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4886 | { |
| 4887 | |
| 4888 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4889 | nfs4_stateid_is_current(&args->stateid, |
| 4890 | args->context, |
| 4891 | args->lock_context, |
| 4892 | FMODE_READ)) |
| 4893 | return false; |
| 4894 | rpc_restart_call_prepare(task); |
| 4895 | return true; |
| 4896 | } |
| 4897 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4898 | 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] | 4899 | { |
| 4900 | |
| 4901 | dprintk("--> %s\n", __func__); |
| 4902 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4903 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4904 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4905 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4906 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4907 | if (task->tk_status > 0) |
| 4908 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4909 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4910 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4913 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4914 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4916 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4917 | if (!hdr->pgio_done_cb) |
| 4918 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4919 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4920 | 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] | 4921 | } |
| 4922 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4923 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4924 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4925 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4926 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4927 | &hdr->args.seq_args, |
| 4928 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4929 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4930 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4931 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4932 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4933 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4934 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4935 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4936 | return -EIO; |
| 4937 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4940 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4941 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4943 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4944 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4945 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4946 | if (task->tk_status < 0) { |
| 4947 | struct nfs4_exception exception = { |
| 4948 | .inode = hdr->inode, |
| 4949 | .state = hdr->args.context->state, |
| 4950 | .stateid = &hdr->args.stateid, |
| 4951 | }; |
| 4952 | task->tk_status = nfs4_async_handle_exception(task, |
| 4953 | NFS_SERVER(inode), task->tk_status, |
| 4954 | &exception); |
| 4955 | if (exception.retry) { |
| 4956 | rpc_restart_call_prepare(task); |
| 4957 | return -EAGAIN; |
| 4958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4960 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4961 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4962 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4963 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4964 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4967 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4968 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4969 | { |
| 4970 | |
| 4971 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4972 | nfs4_stateid_is_current(&args->stateid, |
| 4973 | args->context, |
| 4974 | args->lock_context, |
| 4975 | FMODE_WRITE)) |
| 4976 | return false; |
| 4977 | rpc_restart_call_prepare(task); |
| 4978 | return true; |
| 4979 | } |
| 4980 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4981 | 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] | 4982 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4983 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4984 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4985 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4986 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4987 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4988 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4989 | } |
| 4990 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4991 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4992 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4993 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4994 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4995 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4996 | return false; |
| 4997 | /* Otherwise, request attributes if and only if we don't hold |
| 4998 | * a delegation |
| 4999 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5000 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5001 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5002 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5003 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5004 | struct rpc_message *msg, |
| 5005 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5007 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5008 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5009 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5010 | hdr->args.bitmask = NULL; |
| 5011 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5012 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5013 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5014 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5015 | if (!hdr->pgio_done_cb) |
| 5016 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5017 | hdr->res.server = server; |
| 5018 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5020 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5021 | 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] | 5022 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5025 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5026 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5027 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5028 | &data->args.seq_args, |
| 5029 | &data->res.seq_res, |
| 5030 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | } |
| 5032 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5033 | 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] | 5034 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5036 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5037 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5038 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5039 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5040 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5041 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5043 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5044 | } |
| 5045 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5046 | 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] | 5047 | { |
| 5048 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5049 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5050 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5053 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5054 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5056 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5057 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5058 | if (data->commit_done_cb == NULL) |
| 5059 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5060 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5061 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5062 | 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] | 5063 | 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] | 5064 | } |
| 5065 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5066 | struct nfs4_renewdata { |
| 5067 | struct nfs_client *client; |
| 5068 | unsigned long timestamp; |
| 5069 | }; |
| 5070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | /* |
| 5072 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5073 | * standalone procedure for queueing an asynchronous RENEW. |
| 5074 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5075 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5076 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5077 | struct nfs4_renewdata *data = calldata; |
| 5078 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5079 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5080 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5081 | nfs4_schedule_state_renewal(clp); |
| 5082 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5083 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5084 | } |
| 5085 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5086 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5088 | struct nfs4_renewdata *data = calldata; |
| 5089 | struct nfs_client *clp = data->client; |
| 5090 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5092 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5093 | switch (task->tk_status) { |
| 5094 | case 0: |
| 5095 | break; |
| 5096 | case -NFS4ERR_LEASE_MOVED: |
| 5097 | nfs4_schedule_lease_moved_recovery(clp); |
| 5098 | break; |
| 5099 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5100 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5101 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5102 | return; |
| 5103 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5104 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5105 | return; |
| 5106 | } |
| 5107 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5109 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | } |
| 5111 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5112 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5113 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5114 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5115 | }; |
| 5116 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5117 | 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] | 5118 | { |
| 5119 | struct rpc_message msg = { |
| 5120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5121 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5122 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5124 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5126 | if (renew_flags == 0) |
| 5127 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5128 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5129 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5130 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5131 | if (data == NULL) { |
| 5132 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5133 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5134 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5135 | data->client = clp; |
| 5136 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5137 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5138 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5141 | 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] | 5142 | { |
| 5143 | struct rpc_message msg = { |
| 5144 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5145 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5146 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | }; |
| 5148 | unsigned long now = jiffies; |
| 5149 | int status; |
| 5150 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5151 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | if (status < 0) |
| 5153 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5154 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | return 0; |
| 5156 | } |
| 5157 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5158 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5159 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5160 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5163 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5164 | * 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] | 5165 | * the stack. |
| 5166 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5167 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5168 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5169 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5170 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5171 | { |
| 5172 | struct page *newpage, **spages; |
| 5173 | int rc = 0; |
| 5174 | size_t len; |
| 5175 | spages = pages; |
| 5176 | |
| 5177 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5178 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5179 | newpage = alloc_page(GFP_KERNEL); |
| 5180 | |
| 5181 | if (newpage == NULL) |
| 5182 | goto unwind; |
| 5183 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5184 | buf += len; |
| 5185 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5186 | *pages++ = newpage; |
| 5187 | rc++; |
| 5188 | } while (buflen != 0); |
| 5189 | |
| 5190 | return rc; |
| 5191 | |
| 5192 | unwind: |
| 5193 | for(; rc > 0; rc--) |
| 5194 | __free_page(spages[rc-1]); |
| 5195 | return -ENOMEM; |
| 5196 | } |
| 5197 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5198 | struct nfs4_cached_acl { |
| 5199 | int cached; |
| 5200 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5201 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5202 | }; |
| 5203 | |
| 5204 | 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] | 5205 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5206 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5207 | |
| 5208 | spin_lock(&inode->i_lock); |
| 5209 | kfree(nfsi->nfs4_acl); |
| 5210 | nfsi->nfs4_acl = acl; |
| 5211 | spin_unlock(&inode->i_lock); |
| 5212 | } |
| 5213 | |
| 5214 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5215 | { |
| 5216 | nfs4_set_cached_acl(inode, NULL); |
| 5217 | } |
| 5218 | |
| 5219 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5220 | { |
| 5221 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5222 | struct nfs4_cached_acl *acl; |
| 5223 | int ret = -ENOENT; |
| 5224 | |
| 5225 | spin_lock(&inode->i_lock); |
| 5226 | acl = nfsi->nfs4_acl; |
| 5227 | if (acl == NULL) |
| 5228 | goto out; |
| 5229 | if (buf == NULL) /* user is just asking for length */ |
| 5230 | goto out_len; |
| 5231 | if (acl->cached == 0) |
| 5232 | goto out; |
| 5233 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5234 | if (acl->len > buflen) |
| 5235 | goto out; |
| 5236 | memcpy(buf, acl->data, acl->len); |
| 5237 | out_len: |
| 5238 | ret = acl->len; |
| 5239 | out: |
| 5240 | spin_unlock(&inode->i_lock); |
| 5241 | return ret; |
| 5242 | } |
| 5243 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5244 | 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] | 5245 | { |
| 5246 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5247 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5248 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5249 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5250 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5251 | if (acl == NULL) |
| 5252 | goto out; |
| 5253 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5254 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5255 | } else { |
| 5256 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5257 | if (acl == NULL) |
| 5258 | goto out; |
| 5259 | acl->cached = 0; |
| 5260 | } |
| 5261 | acl->len = acl_len; |
| 5262 | out: |
| 5263 | nfs4_set_cached_acl(inode, acl); |
| 5264 | } |
| 5265 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5266 | /* |
| 5267 | * The getxattr API returns the required buffer length when called with a |
| 5268 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5269 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5270 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5271 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5272 | * the cache. If not so, we throw away the page, and cache the required |
| 5273 | * length. The next getxattr call will then produce another round trip to |
| 5274 | * the server, this time with the input buf of the required size. |
| 5275 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5276 | 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] | 5277 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5278 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5279 | struct nfs_getaclargs args = { |
| 5280 | .fh = NFS_FH(inode), |
| 5281 | .acl_pages = pages, |
| 5282 | .acl_len = buflen, |
| 5283 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5284 | struct nfs_getaclres res = { |
| 5285 | .acl_len = buflen, |
| 5286 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5287 | struct rpc_message msg = { |
| 5288 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5289 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5290 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5291 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5292 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5293 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5294 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5295 | if (npages > ARRAY_SIZE(pages)) |
| 5296 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5297 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5298 | for (i = 0; i < npages; i++) { |
| 5299 | pages[i] = alloc_page(GFP_KERNEL); |
| 5300 | if (!pages[i]) |
| 5301 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5302 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5303 | |
| 5304 | /* for decoding across pages */ |
| 5305 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5306 | if (!res.acl_scratch) |
| 5307 | goto out_free; |
| 5308 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5309 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5310 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5311 | 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] | 5312 | __func__, buf, buflen, npages, args.acl_len); |
| 5313 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5314 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5315 | if (ret) |
| 5316 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5317 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5318 | /* Handle the case where the passed-in buffer is too short */ |
| 5319 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5320 | /* Did the user only issue a request for the acl length? */ |
| 5321 | if (buf == NULL) |
| 5322 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5323 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5324 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5325 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5326 | 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] | 5327 | if (buf) { |
| 5328 | if (res.acl_len > buflen) { |
| 5329 | ret = -ERANGE; |
| 5330 | goto out_free; |
| 5331 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5332 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5333 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5334 | out_ok: |
| 5335 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5336 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5337 | for (i = 0; i < npages; i++) |
| 5338 | if (pages[i]) |
| 5339 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5340 | if (res.acl_scratch) |
| 5341 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5342 | return ret; |
| 5343 | } |
| 5344 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5345 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5346 | { |
| 5347 | struct nfs4_exception exception = { }; |
| 5348 | ssize_t ret; |
| 5349 | do { |
| 5350 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5351 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5352 | if (ret >= 0) |
| 5353 | break; |
| 5354 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5355 | } while (exception.retry); |
| 5356 | return ret; |
| 5357 | } |
| 5358 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5359 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5360 | { |
| 5361 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5362 | int ret; |
| 5363 | |
| 5364 | if (!nfs4_server_supports_acls(server)) |
| 5365 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5366 | ret = nfs_revalidate_inode(server, inode); |
| 5367 | if (ret < 0) |
| 5368 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5369 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5370 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5371 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5372 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5373 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5374 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5375 | return ret; |
| 5376 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5379 | 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] | 5380 | { |
| 5381 | struct nfs_server *server = NFS_SERVER(inode); |
| 5382 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5383 | struct nfs_setaclargs arg = { |
| 5384 | .fh = NFS_FH(inode), |
| 5385 | .acl_pages = pages, |
| 5386 | .acl_len = buflen, |
| 5387 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5388 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5389 | struct rpc_message msg = { |
| 5390 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5391 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5392 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5393 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5394 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5395 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5396 | |
| 5397 | if (!nfs4_server_supports_acls(server)) |
| 5398 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5399 | if (npages > ARRAY_SIZE(pages)) |
| 5400 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5401 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5402 | if (i < 0) |
| 5403 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5404 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5405 | 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] | 5406 | |
| 5407 | /* |
| 5408 | * Free each page after tx, so the only ref left is |
| 5409 | * held by the network stack |
| 5410 | */ |
| 5411 | for (; i > 0; i--) |
| 5412 | put_page(pages[i-1]); |
| 5413 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5414 | /* |
| 5415 | * Acl update can result in inode attribute update. |
| 5416 | * so mark the attribute cache invalid. |
| 5417 | */ |
| 5418 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5419 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5420 | | NFS_INO_INVALID_CTIME |
| 5421 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5422 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5423 | nfs_access_zap_cache(inode); |
| 5424 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5425 | return ret; |
| 5426 | } |
| 5427 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5428 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5429 | { |
| 5430 | struct nfs4_exception exception = { }; |
| 5431 | int err; |
| 5432 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5433 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5434 | trace_nfs4_set_acl(inode, err); |
| 5435 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5436 | &exception); |
| 5437 | } while (exception.retry); |
| 5438 | return err; |
| 5439 | } |
| 5440 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5441 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5442 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5443 | size_t buflen) |
| 5444 | { |
| 5445 | struct nfs_server *server = NFS_SERVER(inode); |
| 5446 | struct nfs_fattr fattr; |
| 5447 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5448 | |
| 5449 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5450 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5451 | .fh = NFS_FH(inode), |
| 5452 | .bitmask = bitmask, |
| 5453 | }; |
| 5454 | struct nfs4_getattr_res res = { |
| 5455 | .fattr = &fattr, |
| 5456 | .label = &label, |
| 5457 | .server = server, |
| 5458 | }; |
| 5459 | struct rpc_message msg = { |
| 5460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5461 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5462 | .rpc_resp = &res, |
| 5463 | }; |
| 5464 | int ret; |
| 5465 | |
| 5466 | nfs_fattr_init(&fattr); |
| 5467 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5468 | 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] | 5469 | if (ret) |
| 5470 | return ret; |
| 5471 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5472 | return -ENOENT; |
| 5473 | if (buflen < label.len) |
| 5474 | return -ERANGE; |
| 5475 | return 0; |
| 5476 | } |
| 5477 | |
| 5478 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5479 | size_t buflen) |
| 5480 | { |
| 5481 | struct nfs4_exception exception = { }; |
| 5482 | int err; |
| 5483 | |
| 5484 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5485 | return -EOPNOTSUPP; |
| 5486 | |
| 5487 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5488 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5489 | trace_nfs4_get_security_label(inode, err); |
| 5490 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5491 | &exception); |
| 5492 | } while (exception.retry); |
| 5493 | return err; |
| 5494 | } |
| 5495 | |
| 5496 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5497 | struct nfs4_label *ilabel, |
| 5498 | struct nfs_fattr *fattr, |
| 5499 | struct nfs4_label *olabel) |
| 5500 | { |
| 5501 | |
| 5502 | struct iattr sattr = {0}; |
| 5503 | struct nfs_server *server = NFS_SERVER(inode); |
| 5504 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5505 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5506 | .fh = NFS_FH(inode), |
| 5507 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5508 | .server = server, |
| 5509 | .bitmask = bitmask, |
| 5510 | .label = ilabel, |
| 5511 | }; |
| 5512 | struct nfs_setattrres res = { |
| 5513 | .fattr = fattr, |
| 5514 | .label = olabel, |
| 5515 | .server = server, |
| 5516 | }; |
| 5517 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5518 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5519 | .rpc_argp = &arg, |
| 5520 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5521 | }; |
| 5522 | int status; |
| 5523 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5524 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5525 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5526 | 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] | 5527 | if (status) |
| 5528 | dprintk("%s failed: %d\n", __func__, status); |
| 5529 | |
| 5530 | return status; |
| 5531 | } |
| 5532 | |
| 5533 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5534 | struct nfs4_label *ilabel, |
| 5535 | struct nfs_fattr *fattr, |
| 5536 | struct nfs4_label *olabel) |
| 5537 | { |
| 5538 | struct nfs4_exception exception = { }; |
| 5539 | int err; |
| 5540 | |
| 5541 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5542 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5543 | fattr, olabel); |
| 5544 | trace_nfs4_set_security_label(inode, err); |
| 5545 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5546 | &exception); |
| 5547 | } while (exception.retry); |
| 5548 | return err; |
| 5549 | } |
| 5550 | |
| 5551 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5552 | 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] | 5553 | { |
| 5554 | struct nfs4_label ilabel, *olabel = NULL; |
| 5555 | struct nfs_fattr fattr; |
| 5556 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5557 | int status; |
| 5558 | |
| 5559 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5560 | return -EOPNOTSUPP; |
| 5561 | |
| 5562 | nfs_fattr_init(&fattr); |
| 5563 | |
| 5564 | ilabel.pi = 0; |
| 5565 | ilabel.lfs = 0; |
| 5566 | ilabel.label = (char *)buf; |
| 5567 | ilabel.len = buflen; |
| 5568 | |
| 5569 | cred = rpc_lookup_cred(); |
| 5570 | if (IS_ERR(cred)) |
| 5571 | return PTR_ERR(cred); |
| 5572 | |
| 5573 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5574 | if (IS_ERR(olabel)) { |
| 5575 | status = -PTR_ERR(olabel); |
| 5576 | goto out; |
| 5577 | } |
| 5578 | |
| 5579 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5580 | if (status == 0) |
| 5581 | nfs_setsecurity(inode, &fattr, olabel); |
| 5582 | |
| 5583 | nfs4_label_free(olabel); |
| 5584 | out: |
| 5585 | put_rpccred(cred); |
| 5586 | return status; |
| 5587 | } |
| 5588 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5589 | |
| 5590 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5591 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5592 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5593 | { |
| 5594 | __be32 verf[2]; |
| 5595 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5596 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5597 | /* An impossible timestamp guarantees this value |
| 5598 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5599 | verf[0] = cpu_to_be32(U32_MAX); |
| 5600 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5601 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5602 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5603 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5604 | |
| 5605 | verf[0] = cpu_to_be32(ns >> 32); |
| 5606 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5607 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5608 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5609 | } |
| 5610 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5611 | static int |
| 5612 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5613 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5614 | size_t len; |
| 5615 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5616 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5617 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5618 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5619 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5620 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5621 | len = 14 + |
| 5622 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5623 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5624 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5625 | 1; |
| 5626 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5627 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5628 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5629 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5630 | return -EINVAL; |
| 5631 | |
| 5632 | /* |
| 5633 | * Since this string is allocated at mount time, and held until the |
| 5634 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5635 | * about a memory-reclaim deadlock. |
| 5636 | */ |
| 5637 | str = kmalloc(len, GFP_KERNEL); |
| 5638 | if (!str) |
| 5639 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5640 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5641 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5642 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame^] | 5643 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5644 | clp->cl_rpcclient->cl_nodename, |
| 5645 | nfs4_client_id_uniquifier, |
| 5646 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame^] | 5647 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5648 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame^] | 5649 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5650 | clp->cl_rpcclient->cl_nodename, |
| 5651 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame^] | 5652 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5653 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5654 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5655 | clp->cl_owner_id = str; |
| 5656 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5657 | } |
| 5658 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5659 | static int |
| 5660 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5661 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5662 | size_t len; |
| 5663 | char *str; |
| 5664 | |
| 5665 | len = 10 + 10 + 1 + 10 + 1 + |
| 5666 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5667 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5668 | |
| 5669 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5670 | return -EINVAL; |
| 5671 | |
| 5672 | /* |
| 5673 | * Since this string is allocated at mount time, and held until the |
| 5674 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5675 | * about a memory-reclaim deadlock. |
| 5676 | */ |
| 5677 | str = kmalloc(len, GFP_KERNEL); |
| 5678 | if (!str) |
| 5679 | return -ENOMEM; |
| 5680 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5681 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5682 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5683 | nfs4_client_id_uniquifier, |
| 5684 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5685 | clp->cl_owner_id = str; |
| 5686 | return 0; |
| 5687 | } |
| 5688 | |
| 5689 | static int |
| 5690 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5691 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5692 | size_t len; |
| 5693 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5694 | |
| 5695 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5696 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5697 | |
| 5698 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5699 | return nfs4_init_uniquifier_client_string(clp); |
| 5700 | |
| 5701 | len = 10 + 10 + 1 + 10 + 1 + |
| 5702 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5703 | |
| 5704 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5705 | return -EINVAL; |
| 5706 | |
| 5707 | /* |
| 5708 | * Since this string is allocated at mount time, and held until the |
| 5709 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5710 | * about a memory-reclaim deadlock. |
| 5711 | */ |
| 5712 | str = kmalloc(len, GFP_KERNEL); |
| 5713 | if (!str) |
| 5714 | return -ENOMEM; |
| 5715 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5716 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5717 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5718 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5719 | clp->cl_owner_id = str; |
| 5720 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5721 | } |
| 5722 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5723 | /* |
| 5724 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5725 | * services. Advertise one based on the address family of the |
| 5726 | * clientaddr. |
| 5727 | */ |
| 5728 | static unsigned int |
| 5729 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5730 | { |
| 5731 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5732 | return scnprintf(buf, len, "tcp6"); |
| 5733 | else |
| 5734 | return scnprintf(buf, len, "tcp"); |
| 5735 | } |
| 5736 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5737 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5738 | { |
| 5739 | struct nfs4_setclientid *sc = calldata; |
| 5740 | |
| 5741 | if (task->tk_status == 0) |
| 5742 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5743 | } |
| 5744 | |
| 5745 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5746 | .rpc_call_done = nfs4_setclientid_done, |
| 5747 | }; |
| 5748 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5749 | /** |
| 5750 | * nfs4_proc_setclientid - Negotiate client ID |
| 5751 | * @clp: state data structure |
| 5752 | * @program: RPC program for NFSv4 callback service |
| 5753 | * @port: IP port number for NFS4 callback service |
| 5754 | * @cred: RPC credential to use for this call |
| 5755 | * @res: where to place the result |
| 5756 | * |
| 5757 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5758 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5759 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5760 | unsigned short port, struct rpc_cred *cred, |
| 5761 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | { |
| 5763 | nfs4_verifier sc_verifier; |
| 5764 | struct nfs4_setclientid setclientid = { |
| 5765 | .sc_verifier = &sc_verifier, |
| 5766 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5767 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5768 | }; |
| 5769 | struct rpc_message msg = { |
| 5770 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5771 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5772 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5773 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5775 | struct rpc_task *task; |
| 5776 | struct rpc_task_setup task_setup_data = { |
| 5777 | .rpc_client = clp->cl_rpcclient, |
| 5778 | .rpc_message = &msg, |
| 5779 | .callback_ops = &nfs4_setclientid_ops, |
| 5780 | .callback_data = &setclientid, |
| 5781 | .flags = RPC_TASK_TIMEOUT, |
| 5782 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5783 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5785 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5786 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5787 | |
| 5788 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5789 | status = nfs4_init_uniform_client_string(clp); |
| 5790 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5791 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5792 | |
| 5793 | if (status) |
| 5794 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5795 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5796 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5797 | setclientid.sc_netid_len = |
| 5798 | nfs4_init_callback_netid(clp, |
| 5799 | setclientid.sc_netid, |
| 5800 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5801 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5802 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5804 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5805 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5806 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5807 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5808 | task = rpc_run_task(&task_setup_data); |
| 5809 | if (IS_ERR(task)) { |
| 5810 | status = PTR_ERR(task); |
| 5811 | goto out; |
| 5812 | } |
| 5813 | status = task->tk_status; |
| 5814 | if (setclientid.sc_cred) { |
| 5815 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5816 | put_rpccred(setclientid.sc_cred); |
| 5817 | } |
| 5818 | rpc_put_task(task); |
| 5819 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5820 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5821 | dprintk("NFS reply setclientid: %d\n", status); |
| 5822 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5825 | /** |
| 5826 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5827 | * @clp: state data structure |
| 5828 | * @res: result of a previous SETCLIENTID |
| 5829 | * @cred: RPC credential to use for this call |
| 5830 | * |
| 5831 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5832 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5833 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5834 | struct nfs4_setclientid_res *arg, |
| 5835 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | struct rpc_message msg = { |
| 5838 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5839 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5840 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | int status; |
| 5843 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5844 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5845 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5846 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5847 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5848 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5849 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | return status; |
| 5851 | } |
| 5852 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5853 | struct nfs4_delegreturndata { |
| 5854 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5855 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5856 | struct nfs_fh fh; |
| 5857 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5858 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5859 | struct { |
| 5860 | struct nfs4_layoutreturn_args arg; |
| 5861 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5862 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5863 | u32 roc_barrier; |
| 5864 | bool roc; |
| 5865 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5866 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5867 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5868 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5869 | }; |
| 5870 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5871 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5872 | { |
| 5873 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5874 | struct nfs4_exception exception = { |
| 5875 | .inode = data->inode, |
| 5876 | .stateid = &data->stateid, |
| 5877 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5878 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5879 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5880 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5881 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5882 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5883 | |
| 5884 | /* Handle Layoutreturn errors */ |
| 5885 | if (data->args.lr_args && task->tk_status != 0) { |
| 5886 | switch(data->res.lr_ret) { |
| 5887 | default: |
| 5888 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5889 | break; |
| 5890 | case 0: |
| 5891 | data->args.lr_args = NULL; |
| 5892 | data->res.lr_res = NULL; |
| 5893 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5894 | case -NFS4ERR_OLD_STATEID: |
| 5895 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5896 | data->inode)) |
| 5897 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5898 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5899 | case -NFS4ERR_ADMIN_REVOKED: |
| 5900 | case -NFS4ERR_DELEG_REVOKED: |
| 5901 | case -NFS4ERR_EXPIRED: |
| 5902 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5903 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5904 | case -NFS4ERR_WRONG_CRED: |
| 5905 | data->args.lr_args = NULL; |
| 5906 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5907 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5911 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5912 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5913 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5914 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5915 | case -NFS4ERR_ADMIN_REVOKED: |
| 5916 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5917 | case -NFS4ERR_EXPIRED: |
| 5918 | nfs4_free_revoked_stateid(data->res.server, |
| 5919 | data->args.stateid, |
| 5920 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5921 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5922 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5923 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5924 | task->tk_status = 0; |
| 5925 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5926 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5927 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 5928 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5929 | task->tk_status = 0; |
| 5930 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5931 | case -NFS4ERR_ACCESS: |
| 5932 | if (data->args.bitmask) { |
| 5933 | data->args.bitmask = NULL; |
| 5934 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5935 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5936 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5937 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5938 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5939 | task->tk_status = nfs4_async_handle_exception(task, |
| 5940 | data->res.server, task->tk_status, |
| 5941 | &exception); |
| 5942 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5943 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5944 | } |
| 5945 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5946 | return; |
| 5947 | lr_restart: |
| 5948 | data->res.lr_ret = 0; |
| 5949 | out_restart: |
| 5950 | task->tk_status = 0; |
| 5951 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | static void nfs4_delegreturn_release(void *calldata) |
| 5955 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5956 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5957 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5958 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5959 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5960 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5961 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5962 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5963 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5964 | nfs_iput_and_deactive(inode); |
| 5965 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5966 | kfree(calldata); |
| 5967 | } |
| 5968 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5969 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5970 | { |
| 5971 | struct nfs4_delegreturndata *d_data; |
| 5972 | |
| 5973 | d_data = (struct nfs4_delegreturndata *)data; |
| 5974 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5975 | 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] | 5976 | return; |
| 5977 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5978 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5979 | &d_data->args.seq_args, |
| 5980 | &d_data->res.seq_res, |
| 5981 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5982 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5983 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5984 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5985 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5986 | .rpc_call_done = nfs4_delegreturn_done, |
| 5987 | .rpc_release = nfs4_delegreturn_release, |
| 5988 | }; |
| 5989 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5990 | 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] | 5991 | { |
| 5992 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5993 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5994 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5995 | struct rpc_message msg = { |
| 5996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5997 | .rpc_cred = cred, |
| 5998 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5999 | struct rpc_task_setup task_setup_data = { |
| 6000 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6001 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6002 | .callback_ops = &nfs4_delegreturn_ops, |
| 6003 | .flags = RPC_TASK_ASYNC, |
| 6004 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6005 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6006 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6007 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6008 | if (data == NULL) |
| 6009 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6010 | 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] | 6011 | |
| 6012 | nfs4_state_protect(server->nfs_client, |
| 6013 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6014 | &task_setup_data.rpc_client, &msg); |
| 6015 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6016 | data->args.fhandle = &data->fh; |
| 6017 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6018 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6019 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6020 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6021 | data->res.fattr = &data->fattr; |
| 6022 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6023 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6024 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6025 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6026 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6027 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6028 | 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] | 6029 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6030 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6031 | if (data->lr.roc) { |
| 6032 | data->args.lr_args = &data->lr.arg; |
| 6033 | data->res.lr_res = &data->lr.res; |
| 6034 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6035 | } else if (data->lr.roc) { |
| 6036 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6037 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6038 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6039 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6040 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6041 | msg.rpc_argp = &data->args; |
| 6042 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6043 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6044 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6045 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6046 | if (!issync) |
| 6047 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6048 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6049 | if (status != 0) |
| 6050 | goto out; |
| 6051 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6052 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6053 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6054 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6055 | } |
| 6056 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6057 | 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] | 6058 | { |
| 6059 | struct nfs_server *server = NFS_SERVER(inode); |
| 6060 | struct nfs4_exception exception = { }; |
| 6061 | int err; |
| 6062 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6063 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6064 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6065 | switch (err) { |
| 6066 | case -NFS4ERR_STALE_STATEID: |
| 6067 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | case 0: |
| 6069 | return 0; |
| 6070 | } |
| 6071 | err = nfs4_handle_exception(server, err, &exception); |
| 6072 | } while (exception.retry); |
| 6073 | return err; |
| 6074 | } |
| 6075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6076 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6077 | { |
| 6078 | struct inode *inode = state->inode; |
| 6079 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6080 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6081 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6083 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6085 | struct nfs_lockt_res res = { |
| 6086 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | }; |
| 6088 | struct rpc_message msg = { |
| 6089 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6090 | .rpc_argp = &arg, |
| 6091 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6092 | .rpc_cred = state->owner->so_cred, |
| 6093 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6094 | struct nfs4_lock_state *lsp; |
| 6095 | int status; |
| 6096 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6097 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6098 | status = nfs4_set_lock_state(state, request); |
| 6099 | if (status != 0) |
| 6100 | goto out; |
| 6101 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6102 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6103 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6104 | 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] | 6105 | switch (status) { |
| 6106 | case 0: |
| 6107 | request->fl_type = F_UNLCK; |
| 6108 | break; |
| 6109 | case -NFS4ERR_DENIED: |
| 6110 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6112 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6113 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6114 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | return status; |
| 6116 | } |
| 6117 | |
| 6118 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6119 | { |
| 6120 | struct nfs4_exception exception = { }; |
| 6121 | int err; |
| 6122 | |
| 6123 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6124 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6125 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6126 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6127 | &exception); |
| 6128 | } while (exception.retry); |
| 6129 | return err; |
| 6130 | } |
| 6131 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6132 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6133 | struct nfs_locku_args arg; |
| 6134 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6135 | struct nfs4_lock_state *lsp; |
| 6136 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6137 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6138 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6139 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6140 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6141 | }; |
| 6142 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6143 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6144 | struct nfs_open_context *ctx, |
| 6145 | struct nfs4_lock_state *lsp, |
| 6146 | struct nfs_seqid *seqid) |
| 6147 | { |
| 6148 | struct nfs4_unlockdata *p; |
| 6149 | struct inode *inode = lsp->ls_state->inode; |
| 6150 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6151 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6152 | if (p == NULL) |
| 6153 | return NULL; |
| 6154 | p->arg.fh = NFS_FH(inode); |
| 6155 | p->arg.fl = &p->fl; |
| 6156 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6157 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6158 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6159 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6160 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6161 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6162 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6163 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6164 | p->server = NFS_SERVER(inode); |
| 6165 | return p; |
| 6166 | } |
| 6167 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6168 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6169 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6170 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6171 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6172 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6173 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6174 | put_nfs_open_context(calldata->ctx); |
| 6175 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6176 | } |
| 6177 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6178 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6179 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6180 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6181 | struct nfs4_exception exception = { |
| 6182 | .inode = calldata->lsp->ls_state->inode, |
| 6183 | .stateid = &calldata->arg.stateid, |
| 6184 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6185 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6186 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6187 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6188 | switch (task->tk_status) { |
| 6189 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6190 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6191 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6192 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6193 | &calldata->res.stateid)) |
| 6194 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6195 | case -NFS4ERR_ADMIN_REVOKED: |
| 6196 | case -NFS4ERR_EXPIRED: |
| 6197 | nfs4_free_revoked_stateid(calldata->server, |
| 6198 | &calldata->arg.stateid, |
| 6199 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6200 | case -NFS4ERR_BAD_STATEID: |
| 6201 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6202 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6203 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6204 | &calldata->lsp->ls_stateid)) |
| 6205 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6206 | break; |
| 6207 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6208 | task->tk_status = nfs4_async_handle_exception(task, |
| 6209 | calldata->server, task->tk_status, |
| 6210 | &exception); |
| 6211 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6212 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6213 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6214 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6215 | } |
| 6216 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6217 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6218 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6219 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6221 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6222 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6223 | return; |
| 6224 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6225 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6226 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6227 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6228 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6229 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6230 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6231 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6232 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6233 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6234 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6235 | &calldata->res.seq_res, |
| 6236 | task) != 0) |
| 6237 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6238 | return; |
| 6239 | out_no_action: |
| 6240 | task->tk_action = NULL; |
| 6241 | out_wait: |
| 6242 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6245 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6246 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6247 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6248 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6249 | }; |
| 6250 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6251 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6252 | struct nfs_open_context *ctx, |
| 6253 | struct nfs4_lock_state *lsp, |
| 6254 | struct nfs_seqid *seqid) |
| 6255 | { |
| 6256 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6257 | struct rpc_message msg = { |
| 6258 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6259 | .rpc_cred = ctx->cred, |
| 6260 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6261 | struct rpc_task_setup task_setup_data = { |
| 6262 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6263 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6264 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6265 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6266 | .flags = RPC_TASK_ASYNC, |
| 6267 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6268 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6269 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6270 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6271 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6272 | /* Ensure this is an unlock - when canceling a lock, the |
| 6273 | * canceled lock is passed in, and it won't be an unlock. |
| 6274 | */ |
| 6275 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6276 | if (fl->fl_flags & FL_CLOSE) |
| 6277 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6278 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6279 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6280 | if (data == NULL) { |
| 6281 | nfs_free_seqid(seqid); |
| 6282 | return ERR_PTR(-ENOMEM); |
| 6283 | } |
| 6284 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6285 | 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] | 6286 | msg.rpc_argp = &data->arg; |
| 6287 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6288 | task_setup_data.callback_data = data; |
| 6289 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6290 | } |
| 6291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6292 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6293 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6294 | struct inode *inode = state->inode; |
| 6295 | struct nfs4_state_owner *sp = state->owner; |
| 6296 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6297 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6298 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6299 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6300 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6301 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6302 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6304 | status = nfs4_set_lock_state(state, request); |
| 6305 | /* Unlock _before_ we do the RPC call */ |
| 6306 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6307 | /* Exclude nfs_delegation_claim_locks() */ |
| 6308 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6309 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6310 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6311 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6312 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6313 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6314 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6315 | } |
| 6316 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6317 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6318 | if (status != 0) |
| 6319 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6320 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6321 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6322 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6323 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6324 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6325 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6326 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6327 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6328 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6329 | 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] | 6330 | status = PTR_ERR(task); |
| 6331 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6332 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6333 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6334 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6335 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6336 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6337 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6338 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | } |
| 6340 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6341 | struct nfs4_lockdata { |
| 6342 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6343 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6344 | struct nfs4_lock_state *lsp; |
| 6345 | struct nfs_open_context *ctx; |
| 6346 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6347 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6348 | int rpc_status; |
| 6349 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6350 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6351 | }; |
| 6352 | |
| 6353 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6354 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6355 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6356 | { |
| 6357 | struct nfs4_lockdata *p; |
| 6358 | struct inode *inode = lsp->ls_state->inode; |
| 6359 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6360 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6361 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6362 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6363 | if (p == NULL) |
| 6364 | return NULL; |
| 6365 | |
| 6366 | p->arg.fh = NFS_FH(inode); |
| 6367 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6368 | 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] | 6369 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6370 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6371 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6372 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6373 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6374 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6375 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6376 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6377 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6378 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6379 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6380 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6381 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6382 | p->ctx = get_nfs_open_context(ctx); |
| 6383 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6384 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6385 | out_free_seqid: |
| 6386 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6387 | out_free: |
| 6388 | kfree(p); |
| 6389 | return NULL; |
| 6390 | } |
| 6391 | |
| 6392 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6393 | { |
| 6394 | struct nfs4_lockdata *data = calldata; |
| 6395 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6397 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6398 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6399 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6400 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6401 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6402 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6403 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6404 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6405 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6406 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6407 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6408 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6409 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6410 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6411 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6412 | &data->lsp->ls_stateid); |
| 6413 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6414 | if (!nfs4_valid_open_stateid(state)) { |
| 6415 | data->rpc_status = -EBADF; |
| 6416 | task->tk_action = NULL; |
| 6417 | goto out_release_open_seqid; |
| 6418 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6419 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6420 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6421 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6422 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6423 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6424 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6425 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6426 | nfs_release_seqid(data->arg.open_seqid); |
| 6427 | out_release_lock_seqid: |
| 6428 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6429 | out_wait: |
| 6430 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6431 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6432 | } |
| 6433 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6434 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6435 | { |
| 6436 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6437 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6438 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6439 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6440 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6441 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6442 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6443 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6444 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6445 | switch (task->tk_status) { |
| 6446 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6447 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6448 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6449 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6450 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6451 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6452 | break; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6453 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6454 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6455 | if (data->arg.new_lock_owner != 0) { |
| 6456 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6457 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6458 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6459 | goto out_done; |
| 6460 | } else if (nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6461 | goto out_done; |
| 6462 | |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6463 | break; |
| 6464 | case -NFS4ERR_BAD_STATEID: |
| 6465 | case -NFS4ERR_OLD_STATEID: |
| 6466 | case -NFS4ERR_STALE_STATEID: |
| 6467 | case -NFS4ERR_EXPIRED: |
| 6468 | if (data->arg.new_lock_owner != 0) { |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6469 | if (nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6470 | &lsp->ls_state->open_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6471 | goto out_done; |
| 6472 | } else if (nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6473 | &lsp->ls_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6474 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6475 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6476 | if (!data->cancelled) |
| 6477 | rpc_restart_call_prepare(task); |
| 6478 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6479 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | static void nfs4_lock_release(void *calldata) |
| 6483 | { |
| 6484 | struct nfs4_lockdata *data = calldata; |
| 6485 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6486 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6487 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6488 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6489 | struct rpc_task *task; |
| 6490 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6491 | data->arg.lock_seqid); |
| 6492 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6493 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6494 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6495 | } else |
| 6496 | nfs_free_seqid(data->arg.lock_seqid); |
| 6497 | nfs4_put_lock_state(data->lsp); |
| 6498 | put_nfs_open_context(data->ctx); |
| 6499 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6500 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6504 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6505 | .rpc_call_done = nfs4_lock_done, |
| 6506 | .rpc_release = nfs4_lock_release, |
| 6507 | }; |
| 6508 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6509 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6510 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6511 | switch (error) { |
| 6512 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6513 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6514 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6515 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6516 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6517 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6518 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6519 | break; |
| 6520 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6521 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6522 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6523 | }; |
| 6524 | } |
| 6525 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6526 | 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] | 6527 | { |
| 6528 | struct nfs4_lockdata *data; |
| 6529 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6530 | struct rpc_message msg = { |
| 6531 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6532 | .rpc_cred = state->owner->so_cred, |
| 6533 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6534 | struct rpc_task_setup task_setup_data = { |
| 6535 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6536 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6537 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6538 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6539 | .flags = RPC_TASK_ASYNC, |
| 6540 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6541 | int ret; |
| 6542 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6543 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6544 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6545 | fl->fl_u.nfs4_fl.owner, |
| 6546 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6547 | if (data == NULL) |
| 6548 | return -ENOMEM; |
| 6549 | if (IS_SETLKW(cmd)) |
| 6550 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6551 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6552 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6553 | msg.rpc_argp = &data->arg; |
| 6554 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6555 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6556 | if (recovery_type > NFS_LOCK_NEW) { |
| 6557 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6558 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6559 | } else |
| 6560 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6561 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6562 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6563 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6564 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6565 | if (ret == 0) { |
| 6566 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6567 | if (ret) |
| 6568 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6569 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6570 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6571 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6572 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6573 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6574 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6575 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6576 | } |
| 6577 | |
| 6578 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6579 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6580 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6581 | struct nfs4_exception exception = { |
| 6582 | .inode = state->inode, |
| 6583 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6584 | int err; |
| 6585 | |
| 6586 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6587 | /* Cache the lock if possible... */ |
| 6588 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6589 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6590 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6591 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6592 | break; |
| 6593 | nfs4_handle_exception(server, err, &exception); |
| 6594 | } while (exception.retry); |
| 6595 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6596 | } |
| 6597 | |
| 6598 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6599 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6600 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6601 | struct nfs4_exception exception = { |
| 6602 | .inode = state->inode, |
| 6603 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6604 | int err; |
| 6605 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6606 | err = nfs4_set_lock_state(state, request); |
| 6607 | if (err != 0) |
| 6608 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6609 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6610 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6611 | return 0; |
| 6612 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6613 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6614 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6615 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6616 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6617 | switch (err) { |
| 6618 | default: |
| 6619 | goto out; |
| 6620 | case -NFS4ERR_GRACE: |
| 6621 | case -NFS4ERR_DELAY: |
| 6622 | nfs4_handle_exception(server, err, &exception); |
| 6623 | err = 0; |
| 6624 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6625 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6626 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6627 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6628 | } |
| 6629 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6630 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6631 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6632 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6633 | struct nfs4_lock_state *lsp; |
| 6634 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6635 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6636 | status = nfs4_set_lock_state(state, request); |
| 6637 | if (status != 0) |
| 6638 | return status; |
| 6639 | lsp = request->fl_u.nfs4_fl.owner; |
| 6640 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6641 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6642 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6643 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6644 | } |
| 6645 | #endif |
| 6646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6647 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6648 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6649 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6650 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6651 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6652 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6653 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6654 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6655 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6656 | if (status < 0) |
| 6657 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6658 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6659 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6660 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6661 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6662 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6663 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6664 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6665 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6666 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6667 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6668 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6669 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6670 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6671 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6672 | out: |
| 6673 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6674 | return status; |
| 6675 | } |
| 6676 | |
| 6677 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6678 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6679 | struct nfs4_exception exception = { |
| 6680 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6681 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6682 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6683 | int err; |
| 6684 | |
| 6685 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6686 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6687 | if (err == -NFS4ERR_DENIED) |
| 6688 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6689 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6690 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6691 | } while (exception.retry); |
| 6692 | return err; |
| 6693 | } |
| 6694 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6695 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6696 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6697 | |
| 6698 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6699 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6700 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6701 | { |
| 6702 | int status = -ERESTARTSYS; |
| 6703 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6704 | |
| 6705 | while(!signalled()) { |
| 6706 | status = nfs4_proc_setlk(state, cmd, request); |
| 6707 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6708 | break; |
| 6709 | freezable_schedule_timeout_interruptible(timeout); |
| 6710 | timeout *= 2; |
| 6711 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6712 | status = -ERESTARTSYS; |
| 6713 | } |
| 6714 | return status; |
| 6715 | } |
| 6716 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6717 | #ifdef CONFIG_NFS_V4_1 |
| 6718 | struct nfs4_lock_waiter { |
| 6719 | struct task_struct *task; |
| 6720 | struct inode *inode; |
| 6721 | struct nfs_lowner *owner; |
| 6722 | bool notified; |
| 6723 | }; |
| 6724 | |
| 6725 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6726 | 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] | 6727 | { |
| 6728 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6729 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6730 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6731 | /* NULL key means to wake up everyone */ |
| 6732 | if (key) { |
| 6733 | struct cb_notify_lock_args *cbnl = key; |
| 6734 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6735 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6736 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6737 | /* Only wake if the callback was for the same owner. */ |
| 6738 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6739 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6740 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6741 | /* Make sure it's for the right inode */ |
| 6742 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6743 | return 0; |
| 6744 | |
| 6745 | waiter->notified = true; |
| 6746 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6747 | |
| 6748 | /* override "private" so we can use default_wake_function */ |
| 6749 | wait->private = waiter->task; |
| 6750 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6751 | wait->private = waiter; |
| 6752 | return ret; |
| 6753 | } |
| 6754 | |
| 6755 | static int |
| 6756 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6757 | { |
| 6758 | int status = -ERESTARTSYS; |
| 6759 | unsigned long flags; |
| 6760 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6761 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6762 | struct nfs_client *clp = server->nfs_client; |
| 6763 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6764 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6765 | .id = lsp->ls_seqid.owner_id, |
| 6766 | .s_dev = server->s_dev }; |
| 6767 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6768 | .inode = state->inode, |
| 6769 | .owner = &owner, |
| 6770 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6771 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6772 | |
| 6773 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6774 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6775 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6776 | |
| 6777 | init_wait(&wait); |
| 6778 | wait.private = &waiter; |
| 6779 | wait.func = nfs4_wake_lock_waiter; |
| 6780 | add_wait_queue(q, &wait); |
| 6781 | |
| 6782 | while(!signalled()) { |
Jeff Layton | 41a7462 | 2018-03-18 08:37:01 -0400 | [diff] [blame] | 6783 | waiter.notified = false; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6784 | status = nfs4_proc_setlk(state, cmd, request); |
| 6785 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6786 | break; |
| 6787 | |
| 6788 | status = -ERESTARTSYS; |
| 6789 | spin_lock_irqsave(&q->lock, flags); |
| 6790 | if (waiter.notified) { |
| 6791 | spin_unlock_irqrestore(&q->lock, flags); |
| 6792 | continue; |
| 6793 | } |
| 6794 | set_current_state(TASK_INTERRUPTIBLE); |
| 6795 | spin_unlock_irqrestore(&q->lock, flags); |
| 6796 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6797 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | finish_wait(q, &wait); |
| 6801 | return status; |
| 6802 | } |
| 6803 | #else /* !CONFIG_NFS_V4_1 */ |
| 6804 | static inline int |
| 6805 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6806 | { |
| 6807 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6808 | } |
| 6809 | #endif |
| 6810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6811 | static int |
| 6812 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6813 | { |
| 6814 | struct nfs_open_context *ctx; |
| 6815 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | int status; |
| 6817 | |
| 6818 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6819 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | state = ctx->state; |
| 6821 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6822 | if (IS_GETLK(cmd)) { |
| 6823 | if (state != NULL) |
| 6824 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6825 | return 0; |
| 6826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6827 | |
| 6828 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6829 | return -EINVAL; |
| 6830 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6831 | if (request->fl_type == F_UNLCK) { |
| 6832 | if (state != NULL) |
| 6833 | return nfs4_proc_unlck(state, cmd, request); |
| 6834 | return 0; |
| 6835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6837 | if (state == NULL) |
| 6838 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6839 | |
| 6840 | if ((request->fl_flags & FL_POSIX) && |
| 6841 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6842 | return -ENOLCK; |
| 6843 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6844 | /* |
| 6845 | * Don't rely on the VFS having checked the file open mode, |
| 6846 | * since it won't do this for flock() locks. |
| 6847 | */ |
| 6848 | switch (request->fl_type) { |
| 6849 | case F_RDLCK: |
| 6850 | if (!(filp->f_mode & FMODE_READ)) |
| 6851 | return -EBADF; |
| 6852 | break; |
| 6853 | case F_WRLCK: |
| 6854 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6855 | return -EBADF; |
| 6856 | } |
| 6857 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6858 | status = nfs4_set_lock_state(state, request); |
| 6859 | if (status != 0) |
| 6860 | return status; |
| 6861 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6862 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6863 | } |
| 6864 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6865 | 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] | 6866 | { |
| 6867 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6868 | int err; |
| 6869 | |
| 6870 | err = nfs4_set_lock_state(state, fl); |
| 6871 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6872 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6873 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 6874 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6875 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6876 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6877 | struct nfs_release_lockowner_data { |
| 6878 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6879 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6880 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6881 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6882 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6883 | }; |
| 6884 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6885 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6886 | { |
| 6887 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6888 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6889 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6890 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6891 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6892 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6896 | { |
| 6897 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6898 | struct nfs_server *server = data->server; |
| 6899 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6900 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6901 | |
| 6902 | switch (task->tk_status) { |
| 6903 | case 0: |
| 6904 | renew_lease(server, data->timestamp); |
| 6905 | break; |
| 6906 | case -NFS4ERR_STALE_CLIENTID: |
| 6907 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6908 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6909 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6910 | case -NFS4ERR_LEASE_MOVED: |
| 6911 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6912 | if (nfs4_async_handle_error(task, server, |
| 6913 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6914 | rpc_restart_call_prepare(task); |
| 6915 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6916 | } |
| 6917 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6918 | static void nfs4_release_lockowner_release(void *calldata) |
| 6919 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6920 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6921 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6922 | kfree(calldata); |
| 6923 | } |
| 6924 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6925 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6926 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6927 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6928 | .rpc_release = nfs4_release_lockowner_release, |
| 6929 | }; |
| 6930 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6931 | static void |
| 6932 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6933 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6934 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6935 | struct rpc_message msg = { |
| 6936 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6937 | }; |
| 6938 | |
| 6939 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6940 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6941 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6942 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6943 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6944 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6945 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6946 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6947 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6948 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6949 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6950 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6951 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6952 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6953 | 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] | 6954 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6955 | } |
| 6956 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6957 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6958 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6959 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6960 | struct dentry *unused, struct inode *inode, |
| 6961 | const char *key, const void *buf, |
| 6962 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6963 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6964 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6967 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6968 | struct dentry *unused, struct inode *inode, |
| 6969 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6970 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6971 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6972 | } |
| 6973 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6974 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6975 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6976 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6977 | } |
| 6978 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6979 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6980 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6981 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6982 | struct dentry *unused, struct inode *inode, |
| 6983 | const char *key, const void *buf, |
| 6984 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6985 | { |
| 6986 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6987 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6988 | |
| 6989 | return -EOPNOTSUPP; |
| 6990 | } |
| 6991 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6992 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6993 | struct dentry *unused, struct inode *inode, |
| 6994 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6995 | { |
| 6996 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6997 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6998 | return -EOPNOTSUPP; |
| 6999 | } |
| 7000 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7001 | static ssize_t |
| 7002 | 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] | 7003 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7004 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7005 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7006 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7007 | len = security_inode_listsecurity(inode, list, list_len); |
| 7008 | if (list_len && len > list_len) |
| 7009 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7010 | } |
| 7011 | return len; |
| 7012 | } |
| 7013 | |
| 7014 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7015 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7016 | .get = nfs4_xattr_get_nfs4_label, |
| 7017 | .set = nfs4_xattr_set_nfs4_label, |
| 7018 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7019 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7020 | #else |
| 7021 | |
| 7022 | static ssize_t |
| 7023 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7024 | { |
| 7025 | return 0; |
| 7026 | } |
| 7027 | |
| 7028 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7029 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7030 | /* |
| 7031 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7032 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7033 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7034 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7035 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7036 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7037 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7038 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7039 | return; |
| 7040 | |
| 7041 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7042 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7043 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7044 | fattr->nlink = 2; |
| 7045 | } |
| 7046 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7047 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7048 | const struct qstr *name, |
| 7049 | struct nfs4_fs_locations *fs_locations, |
| 7050 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7051 | { |
| 7052 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7053 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7054 | struct nfs4_fs_locations_arg args = { |
| 7055 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7056 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7057 | .page = page, |
| 7058 | .bitmask = bitmask, |
| 7059 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7060 | struct nfs4_fs_locations_res res = { |
| 7061 | .fs_locations = fs_locations, |
| 7062 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7063 | struct rpc_message msg = { |
| 7064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7065 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7066 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7067 | }; |
| 7068 | int status; |
| 7069 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7070 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7071 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7072 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7073 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7074 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7075 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7076 | * is not supported */ |
| 7077 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7078 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7079 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7080 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7081 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7082 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7083 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7084 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7085 | 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] | 7086 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7087 | return status; |
| 7088 | } |
| 7089 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7090 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7091 | const struct qstr *name, |
| 7092 | struct nfs4_fs_locations *fs_locations, |
| 7093 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7094 | { |
| 7095 | struct nfs4_exception exception = { }; |
| 7096 | int err; |
| 7097 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7098 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7099 | fs_locations, page); |
| 7100 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7101 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7102 | &exception); |
| 7103 | } while (exception.retry); |
| 7104 | return err; |
| 7105 | } |
| 7106 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7107 | /* |
| 7108 | * This operation also signals the server that this client is |
| 7109 | * performing migration recovery. The server can stop returning |
| 7110 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7111 | * appended to this compound to identify the client ID which is |
| 7112 | * performing recovery. |
| 7113 | */ |
| 7114 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7115 | struct nfs4_fs_locations *locations, |
| 7116 | struct page *page, struct rpc_cred *cred) |
| 7117 | { |
| 7118 | struct nfs_server *server = NFS_SERVER(inode); |
| 7119 | struct rpc_clnt *clnt = server->client; |
| 7120 | u32 bitmask[2] = { |
| 7121 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7122 | }; |
| 7123 | struct nfs4_fs_locations_arg args = { |
| 7124 | .clientid = server->nfs_client->cl_clientid, |
| 7125 | .fh = NFS_FH(inode), |
| 7126 | .page = page, |
| 7127 | .bitmask = bitmask, |
| 7128 | .migration = 1, /* skip LOOKUP */ |
| 7129 | .renew = 1, /* append RENEW */ |
| 7130 | }; |
| 7131 | struct nfs4_fs_locations_res res = { |
| 7132 | .fs_locations = locations, |
| 7133 | .migration = 1, |
| 7134 | .renew = 1, |
| 7135 | }; |
| 7136 | struct rpc_message msg = { |
| 7137 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7138 | .rpc_argp = &args, |
| 7139 | .rpc_resp = &res, |
| 7140 | .rpc_cred = cred, |
| 7141 | }; |
| 7142 | unsigned long now = jiffies; |
| 7143 | int status; |
| 7144 | |
| 7145 | nfs_fattr_init(&locations->fattr); |
| 7146 | locations->server = server; |
| 7147 | locations->nlocations = 0; |
| 7148 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7149 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7150 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7151 | &args.seq_args, &res.seq_res); |
| 7152 | if (status) |
| 7153 | return status; |
| 7154 | |
| 7155 | renew_lease(server, now); |
| 7156 | return 0; |
| 7157 | } |
| 7158 | |
| 7159 | #ifdef CONFIG_NFS_V4_1 |
| 7160 | |
| 7161 | /* |
| 7162 | * This operation also signals the server that this client is |
| 7163 | * performing migration recovery. The server can stop asserting |
| 7164 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7165 | * performing this operation is identified in the SEQUENCE |
| 7166 | * operation in this compound. |
| 7167 | * |
| 7168 | * When the client supports GETATTR(fs_locations_info), it can |
| 7169 | * be plumbed in here. |
| 7170 | */ |
| 7171 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7172 | struct nfs4_fs_locations *locations, |
| 7173 | struct page *page, struct rpc_cred *cred) |
| 7174 | { |
| 7175 | struct nfs_server *server = NFS_SERVER(inode); |
| 7176 | struct rpc_clnt *clnt = server->client; |
| 7177 | u32 bitmask[2] = { |
| 7178 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7179 | }; |
| 7180 | struct nfs4_fs_locations_arg args = { |
| 7181 | .fh = NFS_FH(inode), |
| 7182 | .page = page, |
| 7183 | .bitmask = bitmask, |
| 7184 | .migration = 1, /* skip LOOKUP */ |
| 7185 | }; |
| 7186 | struct nfs4_fs_locations_res res = { |
| 7187 | .fs_locations = locations, |
| 7188 | .migration = 1, |
| 7189 | }; |
| 7190 | struct rpc_message msg = { |
| 7191 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7192 | .rpc_argp = &args, |
| 7193 | .rpc_resp = &res, |
| 7194 | .rpc_cred = cred, |
| 7195 | }; |
| 7196 | int status; |
| 7197 | |
| 7198 | nfs_fattr_init(&locations->fattr); |
| 7199 | locations->server = server; |
| 7200 | locations->nlocations = 0; |
| 7201 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7202 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7203 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7204 | &args.seq_args, &res.seq_res); |
| 7205 | if (status == NFS4_OK && |
| 7206 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7207 | status = -NFS4ERR_LEASE_MOVED; |
| 7208 | return status; |
| 7209 | } |
| 7210 | |
| 7211 | #endif /* CONFIG_NFS_V4_1 */ |
| 7212 | |
| 7213 | /** |
| 7214 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7215 | * @inode: inode on FSID that is migrating |
| 7216 | * @locations: result of query |
| 7217 | * @page: buffer |
| 7218 | * @cred: credential to use for this operation |
| 7219 | * |
| 7220 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7221 | * operation failed, or a negative errno if a local error occurred. |
| 7222 | * |
| 7223 | * On success, "locations" is filled in, but if the server has |
| 7224 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7225 | * asserted. |
| 7226 | * |
| 7227 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7228 | * from this client that require migration recovery. |
| 7229 | */ |
| 7230 | int nfs4_proc_get_locations(struct inode *inode, |
| 7231 | struct nfs4_fs_locations *locations, |
| 7232 | struct page *page, struct rpc_cred *cred) |
| 7233 | { |
| 7234 | struct nfs_server *server = NFS_SERVER(inode); |
| 7235 | struct nfs_client *clp = server->nfs_client; |
| 7236 | const struct nfs4_mig_recovery_ops *ops = |
| 7237 | clp->cl_mvops->mig_recovery_ops; |
| 7238 | struct nfs4_exception exception = { }; |
| 7239 | int status; |
| 7240 | |
| 7241 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7242 | (unsigned long long)server->fsid.major, |
| 7243 | (unsigned long long)server->fsid.minor, |
| 7244 | clp->cl_hostname); |
| 7245 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7246 | |
| 7247 | do { |
| 7248 | status = ops->get_locations(inode, locations, page, cred); |
| 7249 | if (status != -NFS4ERR_DELAY) |
| 7250 | break; |
| 7251 | nfs4_handle_exception(server, status, &exception); |
| 7252 | } while (exception.retry); |
| 7253 | return status; |
| 7254 | } |
| 7255 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7256 | /* |
| 7257 | * This operation also signals the server that this client is |
| 7258 | * performing "lease moved" recovery. The server can stop |
| 7259 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7260 | * is appended to this compound to identify the client ID which is |
| 7261 | * performing recovery. |
| 7262 | */ |
| 7263 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7264 | { |
| 7265 | struct nfs_server *server = NFS_SERVER(inode); |
| 7266 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7267 | struct rpc_clnt *clnt = server->client; |
| 7268 | struct nfs4_fsid_present_arg args = { |
| 7269 | .fh = NFS_FH(inode), |
| 7270 | .clientid = clp->cl_clientid, |
| 7271 | .renew = 1, /* append RENEW */ |
| 7272 | }; |
| 7273 | struct nfs4_fsid_present_res res = { |
| 7274 | .renew = 1, |
| 7275 | }; |
| 7276 | struct rpc_message msg = { |
| 7277 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7278 | .rpc_argp = &args, |
| 7279 | .rpc_resp = &res, |
| 7280 | .rpc_cred = cred, |
| 7281 | }; |
| 7282 | unsigned long now = jiffies; |
| 7283 | int status; |
| 7284 | |
| 7285 | res.fh = nfs_alloc_fhandle(); |
| 7286 | if (res.fh == NULL) |
| 7287 | return -ENOMEM; |
| 7288 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7289 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7290 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7291 | &args.seq_args, &res.seq_res); |
| 7292 | nfs_free_fhandle(res.fh); |
| 7293 | if (status) |
| 7294 | return status; |
| 7295 | |
| 7296 | do_renew_lease(clp, now); |
| 7297 | return 0; |
| 7298 | } |
| 7299 | |
| 7300 | #ifdef CONFIG_NFS_V4_1 |
| 7301 | |
| 7302 | /* |
| 7303 | * This operation also signals the server that this client is |
| 7304 | * performing "lease moved" recovery. The server can stop asserting |
| 7305 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7306 | * this operation is identified in the SEQUENCE operation in this |
| 7307 | * compound. |
| 7308 | */ |
| 7309 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7310 | { |
| 7311 | struct nfs_server *server = NFS_SERVER(inode); |
| 7312 | struct rpc_clnt *clnt = server->client; |
| 7313 | struct nfs4_fsid_present_arg args = { |
| 7314 | .fh = NFS_FH(inode), |
| 7315 | }; |
| 7316 | struct nfs4_fsid_present_res res = { |
| 7317 | }; |
| 7318 | struct rpc_message msg = { |
| 7319 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7320 | .rpc_argp = &args, |
| 7321 | .rpc_resp = &res, |
| 7322 | .rpc_cred = cred, |
| 7323 | }; |
| 7324 | int status; |
| 7325 | |
| 7326 | res.fh = nfs_alloc_fhandle(); |
| 7327 | if (res.fh == NULL) |
| 7328 | return -ENOMEM; |
| 7329 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7330 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7331 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7332 | &args.seq_args, &res.seq_res); |
| 7333 | nfs_free_fhandle(res.fh); |
| 7334 | if (status == NFS4_OK && |
| 7335 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7336 | status = -NFS4ERR_LEASE_MOVED; |
| 7337 | return status; |
| 7338 | } |
| 7339 | |
| 7340 | #endif /* CONFIG_NFS_V4_1 */ |
| 7341 | |
| 7342 | /** |
| 7343 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7344 | * @inode: inode on FSID to check |
| 7345 | * @cred: credential to use for this operation |
| 7346 | * |
| 7347 | * Server indicates whether the FSID is present, moved, or not |
| 7348 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7349 | * condition for this client ID. |
| 7350 | * |
| 7351 | * Returns NFS4_OK if the FSID is present on this server, |
| 7352 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7353 | * NFS4ERR code if some error occurred on the server, or a |
| 7354 | * negative errno if a local failure occurred. |
| 7355 | */ |
| 7356 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7357 | { |
| 7358 | struct nfs_server *server = NFS_SERVER(inode); |
| 7359 | struct nfs_client *clp = server->nfs_client; |
| 7360 | const struct nfs4_mig_recovery_ops *ops = |
| 7361 | clp->cl_mvops->mig_recovery_ops; |
| 7362 | struct nfs4_exception exception = { }; |
| 7363 | int status; |
| 7364 | |
| 7365 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7366 | (unsigned long long)server->fsid.major, |
| 7367 | (unsigned long long)server->fsid.minor, |
| 7368 | clp->cl_hostname); |
| 7369 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7370 | |
| 7371 | do { |
| 7372 | status = ops->fsid_present(inode, cred); |
| 7373 | if (status != -NFS4ERR_DELAY) |
| 7374 | break; |
| 7375 | nfs4_handle_exception(server, status, &exception); |
| 7376 | } while (exception.retry); |
| 7377 | return status; |
| 7378 | } |
| 7379 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7380 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7381 | * If 'use_integrity' is true and the state managment nfs_client |
| 7382 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7383 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7384 | * Considerations sections. Otherwise, just use the user cred with the |
| 7385 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7386 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7387 | 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] | 7388 | { |
| 7389 | int status; |
| 7390 | struct nfs4_secinfo_arg args = { |
| 7391 | .dir_fh = NFS_FH(dir), |
| 7392 | .name = name, |
| 7393 | }; |
| 7394 | struct nfs4_secinfo_res res = { |
| 7395 | .flavors = flavors, |
| 7396 | }; |
| 7397 | struct rpc_message msg = { |
| 7398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7399 | .rpc_argp = &args, |
| 7400 | .rpc_resp = &res, |
| 7401 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7402 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7403 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7404 | |
| 7405 | if (use_integrity) { |
| 7406 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7407 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7408 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7409 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7410 | |
| 7411 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7412 | |
| 7413 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7414 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7415 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7416 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7417 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7418 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7419 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7420 | if (cred) |
| 7421 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7422 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7423 | return status; |
| 7424 | } |
| 7425 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7426 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7427 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7428 | { |
| 7429 | struct nfs4_exception exception = { }; |
| 7430 | int err; |
| 7431 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7432 | err = -NFS4ERR_WRONGSEC; |
| 7433 | |
| 7434 | /* try to use integrity protection with machine cred */ |
| 7435 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7436 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7437 | |
| 7438 | /* |
| 7439 | * if unable to use integrity protection, or SECINFO with |
| 7440 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7441 | * disallowed by spec, but exists in deployed servers) use |
| 7442 | * the current filesystem's rpc_client and the user cred. |
| 7443 | */ |
| 7444 | if (err == -NFS4ERR_WRONGSEC) |
| 7445 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7446 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7447 | trace_nfs4_secinfo(dir, name, err); |
| 7448 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7449 | &exception); |
| 7450 | } while (exception.retry); |
| 7451 | return err; |
| 7452 | } |
| 7453 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7454 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7455 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7456 | * Check the exchange flags returned by the server for invalid flags, having |
| 7457 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7458 | * DS flags set. |
| 7459 | */ |
| 7460 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7461 | { |
| 7462 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7463 | goto out_inval; |
| 7464 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7465 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7466 | goto out_inval; |
| 7467 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7468 | goto out_inval; |
| 7469 | return NFS_OK; |
| 7470 | out_inval: |
| 7471 | return -NFS4ERR_INVAL; |
| 7472 | } |
| 7473 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7474 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7475 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7476 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7477 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7478 | if (a->server_scope_sz != b->server_scope_sz) |
| 7479 | return false; |
| 7480 | 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] | 7481 | } |
| 7482 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7483 | static void |
| 7484 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7485 | { |
| 7486 | } |
| 7487 | |
| 7488 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7489 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7490 | }; |
| 7491 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7492 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7493 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7494 | * |
| 7495 | * The 4.1 client currently uses the same TCP connection for the |
| 7496 | * fore and backchannel. |
| 7497 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7498 | static |
| 7499 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7500 | struct rpc_xprt *xprt, |
| 7501 | struct nfs_client *clp, |
| 7502 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7503 | { |
| 7504 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7505 | struct nfs41_bind_conn_to_session_args args = { |
| 7506 | .client = clp, |
| 7507 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7508 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7509 | struct nfs41_bind_conn_to_session_res res; |
| 7510 | struct rpc_message msg = { |
| 7511 | .rpc_proc = |
| 7512 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7513 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7514 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7515 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7516 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7517 | struct rpc_task_setup task_setup_data = { |
| 7518 | .rpc_client = clnt, |
| 7519 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7520 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7521 | .rpc_message = &msg, |
| 7522 | .flags = RPC_TASK_TIMEOUT, |
| 7523 | }; |
| 7524 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7525 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7526 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7527 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7528 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7529 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7530 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7531 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7532 | args.dir = NFS4_CDFC4_FORE; |
| 7533 | |
| 7534 | task = rpc_run_task(&task_setup_data); |
| 7535 | if (!IS_ERR(task)) { |
| 7536 | status = task->tk_status; |
| 7537 | rpc_put_task(task); |
| 7538 | } else |
| 7539 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7540 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7541 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7542 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7543 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7544 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7545 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7546 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7547 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7548 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7549 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7550 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7551 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7552 | 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] | 7553 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7554 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7555 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7556 | } |
| 7557 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7558 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7559 | return status; |
| 7560 | } |
| 7561 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7562 | struct rpc_bind_conn_calldata { |
| 7563 | struct nfs_client *clp; |
| 7564 | struct rpc_cred *cred; |
| 7565 | }; |
| 7566 | |
| 7567 | static int |
| 7568 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7569 | struct rpc_xprt *xprt, |
| 7570 | void *calldata) |
| 7571 | { |
| 7572 | struct rpc_bind_conn_calldata *p = calldata; |
| 7573 | |
| 7574 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7575 | } |
| 7576 | |
| 7577 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7578 | { |
| 7579 | struct rpc_bind_conn_calldata data = { |
| 7580 | .clp = clp, |
| 7581 | .cred = cred, |
| 7582 | }; |
| 7583 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7584 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7585 | } |
| 7586 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7587 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7588 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7589 | * 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] | 7590 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7591 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7592 | .how = SP4_MACH_CRED, |
| 7593 | .enforce.u.words = { |
| 7594 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7595 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7596 | 1 << (OP_CREATE_SESSION - 32) | |
| 7597 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7598 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7599 | }, |
| 7600 | .allow.u.words = { |
| 7601 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7602 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7603 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7604 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7605 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7606 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7607 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7608 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7609 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7610 | 1 << (OP_FREE_STATEID - 32) | |
| 7611 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7612 | } |
| 7613 | }; |
| 7614 | |
| 7615 | /* |
| 7616 | * Select the state protection mode for client `clp' given the server results |
| 7617 | * from exchange_id in `sp'. |
| 7618 | * |
| 7619 | * Returns 0 on success, negative errno otherwise. |
| 7620 | */ |
| 7621 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7622 | struct nfs41_state_protection *sp) |
| 7623 | { |
| 7624 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7625 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7626 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7627 | 1 << (OP_CREATE_SESSION - 32) | |
| 7628 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7629 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7630 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7631 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7632 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7633 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7634 | |
| 7635 | if (sp->how == SP4_MACH_CRED) { |
| 7636 | /* Print state protect result */ |
| 7637 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7638 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7639 | if (test_bit(i, sp->enforce.u.longs)) |
| 7640 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7641 | if (test_bit(i, sp->allow.u.longs)) |
| 7642 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7643 | } |
| 7644 | |
| 7645 | /* make sure nothing is on enforce list that isn't supported */ |
| 7646 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7647 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7648 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7649 | ret = -EINVAL; |
| 7650 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7651 | } |
| 7652 | } |
| 7653 | |
| 7654 | /* |
| 7655 | * Minimal mode - state operations are allowed to use machine |
| 7656 | * credential. Note this already happens by default, so the |
| 7657 | * client doesn't have to do anything more than the negotiation. |
| 7658 | * |
| 7659 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7660 | * we're already using the machine cred for exchange_id |
| 7661 | * and will never use a different cred. |
| 7662 | */ |
| 7663 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7664 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7665 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7666 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7667 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7668 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7669 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7670 | } else { |
| 7671 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7672 | ret = -EINVAL; |
| 7673 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7674 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7675 | |
| 7676 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7677 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7678 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7679 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7680 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7681 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7682 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7683 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7684 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7685 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7686 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7687 | } |
| 7688 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7689 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7690 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7691 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7692 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7693 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7694 | |
| 7695 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7696 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7697 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7698 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7699 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7700 | |
| 7701 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7702 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7703 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7704 | } |
| 7705 | |
| 7706 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7707 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7708 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7709 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7710 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7711 | out: |
| 7712 | clp->cl_sp4_flags = flags; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7713 | return 0; |
| 7714 | } |
| 7715 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7716 | struct nfs41_exchange_id_data { |
| 7717 | struct nfs41_exchange_id_res res; |
| 7718 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7719 | }; |
| 7720 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7721 | static void nfs4_exchange_id_release(void *data) |
| 7722 | { |
| 7723 | struct nfs41_exchange_id_data *cdata = |
| 7724 | (struct nfs41_exchange_id_data *)data; |
| 7725 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7726 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7727 | kfree(cdata->res.impl_id); |
| 7728 | kfree(cdata->res.server_scope); |
| 7729 | kfree(cdata->res.server_owner); |
| 7730 | kfree(cdata); |
| 7731 | } |
| 7732 | |
| 7733 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7734 | .rpc_release = nfs4_exchange_id_release, |
| 7735 | }; |
| 7736 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7737 | /* |
| 7738 | * _nfs4_proc_exchange_id() |
| 7739 | * |
| 7740 | * Wrapper for EXCHANGE_ID operation. |
| 7741 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7742 | static struct rpc_task * |
| 7743 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7744 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7745 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7746 | struct rpc_message msg = { |
| 7747 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7748 | .rpc_cred = cred, |
| 7749 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7750 | struct rpc_task_setup task_setup_data = { |
| 7751 | .rpc_client = clp->cl_rpcclient, |
| 7752 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7753 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7754 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7755 | }; |
| 7756 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7757 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7758 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7759 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7760 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7761 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7762 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7763 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7764 | if (!calldata) |
| 7765 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7766 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7767 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7768 | |
| 7769 | status = nfs4_init_uniform_client_string(clp); |
| 7770 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7771 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7772 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7773 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7774 | GFP_NOFS); |
| 7775 | status = -ENOMEM; |
| 7776 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7777 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7778 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7779 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7780 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7781 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7782 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7783 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7784 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7785 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7786 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7787 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7788 | switch (sp4_how) { |
| 7789 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7790 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7791 | break; |
| 7792 | |
| 7793 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7794 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7795 | break; |
| 7796 | |
| 7797 | default: |
| 7798 | /* unsupported! */ |
| 7799 | WARN_ON_ONCE(1); |
| 7800 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7801 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7802 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7803 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7804 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7805 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7806 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7807 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7808 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7809 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7810 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7811 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7812 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7813 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7814 | #endif |
| 7815 | msg.rpc_argp = &calldata->args; |
| 7816 | msg.rpc_resp = &calldata->res; |
| 7817 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7818 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7819 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7820 | |
| 7821 | out_impl_id: |
| 7822 | kfree(calldata->res.impl_id); |
| 7823 | out_server_scope: |
| 7824 | kfree(calldata->res.server_scope); |
| 7825 | out_server_owner: |
| 7826 | kfree(calldata->res.server_owner); |
| 7827 | out_calldata: |
| 7828 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7829 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7830 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7831 | return ERR_PTR(status); |
| 7832 | } |
| 7833 | |
| 7834 | /* |
| 7835 | * _nfs4_proc_exchange_id() |
| 7836 | * |
| 7837 | * Wrapper for EXCHANGE_ID operation. |
| 7838 | */ |
| 7839 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7840 | u32 sp4_how) |
| 7841 | { |
| 7842 | struct rpc_task *task; |
| 7843 | struct nfs41_exchange_id_args *argp; |
| 7844 | struct nfs41_exchange_id_res *resp; |
| 7845 | int status; |
| 7846 | |
| 7847 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7848 | if (IS_ERR(task)) |
| 7849 | return PTR_ERR(task); |
| 7850 | |
| 7851 | argp = task->tk_msg.rpc_argp; |
| 7852 | resp = task->tk_msg.rpc_resp; |
| 7853 | status = task->tk_status; |
| 7854 | if (status != 0) |
| 7855 | goto out; |
| 7856 | |
| 7857 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7858 | if (status != 0) |
| 7859 | goto out; |
| 7860 | |
| 7861 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7862 | if (status != 0) |
| 7863 | goto out; |
| 7864 | |
| 7865 | clp->cl_clientid = resp->clientid; |
| 7866 | clp->cl_exchange_flags = resp->flags; |
| 7867 | clp->cl_seqid = resp->seqid; |
| 7868 | /* Client ID is not confirmed */ |
| 7869 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7870 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7871 | &clp->cl_session->session_state); |
| 7872 | |
| 7873 | if (clp->cl_serverscope != NULL && |
| 7874 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7875 | resp->server_scope)) { |
| 7876 | dprintk("%s: server_scope mismatch detected\n", |
| 7877 | __func__); |
| 7878 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7879 | } |
| 7880 | |
| 7881 | swap(clp->cl_serverowner, resp->server_owner); |
| 7882 | swap(clp->cl_serverscope, resp->server_scope); |
| 7883 | swap(clp->cl_implid, resp->impl_id); |
| 7884 | |
| 7885 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7886 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 7887 | sizeof(clp->cl_confirm.data)); |
| 7888 | out: |
| 7889 | trace_nfs4_exchange_id(clp, status); |
| 7890 | rpc_put_task(task); |
| 7891 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7892 | } |
| 7893 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7894 | /* |
| 7895 | * nfs4_proc_exchange_id() |
| 7896 | * |
| 7897 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7898 | * |
| 7899 | * Since the clientid has expired, all compounds using sessions |
| 7900 | * associated with the stale clientid will be returning |
| 7901 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7902 | * be in some phase of session reset. |
| 7903 | * |
| 7904 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7905 | */ |
| 7906 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7907 | { |
| 7908 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7909 | int status; |
| 7910 | |
| 7911 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7912 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7913 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7914 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7915 | if (!status) |
| 7916 | return 0; |
| 7917 | } |
| 7918 | |
| 7919 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7920 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7921 | } |
| 7922 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7923 | /** |
| 7924 | * nfs4_test_session_trunk |
| 7925 | * |
| 7926 | * This is an add_xprt_test() test function called from |
| 7927 | * rpc_clnt_setup_test_and_add_xprt. |
| 7928 | * |
| 7929 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7930 | * and is dereferrenced in nfs4_exchange_id_release |
| 7931 | * |
| 7932 | * Upon success, add the new transport to the rpc_clnt |
| 7933 | * |
| 7934 | * @clnt: struct rpc_clnt to get new transport |
| 7935 | * @xprt: the rpc_xprt to test |
| 7936 | * @data: call data for _nfs4_proc_exchange_id. |
| 7937 | */ |
| 7938 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7939 | void *data) |
| 7940 | { |
| 7941 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7942 | struct rpc_task *task; |
| 7943 | int status; |
| 7944 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7945 | u32 sp4_how; |
| 7946 | |
| 7947 | dprintk("--> %s try %s\n", __func__, |
| 7948 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7949 | |
| 7950 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7951 | |
| 7952 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7953 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7954 | if (IS_ERR(task)) |
| 7955 | return PTR_ERR(task); |
| 7956 | |
| 7957 | status = task->tk_status; |
| 7958 | if (status == 0) |
| 7959 | status = nfs4_detect_session_trunking(adata->clp, |
| 7960 | task->tk_msg.rpc_resp, xprt); |
| 7961 | |
| 7962 | rpc_put_task(task); |
| 7963 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7964 | } |
| 7965 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7966 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7967 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7968 | struct rpc_cred *cred) |
| 7969 | { |
| 7970 | struct rpc_message msg = { |
| 7971 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7972 | .rpc_argp = clp, |
| 7973 | .rpc_cred = cred, |
| 7974 | }; |
| 7975 | int status; |
| 7976 | |
| 7977 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7978 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7979 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7980 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7981 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7982 | return status; |
| 7983 | } |
| 7984 | |
| 7985 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7986 | struct rpc_cred *cred) |
| 7987 | { |
| 7988 | unsigned int loop; |
| 7989 | int ret; |
| 7990 | |
| 7991 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7992 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7993 | switch (ret) { |
| 7994 | case -NFS4ERR_DELAY: |
| 7995 | case -NFS4ERR_CLIENTID_BUSY: |
| 7996 | ssleep(1); |
| 7997 | break; |
| 7998 | default: |
| 7999 | return ret; |
| 8000 | } |
| 8001 | } |
| 8002 | return 0; |
| 8003 | } |
| 8004 | |
| 8005 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8006 | { |
| 8007 | struct rpc_cred *cred; |
| 8008 | int ret = 0; |
| 8009 | |
| 8010 | if (clp->cl_mvops->minor_version < 1) |
| 8011 | goto out; |
| 8012 | if (clp->cl_exchange_flags == 0) |
| 8013 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8014 | if (clp->cl_preserve_clid) |
| 8015 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8016 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8017 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 8018 | if (cred) |
| 8019 | put_rpccred(cred); |
| 8020 | switch (ret) { |
| 8021 | case 0: |
| 8022 | case -NFS4ERR_STALE_CLIENTID: |
| 8023 | clp->cl_exchange_flags = 0; |
| 8024 | } |
| 8025 | out: |
| 8026 | return ret; |
| 8027 | } |
| 8028 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8029 | struct nfs4_get_lease_time_data { |
| 8030 | struct nfs4_get_lease_time_args *args; |
| 8031 | struct nfs4_get_lease_time_res *res; |
| 8032 | struct nfs_client *clp; |
| 8033 | }; |
| 8034 | |
| 8035 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8036 | void *calldata) |
| 8037 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8038 | struct nfs4_get_lease_time_data *data = |
| 8039 | (struct nfs4_get_lease_time_data *)calldata; |
| 8040 | |
| 8041 | dprintk("--> %s\n", __func__); |
| 8042 | /* just setup sequence, do not trigger session recovery |
| 8043 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8044 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8045 | &data->args->la_seq_args, |
| 8046 | &data->res->lr_seq_res, |
| 8047 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8048 | dprintk("<-- %s\n", __func__); |
| 8049 | } |
| 8050 | |
| 8051 | /* |
| 8052 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8053 | * from sequence operation or clientid errors. |
| 8054 | */ |
| 8055 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8056 | { |
| 8057 | struct nfs4_get_lease_time_data *data = |
| 8058 | (struct nfs4_get_lease_time_data *)calldata; |
| 8059 | |
| 8060 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8061 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 8062 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8063 | switch (task->tk_status) { |
| 8064 | case -NFS4ERR_DELAY: |
| 8065 | case -NFS4ERR_GRACE: |
| 8066 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8067 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8068 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8069 | /* fall through */ |
| 8070 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8071 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8072 | return; |
| 8073 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8074 | dprintk("<-- %s\n", __func__); |
| 8075 | } |
| 8076 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8077 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8078 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8079 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8080 | }; |
| 8081 | |
| 8082 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8083 | { |
| 8084 | struct rpc_task *task; |
| 8085 | struct nfs4_get_lease_time_args args; |
| 8086 | struct nfs4_get_lease_time_res res = { |
| 8087 | .lr_fsinfo = fsinfo, |
| 8088 | }; |
| 8089 | struct nfs4_get_lease_time_data data = { |
| 8090 | .args = &args, |
| 8091 | .res = &res, |
| 8092 | .clp = clp, |
| 8093 | }; |
| 8094 | struct rpc_message msg = { |
| 8095 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8096 | .rpc_argp = &args, |
| 8097 | .rpc_resp = &res, |
| 8098 | }; |
| 8099 | struct rpc_task_setup task_setup = { |
| 8100 | .rpc_client = clp->cl_rpcclient, |
| 8101 | .rpc_message = &msg, |
| 8102 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8103 | .callback_data = &data, |
| 8104 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8105 | }; |
| 8106 | int status; |
| 8107 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8108 | 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] | 8109 | task = rpc_run_task(&task_setup); |
| 8110 | |
| 8111 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8112 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8113 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8114 | status = task->tk_status; |
| 8115 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8116 | return status; |
| 8117 | } |
| 8118 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8119 | /* |
| 8120 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8121 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8122 | * use them. |
| 8123 | * |
| 8124 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8125 | * always set csa_cachethis to FALSE because the current implementation |
| 8126 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8127 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8128 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8129 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8130 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8131 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8132 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8133 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8134 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8135 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8136 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8137 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8138 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8139 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8140 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8141 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8142 | |
| 8143 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8144 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8145 | __func__, |
| 8146 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8147 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8148 | |
| 8149 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8150 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8151 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8152 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8153 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8154 | args->bc_attrs.max_reqs = min_t(unsigned short, max_session_cb_slots, 1); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8155 | |
| 8156 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8157 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8158 | __func__, |
| 8159 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8160 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8161 | args->bc_attrs.max_reqs); |
| 8162 | } |
| 8163 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8164 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8165 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8166 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8167 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8168 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8169 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8170 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8171 | return -EINVAL; |
| 8172 | /* |
| 8173 | * Our requested max_ops is the minimum we need; we're not |
| 8174 | * prepared to break up compounds into smaller pieces than that. |
| 8175 | * So, no point even trying to continue if the server won't |
| 8176 | * cooperate: |
| 8177 | */ |
| 8178 | if (rcvd->max_ops < sent->max_ops) |
| 8179 | return -EINVAL; |
| 8180 | if (rcvd->max_reqs == 0) |
| 8181 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8182 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8183 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8184 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8185 | } |
| 8186 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8187 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8188 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8189 | { |
| 8190 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8191 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8192 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8193 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8194 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8195 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8196 | return -EINVAL; |
| 8197 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8198 | return -EINVAL; |
| 8199 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8200 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8201 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8202 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8203 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8204 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8205 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8206 | return 0; |
| 8207 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8208 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8209 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8210 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8211 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8212 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8213 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8214 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8215 | if (ret) |
| 8216 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8217 | return nfs4_verify_back_channel_attrs(args, res); |
| 8218 | } |
| 8219 | |
| 8220 | static void nfs4_update_session(struct nfs4_session *session, |
| 8221 | struct nfs41_create_session_res *res) |
| 8222 | { |
| 8223 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8224 | /* Mark client id and session as being confirmed */ |
| 8225 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8226 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8227 | session->flags = res->flags; |
| 8228 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8229 | if (res->flags & SESSION4_BACK_CHAN) |
| 8230 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8231 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8232 | } |
| 8233 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8234 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8235 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8236 | { |
| 8237 | struct nfs4_session *session = clp->cl_session; |
| 8238 | struct nfs41_create_session_args args = { |
| 8239 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8240 | .clientid = clp->cl_clientid, |
| 8241 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8242 | .cb_program = NFS4_CALLBACK, |
| 8243 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8244 | struct nfs41_create_session_res res; |
| 8245 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8246 | struct rpc_message msg = { |
| 8247 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8248 | .rpc_argp = &args, |
| 8249 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8250 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8251 | }; |
| 8252 | int status; |
| 8253 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8254 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8255 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8256 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8257 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8258 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8259 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8260 | switch (status) { |
| 8261 | case -NFS4ERR_STALE_CLIENTID: |
| 8262 | case -NFS4ERR_DELAY: |
| 8263 | case -ETIMEDOUT: |
| 8264 | case -EACCES: |
| 8265 | case -EAGAIN: |
| 8266 | goto out; |
| 8267 | }; |
| 8268 | |
| 8269 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8270 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8271 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8272 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8273 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8274 | if (status) |
| 8275 | goto out; |
| 8276 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8277 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8278 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8279 | return status; |
| 8280 | } |
| 8281 | |
| 8282 | /* |
| 8283 | * Issues a CREATE_SESSION operation to the server. |
| 8284 | * It is the responsibility of the caller to verify the session is |
| 8285 | * expired before calling this routine. |
| 8286 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8287 | 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] | 8288 | { |
| 8289 | int status; |
| 8290 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8291 | struct nfs4_session *session = clp->cl_session; |
| 8292 | |
| 8293 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8294 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8295 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8296 | if (status) |
| 8297 | goto out; |
| 8298 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8299 | /* Init or reset the session slot tables */ |
| 8300 | status = nfs4_setup_session_slot_tables(session); |
| 8301 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8302 | if (status) |
| 8303 | goto out; |
| 8304 | |
| 8305 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8306 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8307 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8308 | out: |
| 8309 | dprintk("<-- %s\n", __func__); |
| 8310 | return status; |
| 8311 | } |
| 8312 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8313 | /* |
| 8314 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8315 | * The caller must serialize access to this routine. |
| 8316 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8317 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8318 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8319 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8320 | struct rpc_message msg = { |
| 8321 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8322 | .rpc_argp = session, |
| 8323 | .rpc_cred = cred, |
| 8324 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8325 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8326 | |
| 8327 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8328 | |
| 8329 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8330 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8331 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8332 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8333 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8334 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8335 | |
| 8336 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8337 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8338 | "Session has been destroyed regardless...\n", status); |
| 8339 | |
| 8340 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8341 | return status; |
| 8342 | } |
| 8343 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8344 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8345 | * Renew the cl_session lease. |
| 8346 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8347 | struct nfs4_sequence_data { |
| 8348 | struct nfs_client *clp; |
| 8349 | struct nfs4_sequence_args args; |
| 8350 | struct nfs4_sequence_res res; |
| 8351 | }; |
| 8352 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8353 | static void nfs41_sequence_release(void *data) |
| 8354 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8355 | struct nfs4_sequence_data *calldata = data; |
| 8356 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8357 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8358 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8359 | nfs4_schedule_state_renewal(clp); |
| 8360 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8361 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8362 | } |
| 8363 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8364 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8365 | { |
| 8366 | switch(task->tk_status) { |
| 8367 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8368 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8369 | return -EAGAIN; |
| 8370 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8371 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8372 | } |
| 8373 | return 0; |
| 8374 | } |
| 8375 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8376 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8377 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8378 | struct nfs4_sequence_data *calldata = data; |
| 8379 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8380 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8381 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8382 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8383 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8384 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8385 | if (task->tk_status < 0) { |
| 8386 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8387 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8388 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8389 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8390 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8391 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8392 | return; |
| 8393 | } |
| 8394 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8395 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8396 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8397 | dprintk("<-- %s\n", __func__); |
| 8398 | } |
| 8399 | |
| 8400 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8401 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8402 | struct nfs4_sequence_data *calldata = data; |
| 8403 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8404 | struct nfs4_sequence_args *args; |
| 8405 | struct nfs4_sequence_res *res; |
| 8406 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8407 | args = task->tk_msg.rpc_argp; |
| 8408 | res = task->tk_msg.rpc_resp; |
| 8409 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8410 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8411 | } |
| 8412 | |
| 8413 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8414 | .rpc_call_done = nfs41_sequence_call_done, |
| 8415 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8416 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8417 | }; |
| 8418 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8419 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8420 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8421 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8422 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8423 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8424 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8425 | struct rpc_message msg = { |
| 8426 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8427 | .rpc_cred = cred, |
| 8428 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8429 | struct rpc_task_setup task_setup_data = { |
| 8430 | .rpc_client = clp->cl_rpcclient, |
| 8431 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8432 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8433 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8434 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8435 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8436 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8437 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8438 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8439 | goto out_err; |
| 8440 | |
| 8441 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8442 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8443 | if (calldata == NULL) |
| 8444 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8445 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8446 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8447 | msg.rpc_argp = &calldata->args; |
| 8448 | msg.rpc_resp = &calldata->res; |
| 8449 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8450 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8451 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8452 | ret = rpc_run_task(&task_setup_data); |
| 8453 | if (IS_ERR(ret)) |
| 8454 | goto out_err; |
| 8455 | return ret; |
| 8456 | out_put_clp: |
| 8457 | nfs_put_client(clp); |
| 8458 | out_err: |
| 8459 | nfs41_release_slot(slot); |
| 8460 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8461 | } |
| 8462 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8463 | 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] | 8464 | { |
| 8465 | struct rpc_task *task; |
| 8466 | int ret = 0; |
| 8467 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8468 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8469 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8470 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8471 | if (IS_ERR(task)) |
| 8472 | ret = PTR_ERR(task); |
| 8473 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8474 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8475 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8476 | return ret; |
| 8477 | } |
| 8478 | |
| 8479 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8480 | { |
| 8481 | struct rpc_task *task; |
| 8482 | int ret; |
| 8483 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8484 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8485 | if (IS_ERR(task)) { |
| 8486 | ret = PTR_ERR(task); |
| 8487 | goto out; |
| 8488 | } |
| 8489 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8490 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8491 | ret = task->tk_status; |
| 8492 | rpc_put_task(task); |
| 8493 | out: |
| 8494 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8495 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8496 | } |
| 8497 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8498 | struct nfs4_reclaim_complete_data { |
| 8499 | struct nfs_client *clp; |
| 8500 | struct nfs41_reclaim_complete_args arg; |
| 8501 | struct nfs41_reclaim_complete_res res; |
| 8502 | }; |
| 8503 | |
| 8504 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8505 | { |
| 8506 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8507 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8508 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8509 | &calldata->arg.seq_args, |
| 8510 | &calldata->res.seq_res, |
| 8511 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8512 | } |
| 8513 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8514 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8515 | { |
| 8516 | switch(task->tk_status) { |
| 8517 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8518 | wake_up_all(&clp->cl_lock_waitq); |
| 8519 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8520 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8521 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8522 | break; |
| 8523 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8524 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8525 | /* fall through */ |
| 8526 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8527 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8528 | case -NFS4ERR_BADSESSION: |
| 8529 | case -NFS4ERR_DEADSESSION: |
| 8530 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8531 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8532 | task->tk_status); |
| 8533 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8534 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8535 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8536 | } |
| 8537 | return 0; |
| 8538 | } |
| 8539 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8540 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8541 | { |
| 8542 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8543 | struct nfs_client *clp = calldata->clp; |
| 8544 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8545 | |
| 8546 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8547 | if (!nfs41_sequence_done(task, res)) |
| 8548 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8549 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8550 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8551 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8552 | rpc_restart_call_prepare(task); |
| 8553 | return; |
| 8554 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8555 | dprintk("<-- %s\n", __func__); |
| 8556 | } |
| 8557 | |
| 8558 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8559 | { |
| 8560 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8561 | |
| 8562 | kfree(calldata); |
| 8563 | } |
| 8564 | |
| 8565 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8566 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8567 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8568 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8569 | }; |
| 8570 | |
| 8571 | /* |
| 8572 | * Issue a global reclaim complete. |
| 8573 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8574 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8575 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8576 | { |
| 8577 | struct nfs4_reclaim_complete_data *calldata; |
| 8578 | struct rpc_task *task; |
| 8579 | struct rpc_message msg = { |
| 8580 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8581 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8582 | }; |
| 8583 | struct rpc_task_setup task_setup_data = { |
| 8584 | .rpc_client = clp->cl_rpcclient, |
| 8585 | .rpc_message = &msg, |
| 8586 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8587 | .flags = RPC_TASK_ASYNC, |
| 8588 | }; |
| 8589 | int status = -ENOMEM; |
| 8590 | |
| 8591 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8592 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8593 | if (calldata == NULL) |
| 8594 | goto out; |
| 8595 | calldata->clp = clp; |
| 8596 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8597 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8598 | 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] | 8599 | msg.rpc_argp = &calldata->arg; |
| 8600 | msg.rpc_resp = &calldata->res; |
| 8601 | task_setup_data.callback_data = calldata; |
| 8602 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8603 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8604 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8605 | goto out; |
| 8606 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8607 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8608 | if (status == 0) |
| 8609 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8610 | rpc_put_task(task); |
| 8611 | out: |
| 8612 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8613 | return status; |
| 8614 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8615 | |
| 8616 | static void |
| 8617 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8618 | { |
| 8619 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8620 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8621 | |
| 8622 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8623 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8624 | &lgp->res.seq_res, task); |
| 8625 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8626 | } |
| 8627 | |
| 8628 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8629 | { |
| 8630 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8631 | |
| 8632 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8633 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8634 | dprintk("<-- %s\n", __func__); |
| 8635 | } |
| 8636 | |
| 8637 | static int |
| 8638 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8639 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8640 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8641 | struct inode *inode = lgp->args.inode; |
| 8642 | struct nfs_server *server = NFS_SERVER(inode); |
| 8643 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8644 | int nfs4err = task->tk_status; |
| 8645 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8646 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8647 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8648 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8649 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8650 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8651 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8652 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8653 | |
| 8654 | /* |
| 8655 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8656 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8657 | * retry go inband. |
| 8658 | */ |
| 8659 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8660 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8661 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8662 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8663 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8664 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8665 | */ |
| 8666 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8667 | status = -EOVERFLOW; |
| 8668 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8669 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8670 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8671 | * (or clients) writing to the same RAID stripe except when |
| 8672 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8673 | * |
| 8674 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8675 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8676 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8677 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8678 | if (lgp->args.minlength == 0) { |
| 8679 | status = -EOVERFLOW; |
| 8680 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8681 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8682 | status = -EBUSY; |
| 8683 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8684 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8685 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8686 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8687 | case -NFS4ERR_DELEG_REVOKED: |
| 8688 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8689 | case -NFS4ERR_EXPIRED: |
| 8690 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8691 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8692 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8693 | lo = NFS_I(inode)->layout; |
| 8694 | /* If the open stateid was bad, then recover it. */ |
| 8695 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8696 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8697 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8698 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8699 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8700 | break; |
| 8701 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8702 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8703 | /* |
| 8704 | * Mark the bad layout state as invalid, then retry |
| 8705 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8706 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8707 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8708 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8709 | pnfs_free_lseg_list(&head); |
| 8710 | status = -EAGAIN; |
| 8711 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8712 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8713 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8714 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8715 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8716 | if (!status) { |
| 8717 | if (exception->retry) |
| 8718 | status = -EAGAIN; |
| 8719 | else |
| 8720 | status = err; |
| 8721 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8722 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8723 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8724 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8725 | } |
| 8726 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8727 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8728 | { |
| 8729 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8730 | return nfs_page_array_len(0, max_resp_sz); |
| 8731 | } |
| 8732 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8733 | static void nfs4_layoutget_release(void *calldata) |
| 8734 | { |
| 8735 | struct nfs4_layoutget *lgp = calldata; |
| 8736 | |
| 8737 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8738 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 8739 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8740 | dprintk("<-- %s\n", __func__); |
| 8741 | } |
| 8742 | |
| 8743 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8744 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8745 | .rpc_call_done = nfs4_layoutget_done, |
| 8746 | .rpc_release = nfs4_layoutget_release, |
| 8747 | }; |
| 8748 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8749 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8750 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8751 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8752 | struct inode *inode = lgp->args.inode; |
| 8753 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8754 | struct rpc_task *task; |
| 8755 | struct rpc_message msg = { |
| 8756 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8757 | .rpc_argp = &lgp->args, |
| 8758 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8759 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8760 | }; |
| 8761 | struct rpc_task_setup task_setup_data = { |
| 8762 | .rpc_client = server->client, |
| 8763 | .rpc_message = &msg, |
| 8764 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8765 | .callback_data = lgp, |
| 8766 | .flags = RPC_TASK_ASYNC, |
| 8767 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8768 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8769 | struct nfs4_exception exception = { |
| 8770 | .inode = inode, |
| 8771 | .timeout = *timeout, |
| 8772 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8773 | int status = 0; |
| 8774 | |
| 8775 | dprintk("--> %s\n", __func__); |
| 8776 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8777 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8778 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8779 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8780 | 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] | 8781 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8782 | task = rpc_run_task(&task_setup_data); |
| 8783 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8784 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8785 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8786 | if (status == 0) { |
| 8787 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8788 | *timeout = exception.timeout; |
| 8789 | } |
| 8790 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8791 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8792 | &lgp->args.range, |
| 8793 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8794 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8795 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8796 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8797 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8798 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8799 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8800 | rpc_put_task(task); |
| 8801 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8802 | if (status) |
| 8803 | return ERR_PTR(status); |
| 8804 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8805 | } |
| 8806 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8807 | static void |
| 8808 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8809 | { |
| 8810 | struct nfs4_layoutreturn *lrp = calldata; |
| 8811 | |
| 8812 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8813 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8814 | &lrp->args.seq_args, |
| 8815 | &lrp->res.seq_res, |
| 8816 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8817 | } |
| 8818 | |
| 8819 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8820 | { |
| 8821 | struct nfs4_layoutreturn *lrp = calldata; |
| 8822 | struct nfs_server *server; |
| 8823 | |
| 8824 | dprintk("--> %s\n", __func__); |
| 8825 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8826 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8827 | return; |
| 8828 | |
| 8829 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8830 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8831 | case -NFS4ERR_OLD_STATEID: |
| 8832 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, |
| 8833 | lrp->args.inode)) |
| 8834 | goto out_restart; |
| 8835 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8836 | default: |
| 8837 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8838 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8839 | case 0: |
| 8840 | break; |
| 8841 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8842 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8843 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8844 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8845 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8846 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8847 | return; |
| 8848 | out_restart: |
| 8849 | task->tk_status = 0; |
| 8850 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8851 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8852 | } |
| 8853 | |
| 8854 | static void nfs4_layoutreturn_release(void *calldata) |
| 8855 | { |
| 8856 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8857 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8858 | |
| 8859 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8860 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8861 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8862 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8863 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8864 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8865 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8866 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8867 | kfree(calldata); |
| 8868 | dprintk("<-- %s\n", __func__); |
| 8869 | } |
| 8870 | |
| 8871 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8872 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8873 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8874 | .rpc_release = nfs4_layoutreturn_release, |
| 8875 | }; |
| 8876 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8877 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8878 | { |
| 8879 | struct rpc_task *task; |
| 8880 | struct rpc_message msg = { |
| 8881 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8882 | .rpc_argp = &lrp->args, |
| 8883 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8884 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8885 | }; |
| 8886 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8887 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8888 | .rpc_message = &msg, |
| 8889 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8890 | .callback_data = lrp, |
| 8891 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8892 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8893 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8894 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8895 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8896 | &task_setup_data.rpc_client, &msg); |
| 8897 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8898 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8899 | if (!sync) { |
| 8900 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8901 | if (!lrp->inode) { |
| 8902 | nfs4_layoutreturn_release(lrp); |
| 8903 | return -EAGAIN; |
| 8904 | } |
| 8905 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8906 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8907 | 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] | 8908 | task = rpc_run_task(&task_setup_data); |
| 8909 | if (IS_ERR(task)) |
| 8910 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8911 | if (sync) |
| 8912 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8913 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8914 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8915 | rpc_put_task(task); |
| 8916 | return status; |
| 8917 | } |
| 8918 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8919 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8920 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8921 | struct pnfs_device *pdev, |
| 8922 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8923 | { |
| 8924 | struct nfs4_getdeviceinfo_args args = { |
| 8925 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8926 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8927 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8928 | }; |
| 8929 | struct nfs4_getdeviceinfo_res res = { |
| 8930 | .pdev = pdev, |
| 8931 | }; |
| 8932 | struct rpc_message msg = { |
| 8933 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8934 | .rpc_argp = &args, |
| 8935 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8936 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8937 | }; |
| 8938 | int status; |
| 8939 | |
| 8940 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8941 | 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] | 8942 | if (res.notification & ~args.notify_types) |
| 8943 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8944 | if (res.notification != args.notify_types) |
| 8945 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8946 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8947 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8948 | |
| 8949 | return status; |
| 8950 | } |
| 8951 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8952 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8953 | struct pnfs_device *pdev, |
| 8954 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8955 | { |
| 8956 | struct nfs4_exception exception = { }; |
| 8957 | int err; |
| 8958 | |
| 8959 | do { |
| 8960 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8961 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8962 | &exception); |
| 8963 | } while (exception.retry); |
| 8964 | return err; |
| 8965 | } |
| 8966 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8967 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8968 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8969 | { |
| 8970 | struct nfs4_layoutcommit_data *data = calldata; |
| 8971 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8972 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8973 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8974 | &data->args.seq_args, |
| 8975 | &data->res.seq_res, |
| 8976 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8977 | } |
| 8978 | |
| 8979 | static void |
| 8980 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8981 | { |
| 8982 | struct nfs4_layoutcommit_data *data = calldata; |
| 8983 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8984 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8985 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8986 | return; |
| 8987 | |
| 8988 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8989 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8990 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8991 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8992 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8993 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8994 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8995 | break; |
| 8996 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8997 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8998 | rpc_restart_call_prepare(task); |
| 8999 | return; |
| 9000 | } |
| 9001 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9002 | } |
| 9003 | |
| 9004 | static void nfs4_layoutcommit_release(void *calldata) |
| 9005 | { |
| 9006 | struct nfs4_layoutcommit_data *data = calldata; |
| 9007 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9008 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9009 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9010 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9011 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9012 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9013 | kfree(data); |
| 9014 | } |
| 9015 | |
| 9016 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9017 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9018 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9019 | .rpc_release = nfs4_layoutcommit_release, |
| 9020 | }; |
| 9021 | |
| 9022 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9023 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9024 | { |
| 9025 | struct rpc_message msg = { |
| 9026 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9027 | .rpc_argp = &data->args, |
| 9028 | .rpc_resp = &data->res, |
| 9029 | .rpc_cred = data->cred, |
| 9030 | }; |
| 9031 | struct rpc_task_setup task_setup_data = { |
| 9032 | .task = &data->task, |
| 9033 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9034 | .rpc_message = &msg, |
| 9035 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9036 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9037 | }; |
| 9038 | struct rpc_task *task; |
| 9039 | int status = 0; |
| 9040 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9041 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9042 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9043 | data->args.lastbytewritten, |
| 9044 | data->args.inode->i_ino); |
| 9045 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9046 | if (!sync) { |
| 9047 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9048 | if (data->inode == NULL) { |
| 9049 | nfs4_layoutcommit_release(data); |
| 9050 | return -EAGAIN; |
| 9051 | } |
| 9052 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9053 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9054 | 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] | 9055 | task = rpc_run_task(&task_setup_data); |
| 9056 | if (IS_ERR(task)) |
| 9057 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9058 | if (sync) |
| 9059 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9060 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9061 | dprintk("%s: status %d\n", __func__, status); |
| 9062 | rpc_put_task(task); |
| 9063 | return status; |
| 9064 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9065 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9066 | /** |
| 9067 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9068 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9069 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9070 | static int |
| 9071 | _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] | 9072 | struct nfs_fsinfo *info, |
| 9073 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9074 | { |
| 9075 | struct nfs41_secinfo_no_name_args args = { |
| 9076 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9077 | }; |
| 9078 | struct nfs4_secinfo_res res = { |
| 9079 | .flavors = flavors, |
| 9080 | }; |
| 9081 | struct rpc_message msg = { |
| 9082 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9083 | .rpc_argp = &args, |
| 9084 | .rpc_resp = &res, |
| 9085 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9086 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9087 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9088 | int status; |
| 9089 | |
| 9090 | if (use_integrity) { |
| 9091 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9092 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9093 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9094 | } |
| 9095 | |
| 9096 | dprintk("--> %s\n", __func__); |
| 9097 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9098 | &res.seq_res, 0); |
| 9099 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9100 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9101 | if (cred) |
| 9102 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9103 | |
| 9104 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9105 | } |
| 9106 | |
| 9107 | static int |
| 9108 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9109 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9110 | { |
| 9111 | struct nfs4_exception exception = { }; |
| 9112 | int err; |
| 9113 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9114 | /* first try using integrity protection */ |
| 9115 | err = -NFS4ERR_WRONGSEC; |
| 9116 | |
| 9117 | /* try to use integrity protection with machine cred */ |
| 9118 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9119 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9120 | flavors, true); |
| 9121 | |
| 9122 | /* |
| 9123 | * if unable to use integrity protection, or SECINFO with |
| 9124 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9125 | * disallowed by spec, but exists in deployed servers) use |
| 9126 | * the current filesystem's rpc_client and the user cred. |
| 9127 | */ |
| 9128 | if (err == -NFS4ERR_WRONGSEC) |
| 9129 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9130 | flavors, false); |
| 9131 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9132 | switch (err) { |
| 9133 | case 0: |
| 9134 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9135 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9136 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9137 | default: |
| 9138 | err = nfs4_handle_exception(server, err, &exception); |
| 9139 | } |
| 9140 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9141 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9142 | return err; |
| 9143 | } |
| 9144 | |
| 9145 | static int |
| 9146 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9147 | struct nfs_fsinfo *info) |
| 9148 | { |
| 9149 | int err; |
| 9150 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9151 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9152 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9153 | struct nfs4_secinfo4 *secinfo; |
| 9154 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9155 | |
| 9156 | page = alloc_page(GFP_KERNEL); |
| 9157 | if (!page) { |
| 9158 | err = -ENOMEM; |
| 9159 | goto out; |
| 9160 | } |
| 9161 | |
| 9162 | flavors = page_address(page); |
| 9163 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9164 | |
| 9165 | /* |
| 9166 | * Fall back on "guess and check" method if |
| 9167 | * the server doesn't support SECINFO_NO_NAME |
| 9168 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9169 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9170 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9171 | goto out_freepage; |
| 9172 | } |
| 9173 | if (err) |
| 9174 | goto out_freepage; |
| 9175 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9176 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9177 | secinfo = &flavors->flavors[i]; |
| 9178 | |
| 9179 | switch (secinfo->flavor) { |
| 9180 | case RPC_AUTH_NULL: |
| 9181 | case RPC_AUTH_UNIX: |
| 9182 | case RPC_AUTH_GSS: |
| 9183 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9184 | &secinfo->flavor_info); |
| 9185 | break; |
| 9186 | default: |
| 9187 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9188 | break; |
| 9189 | } |
| 9190 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9191 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9192 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9193 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9194 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9195 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9196 | info, flavor); |
| 9197 | if (!err) |
| 9198 | break; |
| 9199 | } |
| 9200 | } |
| 9201 | |
| 9202 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9203 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9204 | |
| 9205 | out_freepage: |
| 9206 | put_page(page); |
| 9207 | if (err == -EACCES) |
| 9208 | return -EPERM; |
| 9209 | out: |
| 9210 | return err; |
| 9211 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9212 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9213 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9214 | nfs4_stateid *stateid, |
| 9215 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9216 | { |
| 9217 | int status; |
| 9218 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9219 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9220 | }; |
| 9221 | struct nfs41_test_stateid_res res; |
| 9222 | struct rpc_message msg = { |
| 9223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9224 | .rpc_argp = &args, |
| 9225 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9226 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9227 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9228 | struct rpc_clnt *rpc_client = server->client; |
| 9229 | |
| 9230 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9231 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9232 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9233 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9234 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9235 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9236 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9237 | if (status != NFS_OK) { |
| 9238 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9239 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9240 | } |
| 9241 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9242 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9243 | } |
| 9244 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9245 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9246 | int err, struct nfs4_exception *exception) |
| 9247 | { |
| 9248 | exception->retry = 0; |
| 9249 | switch(err) { |
| 9250 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9251 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9252 | nfs4_handle_exception(server, err, exception); |
| 9253 | break; |
| 9254 | case -NFS4ERR_BADSESSION: |
| 9255 | case -NFS4ERR_BADSLOT: |
| 9256 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9257 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9258 | case -NFS4ERR_DEADSESSION: |
| 9259 | nfs4_do_handle_exception(server, err, exception); |
| 9260 | } |
| 9261 | } |
| 9262 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9263 | /** |
| 9264 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9265 | * |
| 9266 | * @server: server / transport on which to perform the operation |
| 9267 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9268 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9269 | * |
| 9270 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9271 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9272 | * failed or the state ID is not currently valid. |
| 9273 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9274 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9275 | nfs4_stateid *stateid, |
| 9276 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9277 | { |
| 9278 | struct nfs4_exception exception = { }; |
| 9279 | int err; |
| 9280 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9281 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9282 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9283 | } while (exception.retry); |
| 9284 | return err; |
| 9285 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9286 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9287 | struct nfs_free_stateid_data { |
| 9288 | struct nfs_server *server; |
| 9289 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9290 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9291 | }; |
| 9292 | |
| 9293 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9294 | { |
| 9295 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9296 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9297 | &data->args.seq_args, |
| 9298 | &data->res.seq_res, |
| 9299 | task); |
| 9300 | } |
| 9301 | |
| 9302 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9303 | { |
| 9304 | struct nfs_free_stateid_data *data = calldata; |
| 9305 | |
| 9306 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9307 | |
| 9308 | switch (task->tk_status) { |
| 9309 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9310 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9311 | rpc_restart_call_prepare(task); |
| 9312 | } |
| 9313 | } |
| 9314 | |
| 9315 | static void nfs41_free_stateid_release(void *calldata) |
| 9316 | { |
| 9317 | kfree(calldata); |
| 9318 | } |
| 9319 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9320 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9321 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9322 | .rpc_call_done = nfs41_free_stateid_done, |
| 9323 | .rpc_release = nfs41_free_stateid_release, |
| 9324 | }; |
| 9325 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9326 | /** |
| 9327 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9328 | * |
| 9329 | * @server: server / transport on which to perform the operation |
| 9330 | * @stateid: state ID to release |
| 9331 | * @cred: credential |
| 9332 | * @is_recovery: set to true if this call needs to be privileged |
| 9333 | * |
| 9334 | * Note: this function is always asynchronous. |
| 9335 | */ |
| 9336 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9337 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9338 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9339 | bool privileged) |
| 9340 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9341 | struct rpc_message msg = { |
| 9342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9343 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9344 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9345 | struct rpc_task_setup task_setup = { |
| 9346 | .rpc_client = server->client, |
| 9347 | .rpc_message = &msg, |
| 9348 | .callback_ops = &nfs41_free_stateid_ops, |
| 9349 | .flags = RPC_TASK_ASYNC, |
| 9350 | }; |
| 9351 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9352 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9353 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9354 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9355 | &task_setup.rpc_client, &msg); |
| 9356 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9357 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9358 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9359 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9360 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9361 | data->server = server; |
| 9362 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9363 | |
| 9364 | task_setup.callback_data = data; |
| 9365 | |
| 9366 | msg.rpc_argp = &data->args; |
| 9367 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9368 | 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] | 9369 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9370 | if (IS_ERR(task)) |
| 9371 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9372 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9373 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9374 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9375 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9376 | static void |
| 9377 | 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] | 9378 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9379 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9380 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9381 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9382 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9383 | } |
| 9384 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9385 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9386 | const nfs4_stateid *s2) |
| 9387 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9388 | if (s1->type != s2->type) |
| 9389 | return false; |
| 9390 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9391 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9392 | return false; |
| 9393 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9394 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9395 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9396 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9397 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9398 | } |
| 9399 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9400 | #endif /* CONFIG_NFS_V4_1 */ |
| 9401 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9402 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9403 | const nfs4_stateid *s2) |
| 9404 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9405 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9406 | } |
| 9407 | |
| 9408 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9409 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9410 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9411 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9412 | .recover_open = nfs4_open_reclaim, |
| 9413 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9414 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9415 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9416 | }; |
| 9417 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9418 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9419 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9420 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9421 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9422 | .recover_open = nfs4_open_reclaim, |
| 9423 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9424 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9425 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9426 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9427 | }; |
| 9428 | #endif /* CONFIG_NFS_V4_1 */ |
| 9429 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9430 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9431 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9432 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9433 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9434 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9435 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9436 | }; |
| 9437 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9438 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9439 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9440 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9441 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9442 | .recover_open = nfs41_open_expired, |
| 9443 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9444 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9445 | }; |
| 9446 | #endif /* CONFIG_NFS_V4_1 */ |
| 9447 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9448 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9449 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9450 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9451 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9452 | }; |
| 9453 | |
| 9454 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9455 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9456 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9457 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9458 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9459 | }; |
| 9460 | #endif |
| 9461 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9462 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9463 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9464 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9465 | }; |
| 9466 | |
| 9467 | #if defined(CONFIG_NFS_V4_1) |
| 9468 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9469 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9470 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9471 | }; |
| 9472 | #endif /* CONFIG_NFS_V4_1 */ |
| 9473 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9474 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9475 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9476 | .init_caps = NFS_CAP_READDIRPLUS |
| 9477 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9478 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9479 | .init_client = nfs40_init_client, |
| 9480 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9481 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9482 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9483 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9484 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9485 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9486 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9487 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9488 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9489 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9490 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9491 | }; |
| 9492 | |
| 9493 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9494 | static struct nfs_seqid * |
| 9495 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9496 | { |
| 9497 | return NULL; |
| 9498 | } |
| 9499 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9500 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9501 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9502 | .init_caps = NFS_CAP_READDIRPLUS |
| 9503 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9504 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9505 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9506 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9507 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9508 | .init_client = nfs41_init_client, |
| 9509 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9510 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9511 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9512 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9513 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9514 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9515 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9516 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9517 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9518 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9519 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9520 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9521 | }; |
| 9522 | #endif |
| 9523 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9524 | #if defined(CONFIG_NFS_V4_2) |
| 9525 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9526 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9527 | .init_caps = NFS_CAP_READDIRPLUS |
| 9528 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9529 | | NFS_CAP_POSIX_LOCK |
| 9530 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9531 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9532 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9533 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9534 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9535 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9536 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9537 | | NFS_CAP_LAYOUTSTATS |
| 9538 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9539 | .init_client = nfs41_init_client, |
| 9540 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9541 | .match_stateid = nfs41_match_stateid, |
| 9542 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9543 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9544 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9545 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9546 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9547 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9548 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9549 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9550 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9551 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9552 | }; |
| 9553 | #endif |
| 9554 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9555 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9556 | [0] = &nfs_v4_0_minor_ops, |
| 9557 | #if defined(CONFIG_NFS_V4_1) |
| 9558 | [1] = &nfs_v4_1_minor_ops, |
| 9559 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9560 | #if defined(CONFIG_NFS_V4_2) |
| 9561 | [2] = &nfs_v4_2_minor_ops, |
| 9562 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9563 | }; |
| 9564 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9565 | 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] | 9566 | { |
| 9567 | ssize_t error, error2; |
| 9568 | |
| 9569 | error = generic_listxattr(dentry, list, size); |
| 9570 | if (error < 0) |
| 9571 | return error; |
| 9572 | if (list) { |
| 9573 | list += error; |
| 9574 | size -= error; |
| 9575 | } |
| 9576 | |
| 9577 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9578 | if (error2 < 0) |
| 9579 | return error2; |
| 9580 | return error + error2; |
| 9581 | } |
| 9582 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9583 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9584 | .create = nfs_create, |
| 9585 | .lookup = nfs_lookup, |
| 9586 | .atomic_open = nfs_atomic_open, |
| 9587 | .link = nfs_link, |
| 9588 | .unlink = nfs_unlink, |
| 9589 | .symlink = nfs_symlink, |
| 9590 | .mkdir = nfs_mkdir, |
| 9591 | .rmdir = nfs_rmdir, |
| 9592 | .mknod = nfs_mknod, |
| 9593 | .rename = nfs_rename, |
| 9594 | .permission = nfs_permission, |
| 9595 | .getattr = nfs_getattr, |
| 9596 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9597 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9598 | }; |
| 9599 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9600 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9601 | .permission = nfs_permission, |
| 9602 | .getattr = nfs_getattr, |
| 9603 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9604 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9605 | }; |
| 9606 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9607 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9608 | .version = 4, /* protocol version */ |
| 9609 | .dentry_ops = &nfs4_dentry_operations, |
| 9610 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9611 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9612 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9613 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9614 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9615 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9616 | .getattr = nfs4_proc_getattr, |
| 9617 | .setattr = nfs4_proc_setattr, |
| 9618 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9619 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9620 | .access = nfs4_proc_access, |
| 9621 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9622 | .create = nfs4_proc_create, |
| 9623 | .remove = nfs4_proc_remove, |
| 9624 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9625 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9626 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9627 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9628 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9629 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9630 | .link = nfs4_proc_link, |
| 9631 | .symlink = nfs4_proc_symlink, |
| 9632 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9633 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9634 | .readdir = nfs4_proc_readdir, |
| 9635 | .mknod = nfs4_proc_mknod, |
| 9636 | .statfs = nfs4_proc_statfs, |
| 9637 | .fsinfo = nfs4_proc_fsinfo, |
| 9638 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9639 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9640 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9641 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9642 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9643 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9644 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9645 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9646 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9647 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9648 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9649 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9650 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9651 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9652 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9653 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9654 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9655 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9656 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9657 | .create_server = nfs4_create_server, |
| 9658 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9659 | }; |
| 9660 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9661 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9662 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9663 | .list = nfs4_xattr_list_nfs4_acl, |
| 9664 | .get = nfs4_xattr_get_nfs4_acl, |
| 9665 | .set = nfs4_xattr_set_nfs4_acl, |
| 9666 | }; |
| 9667 | |
| 9668 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9669 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9670 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9671 | &nfs4_xattr_nfs4_label_handler, |
| 9672 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9673 | NULL |
| 9674 | }; |
| 9675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9676 | /* |
| 9677 | * Local variables: |
| 9678 | * c-basic-offset: 8 |
| 9679 | * End: |
| 9680 | */ |