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 | f9312a5 | 2018-06-09 19:10:31 -0400 | [diff] [blame] | 778 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 779 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 780 | /* |
| 781 | * The server thinks we tried to replay a request. |
| 782 | * Retry the call after bumping the sequence ID. |
| 783 | */ |
| 784 | goto retry_new_seq; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 785 | case -NFS4ERR_BADSLOT: |
| 786 | /* |
| 787 | * The slot id we used was probably retired. Try again |
| 788 | * using a different slot id. |
| 789 | */ |
Trond Myklebust | 9958910 | 2018-06-09 12:50:50 -0400 | [diff] [blame] | 790 | if (slot->slot_nr < slot->table->target_highest_slotid) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 791 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 792 | goto retry_nowait; |
| 793 | case -NFS4ERR_SEQ_MISORDERED: |
| 794 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 795 | * Was the last operation on this sequence interrupted? |
| 796 | * If so, retry after bumping the sequence number. |
| 797 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 798 | if (interrupted) |
| 799 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 800 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 801 | * Could this slot have been previously retired? |
| 802 | * If so, then the server may be expecting seq_nr = 1! |
| 803 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 804 | if (slot->seq_nr != 1) { |
| 805 | slot->seq_nr = 1; |
| 806 | goto retry_nowait; |
| 807 | } |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 808 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 809 | default: |
| 810 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 811 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 812 | } |
| 813 | out: |
| 814 | /* The session may be reset by one of the error handlers. */ |
| 815 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 816 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 817 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 818 | session_recover: |
| 819 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 820 | goto retry_nowait; |
| 821 | retry_new_seq: |
| 822 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 823 | retry_nowait: |
| 824 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 825 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 826 | task->tk_status = 0; |
| 827 | ret = 0; |
| 828 | } |
| 829 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 830 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 831 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 832 | goto out; |
| 833 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 834 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 835 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 836 | |
| 837 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 838 | { |
| 839 | if (!nfs41_sequence_process(task, res)) |
| 840 | return 0; |
| 841 | if (res->sr_slot != NULL) |
| 842 | nfs41_sequence_free_slot(res); |
| 843 | return 1; |
| 844 | |
| 845 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 846 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 847 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 848 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 849 | { |
| 850 | if (res->sr_slot == NULL) |
| 851 | return 1; |
| 852 | if (res->sr_slot->table->session != NULL) |
| 853 | return nfs41_sequence_process(task, res); |
| 854 | return nfs40_sequence_done(task, res); |
| 855 | } |
| 856 | |
| 857 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 858 | { |
| 859 | if (res->sr_slot != NULL) { |
| 860 | if (res->sr_slot->table->session != NULL) |
| 861 | nfs41_sequence_free_slot(res); |
| 862 | else |
| 863 | nfs40_sequence_free_slot(res); |
| 864 | } |
| 865 | } |
| 866 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 867 | 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] | 868 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 869 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 870 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 871 | if (!res->sr_slot->table->session) |
| 872 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 873 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 874 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 875 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 876 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 877 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 878 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 879 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 880 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 881 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 882 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 883 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 884 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 887 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 888 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 889 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 890 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 891 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 894 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 895 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 896 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | }; |
| 898 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 899 | static void |
| 900 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 901 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 902 | { |
| 903 | struct rpc_task *task; |
| 904 | |
| 905 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 906 | if (!IS_ERR(task)) |
| 907 | rpc_put_task_async(task); |
| 908 | } |
| 909 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 910 | #else /* !CONFIG_NFS_V4_1 */ |
| 911 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 912 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 913 | { |
| 914 | return nfs40_sequence_done(task, res); |
| 915 | } |
| 916 | |
| 917 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 918 | { |
| 919 | if (res->sr_slot != NULL) |
| 920 | nfs40_sequence_free_slot(res); |
| 921 | } |
| 922 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 923 | int nfs4_sequence_done(struct rpc_task *task, |
| 924 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 925 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 926 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 927 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 928 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 929 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 930 | static void |
| 931 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 932 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 933 | { |
| 934 | WARN_ON_ONCE(1); |
| 935 | slot->interrupted = 0; |
| 936 | } |
| 937 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 938 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 939 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 940 | static |
| 941 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 942 | struct nfs4_sequence_res *res, |
| 943 | struct nfs4_slot *slot) |
| 944 | { |
| 945 | if (!slot) |
| 946 | return; |
| 947 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 948 | args->sa_slot = slot; |
| 949 | |
| 950 | res->sr_slot = slot; |
| 951 | res->sr_timestamp = jiffies; |
| 952 | res->sr_status_flags = 0; |
| 953 | res->sr_status = 1; |
| 954 | |
| 955 | } |
| 956 | |
| 957 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 958 | struct nfs4_sequence_args *args, |
| 959 | struct nfs4_sequence_res *res, |
| 960 | struct rpc_task *task) |
| 961 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 962 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 963 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 964 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 965 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 966 | /* slot already allocated? */ |
| 967 | if (res->sr_slot != NULL) |
| 968 | goto out_start; |
| 969 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 970 | if (session) { |
| 971 | tbl = &session->fc_slot_table; |
| 972 | task->tk_timeout = 0; |
| 973 | } |
| 974 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 975 | for (;;) { |
| 976 | spin_lock(&tbl->slot_tbl_lock); |
| 977 | /* The state manager will wait until the slot table is empty */ |
| 978 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 979 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 980 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 981 | slot = nfs4_alloc_slot(tbl); |
| 982 | if (IS_ERR(slot)) { |
| 983 | /* Try again in 1/4 second */ |
| 984 | if (slot == ERR_PTR(-ENOMEM)) |
| 985 | task->tk_timeout = HZ >> 2; |
| 986 | goto out_sleep; |
| 987 | } |
| 988 | spin_unlock(&tbl->slot_tbl_lock); |
| 989 | |
| 990 | if (likely(!slot->interrupted)) |
| 991 | break; |
| 992 | nfs4_sequence_process_interrupted(client, |
| 993 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 994 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 995 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 996 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 997 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 998 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 999 | out_start: |
| 1000 | rpc_call_start(task); |
| 1001 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 1002 | |
| 1003 | out_sleep: |
| 1004 | if (args->sa_privileged) |
| 1005 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 1006 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 1007 | else |
| 1008 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 1009 | spin_unlock(&tbl->slot_tbl_lock); |
| 1010 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1011 | } |
| 1012 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 1013 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1014 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1015 | { |
| 1016 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 1017 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1018 | data->seq_args, data->seq_res, task); |
| 1019 | } |
| 1020 | |
| 1021 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1022 | { |
| 1023 | struct nfs4_call_sync_data *data = calldata; |
| 1024 | nfs4_sequence_done(task, data->seq_res); |
| 1025 | } |
| 1026 | |
| 1027 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1028 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1029 | .rpc_call_done = nfs40_call_sync_done, |
| 1030 | }; |
| 1031 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1032 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1033 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1034 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1035 | struct nfs4_sequence_args *args, |
| 1036 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1037 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1038 | int ret; |
| 1039 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1040 | struct nfs_client *clp = server->nfs_client; |
| 1041 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1042 | .seq_server = server, |
| 1043 | .seq_args = args, |
| 1044 | .seq_res = res, |
| 1045 | }; |
| 1046 | struct rpc_task_setup task_setup = { |
| 1047 | .rpc_client = clnt, |
| 1048 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1049 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | .callback_data = &data |
| 1051 | }; |
| 1052 | |
| 1053 | task = rpc_run_task(&task_setup); |
| 1054 | if (IS_ERR(task)) |
| 1055 | ret = PTR_ERR(task); |
| 1056 | else { |
| 1057 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1058 | rpc_put_task(task); |
| 1059 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1060 | return ret; |
| 1061 | } |
| 1062 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1063 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1064 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1065 | struct rpc_message *msg, |
| 1066 | struct nfs4_sequence_args *args, |
| 1067 | struct nfs4_sequence_res *res, |
| 1068 | int cache_reply) |
| 1069 | { |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 1070 | nfs4_init_sequence(args, res, cache_reply, 0); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1071 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1074 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1075 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
| 1077 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1078 | |
| 1079 | spin_lock(&dir->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 1080 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
| 1081 | | NFS_INO_INVALID_MTIME |
| 1082 | | NFS_INO_INVALID_DATA; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1083 | if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1084 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1085 | nfsi->attrtimeo_timestamp = jiffies; |
| 1086 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | nfs_force_lookup_revalidate(dir); |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1088 | if (cinfo->before != inode_peek_iversion_raw(dir)) |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1089 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1090 | NFS_INO_INVALID_ACL; |
| 1091 | } |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 1092 | inode_set_iversion_raw(dir, cinfo->after); |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1093 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1094 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1095 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | spin_unlock(&dir->i_lock); |
| 1097 | } |
| 1098 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1099 | struct nfs4_open_createattrs { |
| 1100 | struct nfs4_label *label; |
| 1101 | struct iattr *sattr; |
| 1102 | const __u32 verf[2]; |
| 1103 | }; |
| 1104 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1105 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1106 | int err, struct nfs4_exception *exception) |
| 1107 | { |
| 1108 | if (err != -EINVAL) |
| 1109 | return false; |
| 1110 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1111 | return false; |
| 1112 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1113 | exception->retry = 1; |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1117 | static u32 |
| 1118 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1119 | fmode_t fmode, int openflags) |
| 1120 | { |
| 1121 | u32 res = 0; |
| 1122 | |
| 1123 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1124 | case FMODE_READ: |
| 1125 | res = NFS4_SHARE_ACCESS_READ; |
| 1126 | break; |
| 1127 | case FMODE_WRITE: |
| 1128 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1129 | break; |
| 1130 | case FMODE_READ|FMODE_WRITE: |
| 1131 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1132 | } |
| 1133 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1134 | goto out; |
| 1135 | /* Want no delegation if we're using O_DIRECT */ |
| 1136 | if (openflags & O_DIRECT) |
| 1137 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1138 | out: |
| 1139 | return res; |
| 1140 | } |
| 1141 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1142 | static enum open_claim_type4 |
| 1143 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1144 | enum open_claim_type4 claim) |
| 1145 | { |
| 1146 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1147 | return claim; |
| 1148 | switch (claim) { |
| 1149 | default: |
| 1150 | return claim; |
| 1151 | case NFS4_OPEN_CLAIM_FH: |
| 1152 | return NFS4_OPEN_CLAIM_NULL; |
| 1153 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1154 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1155 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1156 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1157 | } |
| 1158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | { |
| 1162 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1163 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1164 | p->o_res.seqid = p->o_arg.seqid; |
| 1165 | p->c_res.seqid = p->c_arg.seqid; |
| 1166 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1167 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1168 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1169 | 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] | 1170 | } |
| 1171 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1172 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1174 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1175 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1176 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1177 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1178 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1179 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1180 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1181 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1182 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | struct nfs4_opendata *p; |
| 1184 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1185 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1186 | if (p == NULL) |
| 1187 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1188 | |
| 1189 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1190 | if (IS_ERR(p->f_label)) |
| 1191 | goto err_free_p; |
| 1192 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1193 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1194 | if (IS_ERR(p->a_label)) |
| 1195 | goto err_free_f; |
| 1196 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1197 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1198 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1199 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1200 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1201 | nfs_sb_active(dentry->d_sb); |
| 1202 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1203 | p->dir = parent; |
| 1204 | p->owner = sp; |
| 1205 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1206 | p->o_arg.open_flags = flags; |
| 1207 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1208 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1209 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1210 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1211 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1212 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1213 | * will return permission denied for all bits until close */ |
| 1214 | if (!(flags & O_EXCL)) { |
| 1215 | /* ask server to check for all possible rights as results |
| 1216 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1217 | switch (p->o_arg.claim) { |
| 1218 | default: |
| 1219 | break; |
| 1220 | case NFS4_OPEN_CLAIM_NULL: |
| 1221 | case NFS4_OPEN_CLAIM_FH: |
| 1222 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1223 | NFS4_ACCESS_MODIFY | |
| 1224 | NFS4_ACCESS_EXTEND | |
| 1225 | NFS4_ACCESS_EXECUTE; |
| 1226 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1227 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1228 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1229 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1230 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1231 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1232 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1233 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1234 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1235 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1236 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1237 | case NFS4_OPEN_CLAIM_NULL: |
| 1238 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1239 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1240 | p->o_arg.fh = NFS_FH(dir); |
| 1241 | break; |
| 1242 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1243 | case NFS4_OPEN_CLAIM_FH: |
| 1244 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1245 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1246 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1247 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1248 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1249 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1250 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1251 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1252 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1253 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1254 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1255 | p->c_arg.fh = &p->o_res.fh; |
| 1256 | p->c_arg.stateid = &p->o_res.stateid; |
| 1257 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1258 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1259 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1260 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1261 | |
| 1262 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1263 | nfs4_label_free(p->a_label); |
| 1264 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1265 | nfs4_label_free(p->f_label); |
| 1266 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | kfree(p); |
| 1268 | err: |
| 1269 | dput(parent); |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1273 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1274 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1275 | struct nfs4_opendata *p = container_of(kref, |
| 1276 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1277 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | |
Fred Isaman | 30ae241 | 2016-10-18 13:39:51 -0400 | [diff] [blame] | 1279 | nfs4_lgopen_release(p->lgp); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1280 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1281 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1282 | if (p->state != NULL) |
| 1283 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1284 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1285 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1286 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1287 | nfs4_label_free(p->f_label); |
| 1288 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1289 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1290 | dput(p->dentry); |
| 1291 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1292 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1293 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1294 | kfree(p); |
| 1295 | } |
| 1296 | |
| 1297 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1298 | { |
| 1299 | if (p != NULL) |
| 1300 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1303 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1304 | fmode_t fmode) |
| 1305 | { |
| 1306 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1307 | case FMODE_READ|FMODE_WRITE: |
| 1308 | return state->n_rdwr != 0; |
| 1309 | case FMODE_WRITE: |
| 1310 | return state->n_wronly != 0; |
| 1311 | case FMODE_READ: |
| 1312 | return state->n_rdonly != 0; |
| 1313 | } |
| 1314 | WARN_ON_ONCE(1); |
| 1315 | return false; |
| 1316 | } |
| 1317 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | 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] | 1319 | { |
| 1320 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1321 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1322 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1323 | goto out; |
| 1324 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1325 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1326 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1327 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1328 | break; |
| 1329 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1330 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1331 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1334 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1335 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1336 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1337 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1338 | return ret; |
| 1339 | } |
| 1340 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1341 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1342 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1343 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1344 | if (delegation == NULL) |
| 1345 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1347 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1348 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1349 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1350 | switch (claim) { |
| 1351 | case NFS4_OPEN_CLAIM_NULL: |
| 1352 | case NFS4_OPEN_CLAIM_FH: |
| 1353 | break; |
| 1354 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1355 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1356 | break; |
| 1357 | default: |
| 1358 | return 0; |
| 1359 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1360 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1361 | return 1; |
| 1362 | } |
| 1363 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1364 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1365 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1366 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1367 | case FMODE_WRITE: |
| 1368 | state->n_wronly++; |
| 1369 | break; |
| 1370 | case FMODE_READ: |
| 1371 | state->n_rdonly++; |
| 1372 | break; |
| 1373 | case FMODE_READ|FMODE_WRITE: |
| 1374 | state->n_rdwr++; |
| 1375 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1376 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1379 | #ifdef CONFIG_NFS_V4_1 |
| 1380 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1381 | { |
| 1382 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1383 | return true; |
| 1384 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1385 | return true; |
| 1386 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1387 | return true; |
| 1388 | return false; |
| 1389 | } |
| 1390 | #endif /* CONFIG_NFS_V4_1 */ |
| 1391 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1392 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1393 | { |
| 1394 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1395 | wake_up_all(&state->waitq); |
| 1396 | } |
| 1397 | |
| 1398 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1399 | const nfs4_stateid *stateid) |
| 1400 | { |
| 1401 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1402 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1403 | |
| 1404 | if (stateid_seqid == state_seqid + 1U || |
| 1405 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1406 | nfs_state_log_update_open_stateid(state); |
| 1407 | else |
| 1408 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1409 | } |
| 1410 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1411 | 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] | 1412 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1413 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1414 | bool need_recover = false; |
| 1415 | |
| 1416 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1417 | need_recover = true; |
| 1418 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1419 | need_recover = true; |
| 1420 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1421 | need_recover = true; |
| 1422 | if (need_recover) |
| 1423 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1424 | } |
| 1425 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1426 | /* |
| 1427 | * Check for whether or not the caller may update the open stateid |
| 1428 | * to the value passed in by stateid. |
| 1429 | * |
| 1430 | * Note: This function relies heavily on the server implementing |
| 1431 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1432 | * correctly. |
| 1433 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1434 | * are then incremented on every state transition. |
| 1435 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1436 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1437 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1438 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1439 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1440 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1441 | if (stateid->seqid == cpu_to_be32(1)) |
| 1442 | nfs_state_log_update_open_stateid(state); |
| 1443 | else |
| 1444 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1445 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1446 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1447 | |
| 1448 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1449 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1450 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1451 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
| 1454 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1455 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1456 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1457 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1458 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1459 | if (state->n_wronly) |
| 1460 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1461 | if (state->n_rdonly) |
| 1462 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1463 | if (state->n_rdwr) |
| 1464 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1465 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1466 | } |
| 1467 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1468 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1469 | nfs4_stateid *stateid, fmode_t fmode) |
| 1470 | { |
| 1471 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1472 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1473 | case FMODE_WRITE: |
| 1474 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1475 | break; |
| 1476 | case FMODE_READ: |
| 1477 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1478 | break; |
| 1479 | case 0: |
| 1480 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1481 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1482 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1483 | } |
| 1484 | if (stateid == NULL) |
| 1485 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1486 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1487 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1488 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1489 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1490 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1491 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1492 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1493 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1494 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1495 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1496 | out: |
| 1497 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1498 | } |
| 1499 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1500 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1501 | nfs4_stateid *arg_stateid, |
| 1502 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1503 | { |
| 1504 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1505 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1506 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1507 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1508 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1509 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1510 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1513 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1514 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1515 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1516 | DEFINE_WAIT(wait); |
| 1517 | int status = 0; |
| 1518 | for (;;) { |
| 1519 | |
| 1520 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1521 | return; |
| 1522 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1523 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1524 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1525 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1526 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1527 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1528 | break; |
| 1529 | |
| 1530 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1531 | /* |
| 1532 | * Ensure we process the state changes in the same order |
| 1533 | * in which the server processed them by delaying the |
| 1534 | * update of the stateid until we are in sequence. |
| 1535 | */ |
| 1536 | write_sequnlock(&state->seqlock); |
| 1537 | spin_unlock(&state->owner->so_lock); |
| 1538 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1539 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1540 | if (!signal_pending(current)) { |
| 1541 | if (schedule_timeout(5*HZ) == 0) |
| 1542 | status = -EAGAIN; |
| 1543 | else |
| 1544 | status = 0; |
| 1545 | } else |
| 1546 | status = -EINTR; |
| 1547 | finish_wait(&state->waitq, &wait); |
| 1548 | rcu_read_lock(); |
| 1549 | spin_lock(&state->owner->so_lock); |
| 1550 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1551 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1552 | |
Trond Myklebust | e1fff5d | 2017-11-07 13:10:46 -0500 | [diff] [blame] | 1553 | if (test_bit(NFS_OPEN_STATE, &state->flags) && |
| 1554 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1555 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1556 | nfs_test_and_clear_all_open_stateid(state); |
| 1557 | } |
| 1558 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1559 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1560 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1561 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1562 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1563 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1566 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1567 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1568 | fmode_t fmode, |
| 1569 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1571 | /* |
| 1572 | * Protect the call to nfs4_state_set_mode_locked and |
| 1573 | * serialise the stateid update |
| 1574 | */ |
| 1575 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1576 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1577 | switch (fmode) { |
| 1578 | case FMODE_READ: |
| 1579 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1580 | break; |
| 1581 | case FMODE_WRITE: |
| 1582 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1583 | break; |
| 1584 | case FMODE_READ|FMODE_WRITE: |
| 1585 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1586 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1587 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1588 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1592 | const nfs4_stateid *deleg_stateid, |
| 1593 | fmode_t fmode) |
| 1594 | { |
| 1595 | /* |
| 1596 | * Protect the call to nfs4_state_set_mode_locked and |
| 1597 | * serialise the stateid update |
| 1598 | */ |
| 1599 | write_seqlock(&state->seqlock); |
| 1600 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1601 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1602 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1605 | static int update_open_stateid(struct nfs4_state *state, |
| 1606 | const nfs4_stateid *open_stateid, |
| 1607 | const nfs4_stateid *delegation, |
| 1608 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1609 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1610 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1611 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1612 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1613 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1614 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1615 | int ret = 0; |
| 1616 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1617 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1618 | |
| 1619 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1620 | spin_lock(&state->owner->so_lock); |
| 1621 | if (open_stateid != NULL) { |
| 1622 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1623 | ret = 1; |
| 1624 | } |
| 1625 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1626 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1627 | if (deleg_cur == NULL) |
| 1628 | goto no_delegation; |
| 1629 | |
| 1630 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1631 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1632 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1633 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1634 | goto no_delegation_unlock; |
| 1635 | |
| 1636 | if (delegation == NULL) |
| 1637 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1638 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1639 | goto no_delegation_unlock; |
| 1640 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1641 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1642 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1643 | ret = 1; |
| 1644 | no_delegation_unlock: |
| 1645 | spin_unlock(&deleg_cur->lock); |
| 1646 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1647 | if (ret) |
| 1648 | update_open_stateflags(state, fmode); |
| 1649 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1650 | rcu_read_unlock(); |
| 1651 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1652 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1653 | nfs4_schedule_state_manager(clp); |
| 1654 | if (freeme.type != 0) |
| 1655 | nfs4_test_and_free_stateid(server, &freeme, |
| 1656 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1657 | |
| 1658 | return ret; |
| 1659 | } |
| 1660 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1661 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1662 | const nfs4_stateid *stateid) |
| 1663 | { |
| 1664 | struct nfs4_state *state = lsp->ls_state; |
| 1665 | bool ret = false; |
| 1666 | |
| 1667 | spin_lock(&state->state_lock); |
| 1668 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1669 | goto out_noupdate; |
| 1670 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1671 | goto out_noupdate; |
| 1672 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1673 | ret = true; |
| 1674 | out_noupdate: |
| 1675 | spin_unlock(&state->state_lock); |
| 1676 | return ret; |
| 1677 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1678 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1679 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1680 | { |
| 1681 | struct nfs_delegation *delegation; |
| 1682 | |
Trond Myklebust | f508624 | 2018-03-20 16:43:13 -0400 | [diff] [blame] | 1683 | fmode &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1684 | rcu_read_lock(); |
| 1685 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1686 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1687 | rcu_read_unlock(); |
| 1688 | return; |
| 1689 | } |
| 1690 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1691 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1694 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1695 | { |
| 1696 | struct nfs4_state *state = opendata->state; |
| 1697 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1698 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1699 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1700 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1701 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1702 | nfs4_stateid stateid; |
| 1703 | int ret = -EAGAIN; |
| 1704 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1705 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1706 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1707 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1708 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1709 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1710 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1711 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1712 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1713 | rcu_read_lock(); |
| 1714 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1715 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1716 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1717 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1718 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1720 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1721 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1722 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1723 | if (!opendata->is_recover) { |
| 1724 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1725 | if (ret != 0) |
| 1726 | goto out; |
| 1727 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1728 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1729 | |
| 1730 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1731 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1732 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1733 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1734 | out: |
| 1735 | return ERR_PTR(ret); |
| 1736 | out_return_state: |
| 1737 | atomic_inc(&state->count); |
| 1738 | return state; |
| 1739 | } |
| 1740 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1741 | static void |
| 1742 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1743 | { |
| 1744 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1745 | struct nfs_delegation *delegation; |
| 1746 | int delegation_flags = 0; |
| 1747 | |
| 1748 | rcu_read_lock(); |
| 1749 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1750 | if (delegation) |
| 1751 | delegation_flags = delegation->flags; |
| 1752 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1753 | switch (data->o_arg.claim) { |
| 1754 | default: |
| 1755 | break; |
| 1756 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1757 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1758 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1759 | "returning a delegation for " |
| 1760 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1761 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1762 | return; |
| 1763 | } |
| 1764 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1765 | nfs_inode_set_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1766 | data->owner->so_cred, |
| 1767 | data->o_res.delegation_type, |
| 1768 | &data->o_res.delegation, |
| 1769 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1770 | else |
| 1771 | nfs_inode_reclaim_delegation(state->inode, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 1772 | data->owner->so_cred, |
| 1773 | data->o_res.delegation_type, |
| 1774 | &data->o_res.delegation, |
| 1775 | data->o_res.pagemod_limit); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1780 | * and update the nfs4_state. |
| 1781 | */ |
| 1782 | static struct nfs4_state * |
| 1783 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1784 | { |
| 1785 | struct inode *inode = data->state->inode; |
| 1786 | struct nfs4_state *state = data->state; |
| 1787 | int ret; |
| 1788 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1789 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1790 | if (data->rpc_status) |
| 1791 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1792 | /* cached opens have already been processed */ |
| 1793 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1794 | } |
| 1795 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1796 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1797 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1798 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1799 | |
| 1800 | if (data->o_res.delegation_type != 0) |
| 1801 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1802 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1803 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1804 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1805 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1806 | |
| 1807 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1810 | static struct inode * |
| 1811 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1812 | { |
| 1813 | struct inode *inode; |
| 1814 | |
| 1815 | switch (data->o_arg.claim) { |
| 1816 | case NFS4_OPEN_CLAIM_NULL: |
| 1817 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1818 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1819 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1820 | return ERR_PTR(-EAGAIN); |
| 1821 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1822 | &data->f_attr, data->f_label); |
| 1823 | break; |
| 1824 | default: |
| 1825 | inode = d_inode(data->dentry); |
| 1826 | ihold(inode); |
| 1827 | nfs_refresh_inode(inode, &data->f_attr); |
| 1828 | } |
| 1829 | return inode; |
| 1830 | } |
| 1831 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1832 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1833 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1834 | { |
| 1835 | struct nfs4_state *state; |
| 1836 | struct inode *inode; |
| 1837 | |
| 1838 | inode = nfs4_opendata_get_inode(data); |
| 1839 | if (IS_ERR(inode)) |
| 1840 | return ERR_CAST(inode); |
| 1841 | if (data->state != NULL && data->state->inode == inode) { |
| 1842 | state = data->state; |
| 1843 | atomic_inc(&state->count); |
| 1844 | } else |
| 1845 | state = nfs4_get_open_state(inode, data->owner); |
| 1846 | iput(inode); |
| 1847 | if (state == NULL) |
| 1848 | state = ERR_PTR(-ENOMEM); |
| 1849 | return state; |
| 1850 | } |
| 1851 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1852 | static struct nfs4_state * |
| 1853 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1854 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1855 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1856 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1857 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1858 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1859 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1860 | goto out; |
| 1861 | } |
| 1862 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1863 | state = nfs4_opendata_find_nfs4_state(data); |
| 1864 | if (IS_ERR(state)) |
| 1865 | goto out; |
| 1866 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1867 | if (data->o_res.delegation_type != 0) |
| 1868 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1869 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1870 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1871 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1872 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1873 | return state; |
| 1874 | } |
| 1875 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1876 | static struct nfs4_state * |
| 1877 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1878 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1879 | struct nfs4_state *ret; |
| 1880 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1881 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1882 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1883 | else |
| 1884 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1885 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1886 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1887 | } |
| 1888 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1889 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1890 | { |
| 1891 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1892 | struct nfs_open_context *ctx; |
| 1893 | |
| 1894 | spin_lock(&state->inode->i_lock); |
| 1895 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1896 | if (ctx->state != state) |
| 1897 | continue; |
| 1898 | get_nfs_open_context(ctx); |
| 1899 | spin_unlock(&state->inode->i_lock); |
| 1900 | return ctx; |
| 1901 | } |
| 1902 | spin_unlock(&state->inode->i_lock); |
| 1903 | return ERR_PTR(-ENOENT); |
| 1904 | } |
| 1905 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1906 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1907 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1908 | { |
| 1909 | struct nfs4_opendata *opendata; |
| 1910 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1911 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1912 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1913 | if (opendata == NULL) |
| 1914 | return ERR_PTR(-ENOMEM); |
| 1915 | opendata->state = state; |
| 1916 | atomic_inc(&state->count); |
| 1917 | return opendata; |
| 1918 | } |
| 1919 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1920 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1921 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1923 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | int ret; |
| 1925 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1926 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1927 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1928 | opendata->o_arg.open_flags = 0; |
| 1929 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1930 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1931 | NFS_SB(opendata->dentry->d_sb), |
| 1932 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1933 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1934 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1935 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1936 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1937 | if (ret != 0) |
| 1938 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1939 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1940 | if (IS_ERR(newstate)) |
| 1941 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | if (newstate != opendata->state) |
| 1943 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1944 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1945 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1949 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1950 | int ret; |
| 1951 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1952 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1953 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1954 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1955 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1956 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1957 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1958 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1959 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1960 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1961 | if (ret != 0) |
| 1962 | return ret; |
| 1963 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1964 | if (ret != 0) |
| 1965 | return ret; |
| 1966 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1967 | if (ret != 0) |
| 1968 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1969 | /* |
| 1970 | * We may have performed cached opens for all three recoveries. |
| 1971 | * Check if we need to update the current stateid. |
| 1972 | */ |
| 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_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1975 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1976 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1977 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1978 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1979 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1980 | return 0; |
| 1981 | } |
| 1982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | /* |
| 1984 | * OPEN_RECLAIM: |
| 1985 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1987 | 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] | 1988 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1989 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1990 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1991 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | int status; |
| 1993 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1994 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1995 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1996 | if (IS_ERR(opendata)) |
| 1997 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1998 | rcu_read_lock(); |
| 1999 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 2000 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 2001 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 2002 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2003 | opendata->o_arg.u.delegation_type = delegation_type; |
| 2004 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2005 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | return status; |
| 2007 | } |
| 2008 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2009 | 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] | 2010 | { |
| 2011 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2012 | struct nfs4_exception exception = { }; |
| 2013 | int err; |
| 2014 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2015 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2016 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2017 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2018 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2019 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | } while (exception.retry); |
| 2023 | return err; |
| 2024 | } |
| 2025 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2026 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2027 | { |
| 2028 | struct nfs_open_context *ctx; |
| 2029 | int ret; |
| 2030 | |
| 2031 | ctx = nfs4_state_find_open_context(state); |
| 2032 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2033 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2034 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2035 | put_nfs_open_context(ctx); |
| 2036 | return ret; |
| 2037 | } |
| 2038 | |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2039 | 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] | 2040 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2041 | switch (err) { |
| 2042 | default: |
| 2043 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2044 | "%d.\n", __func__, err); |
| 2045 | case 0: |
| 2046 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2047 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2048 | case -ESTALE: |
| 2049 | break; |
| 2050 | case -NFS4ERR_BADSESSION: |
| 2051 | case -NFS4ERR_BADSLOT: |
| 2052 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2053 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2054 | case -NFS4ERR_DEADSESSION: |
| 2055 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2056 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2057 | return -EAGAIN; |
| 2058 | case -NFS4ERR_STALE_CLIENTID: |
| 2059 | case -NFS4ERR_STALE_STATEID: |
| 2060 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2061 | /* Don't recall a delegation if it was lost */ |
| 2062 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2063 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2064 | case -NFS4ERR_MOVED: |
| 2065 | nfs4_schedule_migration_recovery(server); |
| 2066 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2067 | case -NFS4ERR_LEASE_MOVED: |
| 2068 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2069 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2070 | case -NFS4ERR_DELEG_REVOKED: |
| 2071 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2072 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2073 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2074 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2075 | nfs_inode_find_state_and_recover(state->inode, |
| 2076 | stateid); |
| 2077 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2078 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2079 | case -NFS4ERR_DELAY: |
| 2080 | case -NFS4ERR_GRACE: |
| 2081 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2082 | ssleep(1); |
| 2083 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2084 | case -ENOMEM: |
| 2085 | case -NFS4ERR_DENIED: |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2086 | if (fl) { |
| 2087 | struct nfs4_lock_state *lsp = fl->fl_u.nfs4_fl.owner; |
| 2088 | if (lsp) |
| 2089 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2090 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2091 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | return err; |
| 2094 | } |
| 2095 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2096 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2097 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2098 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2099 | { |
| 2100 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2101 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2102 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2103 | |
| 2104 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2105 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2106 | if (IS_ERR(opendata)) |
| 2107 | return PTR_ERR(opendata); |
| 2108 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2109 | write_seqlock(&state->seqlock); |
| 2110 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2111 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2112 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2113 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2114 | case FMODE_READ|FMODE_WRITE: |
| 2115 | case FMODE_WRITE: |
| 2116 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2117 | if (err) |
| 2118 | break; |
| 2119 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2120 | if (err) |
| 2121 | break; |
| 2122 | case FMODE_READ: |
| 2123 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2124 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2125 | nfs4_opendata_put(opendata); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 2126 | return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2127 | } |
| 2128 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2129 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2130 | { |
| 2131 | struct nfs4_opendata *data = calldata; |
| 2132 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2133 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2134 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2135 | } |
| 2136 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2137 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2138 | { |
| 2139 | struct nfs4_opendata *data = calldata; |
| 2140 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2141 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2143 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2144 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2145 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2146 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2147 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2148 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2149 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | static void nfs4_open_confirm_release(void *calldata) |
| 2153 | { |
| 2154 | struct nfs4_opendata *data = calldata; |
| 2155 | struct nfs4_state *state = NULL; |
| 2156 | |
| 2157 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2158 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2159 | goto out_free; |
| 2160 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2161 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2162 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2163 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2164 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2165 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2166 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2167 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2171 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2172 | .rpc_call_done = nfs4_open_confirm_done, |
| 2173 | .rpc_release = nfs4_open_confirm_release, |
| 2174 | }; |
| 2175 | |
| 2176 | /* |
| 2177 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2178 | */ |
| 2179 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2180 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2181 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2182 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2183 | struct rpc_message msg = { |
| 2184 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2185 | .rpc_argp = &data->c_arg, |
| 2186 | .rpc_resp = &data->c_res, |
| 2187 | .rpc_cred = data->owner->so_cred, |
| 2188 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | struct rpc_task_setup task_setup_data = { |
| 2190 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2191 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2192 | .callback_ops = &nfs4_open_confirm_ops, |
| 2193 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2194 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2195 | .flags = RPC_TASK_ASYNC, |
| 2196 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | int status; |
| 2198 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 2199 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1, |
| 2200 | data->is_recover); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2201 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2202 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2203 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2204 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2205 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2206 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2207 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2208 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2209 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2210 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2211 | smp_wmb(); |
| 2212 | } else |
| 2213 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2214 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | return status; |
| 2216 | } |
| 2217 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2218 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2220 | struct nfs4_opendata *data = calldata; |
| 2221 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2222 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2223 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2224 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2225 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2226 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2227 | /* |
| 2228 | * Check if we still need to send an OPEN call, or if we can use |
| 2229 | * a delegation instead. |
| 2230 | */ |
| 2231 | if (data->state != NULL) { |
| 2232 | struct nfs_delegation *delegation; |
| 2233 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2234 | 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] | 2235 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2236 | rcu_read_lock(); |
| 2237 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2238 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2239 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2240 | rcu_read_unlock(); |
| 2241 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2242 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2243 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2244 | switch (claim) { |
| 2245 | default: |
| 2246 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2247 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2248 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2249 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2250 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2251 | case NFS4_OPEN_CLAIM_FH: |
| 2252 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2253 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2254 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2255 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2256 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2257 | &data->o_res.seq_res, |
| 2258 | task) != 0) |
| 2259 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2260 | |
| 2261 | /* Set the create mode (note dependency on the session type) */ |
| 2262 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2263 | if (data->o_arg.open_flags & O_EXCL) { |
| 2264 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2265 | if (nfs4_has_persistent_session(clp)) |
| 2266 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2267 | else if (clp->cl_mvops->minor_version > 0) |
| 2268 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2269 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2270 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2271 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2272 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2273 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2274 | out_no_action: |
| 2275 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2276 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2277 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2278 | } |
| 2279 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2280 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2281 | { |
| 2282 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2284 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2285 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2286 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2287 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2288 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2289 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2290 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2291 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2292 | case S_IFREG: |
| 2293 | break; |
| 2294 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2295 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2296 | break; |
| 2297 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2298 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2299 | break; |
| 2300 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2301 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2302 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2303 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2304 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2305 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2306 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2307 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2308 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2309 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2310 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2311 | static void nfs4_open_release(void *calldata) |
| 2312 | { |
| 2313 | struct nfs4_opendata *data = calldata; |
| 2314 | struct nfs4_state *state = NULL; |
| 2315 | |
| 2316 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2317 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | goto out_free; |
| 2319 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2320 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2321 | goto out_free; |
| 2322 | /* In case we need an open_confirm, no cleanup! */ |
| 2323 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2324 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2325 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2326 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2327 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2328 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2329 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2333 | .rpc_call_prepare = nfs4_open_prepare, |
| 2334 | .rpc_call_done = nfs4_open_done, |
| 2335 | .rpc_release = nfs4_open_release, |
| 2336 | }; |
| 2337 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2338 | static int nfs4_run_open_task(struct nfs4_opendata *data, |
| 2339 | struct nfs_open_context *ctx) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2340 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2341 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2342 | struct nfs_server *server = NFS_SERVER(dir); |
| 2343 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2344 | struct nfs_openres *o_res = &data->o_res; |
| 2345 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2346 | struct rpc_message msg = { |
| 2347 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2348 | .rpc_argp = o_arg, |
| 2349 | .rpc_resp = o_res, |
| 2350 | .rpc_cred = data->owner->so_cred, |
| 2351 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2352 | struct rpc_task_setup task_setup_data = { |
| 2353 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2354 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2355 | .callback_ops = &nfs4_open_ops, |
| 2356 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2357 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2358 | .flags = RPC_TASK_ASYNC, |
| 2359 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2360 | int status; |
| 2361 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2362 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2363 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2364 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2365 | data->cancelled = false; |
| 2366 | data->is_recover = false; |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2367 | if (!ctx) { |
| 2368 | 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] | 2369 | data->is_recover = true; |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2370 | } else { |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2371 | 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] | 2372 | pnfs_lgopen_prepare(data, ctx); |
| 2373 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2374 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2375 | if (IS_ERR(task)) |
| 2376 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2377 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2378 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2379 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2380 | smp_wmb(); |
| 2381 | } else |
| 2382 | status = data->rpc_status; |
| 2383 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2384 | |
| 2385 | return status; |
| 2386 | } |
| 2387 | |
| 2388 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2389 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2390 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2391 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2392 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2393 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2394 | status = nfs4_run_open_task(data, NULL); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2395 | if (status != 0 || !data->rpc_done) |
| 2396 | return status; |
| 2397 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2398 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2399 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2400 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2401 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2402 | |
| 2403 | return status; |
| 2404 | } |
| 2405 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2406 | /* |
| 2407 | * Additional permission checks in order to distinguish between an |
| 2408 | * open for read, and an open for execute. This works around the |
| 2409 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2410 | * the same. |
| 2411 | * Note that in the non-execute case, we want to turn off permission |
| 2412 | * checking if we just created a new file (POSIX open() semantics). |
| 2413 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2414 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2415 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2416 | struct nfs4_state *state, fmode_t fmode, |
| 2417 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2418 | { |
| 2419 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2420 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2421 | |
| 2422 | /* access call failed or for some reason the server doesn't |
| 2423 | * support any access modes -- defer access call until later */ |
| 2424 | if (opendata->o_res.access_supported == 0) |
| 2425 | return 0; |
| 2426 | |
| 2427 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2428 | /* |
| 2429 | * Use openflags to check for exec, because fmode won't |
| 2430 | * always have FMODE_EXEC set when file open for exec. |
| 2431 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2432 | if (openflags & __FMODE_EXEC) { |
| 2433 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2434 | if (S_ISDIR(state->inode->i_mode)) |
| 2435 | mask = NFS4_ACCESS_LOOKUP; |
| 2436 | else |
| 2437 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2438 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2439 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2440 | |
| 2441 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2442 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2443 | nfs_access_add_cache(state->inode, &cache); |
| 2444 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2445 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2446 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2447 | return 0; |
| 2448 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2449 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2452 | /* |
| 2453 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2454 | */ |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2455 | static int _nfs4_proc_open(struct nfs4_opendata *data, |
| 2456 | struct nfs_open_context *ctx) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2457 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2458 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2459 | struct nfs_server *server = NFS_SERVER(dir); |
| 2460 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2461 | struct nfs_openres *o_res = &data->o_res; |
| 2462 | int status; |
| 2463 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2464 | status = nfs4_run_open_task(data, ctx); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2465 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2466 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2467 | if (status != 0) { |
| 2468 | if (status == -NFS4ERR_BADNAME && |
| 2469 | !(o_arg->open_flags & O_CREAT)) |
| 2470 | return -ENOENT; |
| 2471 | return status; |
| 2472 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2473 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2474 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2475 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2476 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2477 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2478 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2479 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2480 | data->file_created = true; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 2481 | if (data->file_created || |
| 2482 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2483 | update_changeattr(dir, &o_res->cinfo, |
| 2484 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2485 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2486 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2487 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2489 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2491 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2493 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2494 | nfs4_sequence_free_slot(&o_res->seq_res); |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 2495 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, |
| 2496 | o_res->f_label, NULL); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2497 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2498 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | /* |
| 2502 | * OPEN_EXPIRED: |
| 2503 | * reclaim state on the server after a network partition. |
| 2504 | * Assumes caller holds the appropriate lock |
| 2505 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2506 | 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] | 2507 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2508 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2509 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2511 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2512 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2513 | if (IS_ERR(opendata)) |
| 2514 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2515 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2516 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2517 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2518 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2519 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2522 | 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] | 2523 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2524 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2525 | struct nfs4_exception exception = { }; |
| 2526 | int err; |
| 2527 | |
| 2528 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2529 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2530 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2531 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2532 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2533 | switch (err) { |
| 2534 | default: |
| 2535 | goto out; |
| 2536 | case -NFS4ERR_GRACE: |
| 2537 | case -NFS4ERR_DELAY: |
| 2538 | nfs4_handle_exception(server, err, &exception); |
| 2539 | err = 0; |
| 2540 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2541 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2542 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2543 | return err; |
| 2544 | } |
| 2545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2547 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2549 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2551 | ctx = nfs4_state_find_open_context(state); |
| 2552 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2553 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2554 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2555 | put_nfs_open_context(ctx); |
| 2556 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2559 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2560 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2561 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2562 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2563 | write_seqlock(&state->seqlock); |
| 2564 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2565 | write_sequnlock(&state->seqlock); |
| 2566 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2567 | } |
| 2568 | |
| 2569 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2570 | { |
| 2571 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2572 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2576 | { |
| 2577 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2578 | nfs40_clear_delegation_stateid(state); |
| 2579 | return nfs4_open_expired(sp, state); |
| 2580 | } |
| 2581 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2582 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2583 | nfs4_stateid *stateid, |
| 2584 | struct rpc_cred *cred) |
| 2585 | { |
| 2586 | return -NFS4ERR_BAD_STATEID; |
| 2587 | } |
| 2588 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2589 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2590 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2591 | nfs4_stateid *stateid, |
| 2592 | struct rpc_cred *cred) |
| 2593 | { |
| 2594 | int status; |
| 2595 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2596 | switch (stateid->type) { |
| 2597 | default: |
| 2598 | break; |
| 2599 | case NFS4_INVALID_STATEID_TYPE: |
| 2600 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2601 | return -NFS4ERR_BAD_STATEID; |
| 2602 | case NFS4_REVOKED_STATEID_TYPE: |
| 2603 | goto out_free; |
| 2604 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2605 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2606 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2607 | switch (status) { |
| 2608 | case -NFS4ERR_EXPIRED: |
| 2609 | case -NFS4ERR_ADMIN_REVOKED: |
| 2610 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2611 | break; |
| 2612 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2613 | return status; |
| 2614 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2615 | out_free: |
| 2616 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2617 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2618 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2619 | } |
| 2620 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2621 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2622 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2623 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2624 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2625 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2626 | struct rpc_cred *cred; |
| 2627 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2629 | /* Get the delegation credential for use by test/free_stateid */ |
| 2630 | rcu_read_lock(); |
| 2631 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2632 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2633 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2638 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2639 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2640 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2641 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2642 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2643 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2644 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2645 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2646 | cred = get_rpccred(delegation->cred); |
| 2647 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2648 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2649 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2650 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2651 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2652 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2653 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2657 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2658 | * |
| 2659 | * @state: NFSv4 state for an inode |
| 2660 | * |
| 2661 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2662 | * Otherwise a negative NFS4ERR value is returned. |
| 2663 | */ |
| 2664 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2665 | { |
| 2666 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2667 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2668 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2669 | |
| 2670 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2671 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2672 | |
| 2673 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2674 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2675 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2676 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2677 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2678 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2679 | spin_unlock(&state->state_lock); |
| 2680 | |
| 2681 | nfs4_put_lock_state(prev); |
| 2682 | prev = lsp; |
| 2683 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2684 | status = nfs41_test_and_free_expired_stateid(server, |
| 2685 | &lsp->ls_stateid, |
| 2686 | cred); |
| 2687 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2688 | if (status == -NFS4ERR_EXPIRED || |
| 2689 | status == -NFS4ERR_BAD_STATEID) { |
| 2690 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2691 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2692 | if (!recover_lost_locks) |
| 2693 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2694 | } else if (status != NFS_OK) { |
| 2695 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2696 | nfs4_put_lock_state(prev); |
| 2697 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2698 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2699 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2700 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2701 | } |
| 2702 | spin_unlock(&state->state_lock); |
| 2703 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2704 | out: |
| 2705 | return ret; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2709 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2710 | * |
| 2711 | * @state: NFSv4 state for an inode |
| 2712 | * |
| 2713 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2714 | * Otherwise a negative NFS4ERR value is returned. |
| 2715 | */ |
| 2716 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2717 | { |
| 2718 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2719 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2720 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2721 | int status; |
| 2722 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2723 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2724 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2725 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2726 | return NFS_OK; |
| 2727 | return -NFS4ERR_OPENMODE; |
| 2728 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2729 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2730 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2731 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2732 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2733 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2734 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2735 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2736 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2737 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2738 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2739 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2740 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2741 | if (nfs_open_stateid_recover_openmode(state)) |
| 2742 | return -NFS4ERR_OPENMODE; |
| 2743 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2747 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2748 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2749 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2750 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2751 | status = nfs41_check_expired_locks(state); |
| 2752 | if (status != NFS_OK) |
| 2753 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2754 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2755 | if (status != NFS_OK) |
| 2756 | status = nfs4_open_expired(sp, state); |
| 2757 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2758 | } |
| 2759 | #endif |
| 2760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2762 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2763 | * fields corresponding to attributes that were used to store the verifier. |
| 2764 | * Make sure we clobber those fields in the later setattr call |
| 2765 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2766 | static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2767 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2768 | { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2769 | const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; |
| 2770 | __u32 attrset[3]; |
| 2771 | unsigned ret; |
| 2772 | unsigned i; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2773 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2774 | for (i = 0; i < ARRAY_SIZE(attrset); i++) { |
| 2775 | attrset[i] = opendata->o_res.attrset[i]; |
| 2776 | if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) |
| 2777 | attrset[i] &= ~bitmask[i]; |
| 2778 | } |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2779 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2780 | ret = (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE) ? |
| 2781 | sattr->ia_valid : 0; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2782 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2783 | if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { |
| 2784 | if (sattr->ia_valid & ATTR_ATIME_SET) |
| 2785 | ret |= ATTR_ATIME_SET; |
| 2786 | else |
| 2787 | ret |= ATTR_ATIME; |
| 2788 | } |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2789 | |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2790 | if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { |
| 2791 | if (sattr->ia_valid & ATTR_MTIME_SET) |
| 2792 | ret |= ATTR_MTIME_SET; |
| 2793 | else |
| 2794 | ret |= ATTR_MTIME; |
| 2795 | } |
| 2796 | |
| 2797 | if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2798 | *label = NULL; |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2799 | return ret; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2802 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2803 | fmode_t fmode, |
| 2804 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2805 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2806 | { |
| 2807 | struct nfs4_state_owner *sp = opendata->owner; |
| 2808 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2809 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2810 | struct nfs4_state *state; |
| 2811 | unsigned int seq; |
| 2812 | int ret; |
| 2813 | |
| 2814 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2815 | |
Fred Isaman | 3b65a30 | 2016-09-19 10:06:49 -0400 | [diff] [blame] | 2816 | ret = _nfs4_proc_open(opendata, ctx); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2817 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2818 | goto out; |
| 2819 | |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2820 | state = _nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2821 | ret = PTR_ERR(state); |
| 2822 | if (IS_ERR(state)) |
| 2823 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2824 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2825 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2826 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2827 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2828 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2829 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2830 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2831 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2832 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2833 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2834 | alias = d_exact_alias(dentry, state->inode); |
| 2835 | if (!alias) |
| 2836 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2837 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2838 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2839 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2840 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2841 | } |
| 2842 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2843 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2846 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2847 | if (ret != 0) |
| 2848 | goto out; |
| 2849 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2850 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2851 | nfs_inode_attach_open_context(ctx); |
| 2852 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2853 | nfs4_schedule_stateid_recovery(server, state); |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2854 | else |
| 2855 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2856 | } |
Fred Isaman | 2409a97 | 2016-10-06 12:11:21 -0400 | [diff] [blame] | 2857 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2858 | out: |
Trond Myklebust | ae55e59 | 2018-05-22 11:17:16 -0400 | [diff] [blame] | 2859 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2860 | return ret; |
| 2861 | } |
| 2862 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2863 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2864 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2866 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2867 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2868 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2869 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2870 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | { |
| 2872 | struct nfs4_state_owner *sp; |
| 2873 | struct nfs4_state *state = NULL; |
| 2874 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2875 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2876 | struct dentry *dentry = ctx->dentry; |
| 2877 | struct rpc_cred *cred = ctx->cred; |
| 2878 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2879 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2880 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2881 | struct iattr *sattr = c->sattr; |
| 2882 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2883 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2884 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2888 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2889 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2891 | goto out_err; |
| 2892 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2893 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2894 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2895 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2896 | if (d_really_is_positive(dentry)) |
| 2897 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2898 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2899 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2900 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2901 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2902 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2903 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2904 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2906 | if (label) { |
| 2907 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2908 | if (IS_ERR(olabel)) { |
| 2909 | status = PTR_ERR(olabel); |
| 2910 | goto err_opendata_put; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2914 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2915 | if (!opendata->f_attr.mdsthreshold) { |
| 2916 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2917 | if (!opendata->f_attr.mdsthreshold) |
| 2918 | goto err_free_label; |
| 2919 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2920 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2921 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2922 | if (d_really_is_positive(dentry)) |
| 2923 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2924 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2925 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2926 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2927 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2928 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2929 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2930 | 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] | 2931 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2932 | unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2933 | /* |
| 2934 | * send create attributes which was not set by open |
| 2935 | * with an extra setattr. |
| 2936 | */ |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2937 | if (attrs || label) { |
| 2938 | unsigned ia_old = sattr->ia_valid; |
| 2939 | |
| 2940 | sattr->ia_valid = attrs; |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2941 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2942 | status = nfs4_do_setattr(state->inode, cred, |
| 2943 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2944 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2945 | if (status == 0) { |
| 2946 | nfs_setattr_update_inode(state->inode, sattr, |
| 2947 | opendata->o_res.f_attr); |
| 2948 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2949 | } |
Trond Myklebust | 609339c | 2018-03-28 16:18:17 -0400 | [diff] [blame] | 2950 | sattr->ia_valid = ia_old; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2951 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2952 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2953 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2954 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2955 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2956 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2957 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2958 | opendata->f_attr.mdsthreshold = NULL; |
| 2959 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2960 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2961 | nfs4_label_free(olabel); |
| 2962 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2963 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2966 | err_free_label: |
| 2967 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2968 | err_opendata_put: |
| 2969 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2970 | err_put_state_owner: |
| 2971 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | return status; |
| 2974 | } |
| 2975 | |
| 2976 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2977 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2978 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2979 | int flags, |
| 2980 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2981 | struct nfs4_label *label, |
| 2982 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2984 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | struct nfs4_exception exception = { }; |
| 2986 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2987 | struct nfs4_open_createattrs c = { |
| 2988 | .label = label, |
| 2989 | .sattr = sattr, |
| 2990 | .verf = { |
| 2991 | [0] = (__u32)jiffies, |
| 2992 | [1] = (__u32)current->pid, |
| 2993 | }, |
| 2994 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | int status; |
| 2996 | |
| 2997 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2998 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2999 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3000 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | if (status == 0) |
| 3002 | break; |
| 3003 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 3004 | * book-keeping w.r.t. state-changing operations |
| 3005 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 3006 | * It is actually a sign of a bug on the client or on the server. |
| 3007 | * |
| 3008 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3009 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | * have unhashed the old state_owner for us, and that we can |
| 3011 | * therefore safely retry using a new one. We should still warn |
| 3012 | * the user though... |
| 3013 | */ |
| 3014 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 3015 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 3016 | " returned a bad sequence-id error!\n", |
| 3017 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | exception.retry = 1; |
| 3019 | continue; |
| 3020 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 3021 | /* |
| 3022 | * BAD_STATEID on OPEN means that the server cancelled our |
| 3023 | * state before it received the OPEN_CONFIRM. |
| 3024 | * Recover by retrying the request as per the discussion |
| 3025 | * on Page 181 of RFC3530. |
| 3026 | */ |
| 3027 | if (status == -NFS4ERR_BAD_STATEID) { |
| 3028 | exception.retry = 1; |
| 3029 | continue; |
| 3030 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 3031 | if (status == -EAGAIN) { |
| 3032 | /* We must have found a delegation */ |
| 3033 | exception.retry = 1; |
| 3034 | continue; |
| 3035 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 3036 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 3037 | continue; |
| 3038 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | status, &exception)); |
| 3040 | } while (exception.retry); |
| 3041 | return res; |
| 3042 | } |
| 3043 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3044 | static int _nfs4_do_setattr(struct inode *inode, |
| 3045 | struct nfs_setattrargs *arg, |
| 3046 | struct nfs_setattrres *res, |
| 3047 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3048 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3049 | { |
| 3050 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3051 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3052 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3053 | .rpc_argp = arg, |
| 3054 | .rpc_resp = res, |
| 3055 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3056 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3057 | struct rpc_cred *delegation_cred = NULL; |
| 3058 | unsigned long timestamp = jiffies; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3059 | bool truncate; |
| 3060 | int status; |
| 3061 | |
| 3062 | nfs_fattr_init(res->fattr); |
| 3063 | |
| 3064 | /* Servers should only apply open mode checks for file size changes */ |
| 3065 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3066 | if (!truncate) |
| 3067 | goto zero_stateid; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3068 | |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3069 | if (nfs4_copy_delegation_stateid(inode, FMODE_WRITE, &arg->stateid, &delegation_cred)) { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3070 | /* Use that stateid */ |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3071 | } else if (ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3072 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3073 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3074 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3075 | l_ctx = nfs_get_lock_context(ctx); |
| 3076 | if (IS_ERR(l_ctx)) |
| 3077 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3078 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3079 | &arg->stateid, &delegation_cred); |
| 3080 | nfs_put_lock_context(l_ctx); |
| 3081 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3082 | return -EBADF; |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3083 | } else { |
| 3084 | zero_stateid: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3085 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
Trond Myklebust | 991eedb | 2018-04-09 11:15:30 -0400 | [diff] [blame] | 3086 | } |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3087 | if (delegation_cred) |
| 3088 | msg.rpc_cred = delegation_cred; |
| 3089 | |
| 3090 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3091 | |
| 3092 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3093 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3094 | renew_lease(server, timestamp); |
| 3095 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3096 | return status; |
| 3097 | } |
| 3098 | |
| 3099 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3100 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3101 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3102 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3104 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3105 | __u32 bitmask[NFS4_BITMASK_SZ]; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3106 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3107 | struct nfs_setattrargs arg = { |
| 3108 | .fh = NFS_FH(inode), |
| 3109 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | .server = server, |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3111 | .bitmask = bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3112 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3113 | }; |
| 3114 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3116 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3118 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3119 | struct nfs4_exception exception = { |
| 3120 | .state = state, |
| 3121 | .inode = inode, |
| 3122 | .stateid = &arg.stateid, |
| 3123 | }; |
| 3124 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | do { |
Trond Myklebust | 30846df | 2018-04-07 13:44:28 -0400 | [diff] [blame] | 3127 | nfs4_bitmap_copy_adjust_setattr(bitmask, |
| 3128 | nfs4_bitmask(server, olabel), |
| 3129 | inode); |
| 3130 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3131 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3132 | switch (err) { |
| 3133 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3134 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3135 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3136 | "applying open mode checks to " |
| 3137 | "a SETATTR that is not " |
| 3138 | "changing file size.\n", |
| 3139 | server->nfs_client->cl_hostname); |
| 3140 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3141 | if (state && !(state->state & FMODE_WRITE)) { |
| 3142 | err = -EBADF; |
| 3143 | if (sattr->ia_valid & ATTR_OPEN) |
| 3144 | err = -EACCES; |
| 3145 | goto out; |
| 3146 | } |
| 3147 | } |
| 3148 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3150 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | return err; |
| 3152 | } |
| 3153 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3154 | static bool |
| 3155 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3156 | { |
| 3157 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3158 | return false; |
| 3159 | |
| 3160 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3161 | } |
| 3162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | struct nfs4_closedata { |
| 3164 | struct inode *inode; |
| 3165 | struct nfs4_state *state; |
| 3166 | struct nfs_closeargs arg; |
| 3167 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3168 | struct { |
| 3169 | struct nfs4_layoutreturn_args arg; |
| 3170 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3171 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3172 | u32 roc_barrier; |
| 3173 | bool roc; |
| 3174 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3175 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3176 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | }; |
| 3178 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3179 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3181 | struct nfs4_closedata *calldata = data; |
| 3182 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3183 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3184 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3185 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3186 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3187 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3188 | nfs4_put_open_state(calldata->state); |
| 3189 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3190 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3191 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3192 | kfree(calldata); |
| 3193 | } |
| 3194 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3195 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3197 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3200 | nfs4_stateid *res_stateid = NULL; |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3201 | struct nfs4_exception exception = { |
| 3202 | .state = state, |
| 3203 | .inode = calldata->inode, |
| 3204 | .stateid = &calldata->arg.stateid, |
| 3205 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3207 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3208 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3209 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3210 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3211 | |
| 3212 | /* Handle Layoutreturn errors */ |
| 3213 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3214 | switch (calldata->res.lr_ret) { |
| 3215 | default: |
| 3216 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3217 | break; |
| 3218 | case 0: |
| 3219 | calldata->arg.lr_args = NULL; |
| 3220 | calldata->res.lr_res = NULL; |
| 3221 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3222 | case -NFS4ERR_OLD_STATEID: |
| 3223 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3224 | calldata->inode)) |
| 3225 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3226 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3227 | case -NFS4ERR_ADMIN_REVOKED: |
| 3228 | case -NFS4ERR_DELEG_REVOKED: |
| 3229 | case -NFS4ERR_EXPIRED: |
| 3230 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3231 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3232 | case -NFS4ERR_WRONG_CRED: |
| 3233 | calldata->arg.lr_args = NULL; |
| 3234 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3235 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3239 | /* 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] | 3240 | * the state_owner. we keep this around to process errors |
| 3241 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | switch (task->tk_status) { |
| 3243 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3244 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3245 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3246 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3247 | case -NFS4ERR_ACCESS: |
| 3248 | if (calldata->arg.bitmask != NULL) { |
| 3249 | calldata->arg.bitmask = NULL; |
| 3250 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3251 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3252 | |
| 3253 | } |
| 3254 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3255 | case -NFS4ERR_OLD_STATEID: |
| 3256 | /* Did we race with OPEN? */ |
| 3257 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3258 | state)) |
| 3259 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3260 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3261 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3263 | case -NFS4ERR_EXPIRED: |
| 3264 | nfs4_free_revoked_stateid(server, |
| 3265 | &calldata->arg.stateid, |
| 3266 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3267 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3268 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3269 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | default: |
Trond Myklebust | b8b8d22 | 2017-11-07 10:51:37 -0500 | [diff] [blame] | 3271 | task->tk_status = nfs4_async_handle_exception(task, |
| 3272 | server, task->tk_status, &exception); |
| 3273 | if (exception.retry) |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3274 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3276 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3277 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3278 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3279 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3280 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3281 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3282 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame] | 3283 | return; |
| 3284 | lr_restart: |
| 3285 | calldata->res.lr_ret = 0; |
| 3286 | out_restart: |
| 3287 | task->tk_status = 0; |
| 3288 | rpc_restart_call_prepare(task); |
| 3289 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3292 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3294 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3295 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3296 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3297 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3298 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3299 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3300 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3301 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3302 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3303 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3304 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3305 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3306 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3307 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3308 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3309 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3310 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3311 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3312 | if (state->n_rdonly == 0) |
| 3313 | call_close |= is_rdonly; |
| 3314 | else if (is_rdonly) |
| 3315 | calldata->arg.fmode |= FMODE_READ; |
| 3316 | if (state->n_wronly == 0) |
| 3317 | call_close |= is_wronly; |
| 3318 | else if (is_wronly) |
| 3319 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3320 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3321 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3322 | } else if (is_rdwr) |
| 3323 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3324 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3325 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3326 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3327 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3328 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3329 | |
| 3330 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3331 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3332 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3333 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3334 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3335 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3336 | nfs_release_seqid(calldata->arg.seqid); |
| 3337 | goto out_wait; |
| 3338 | } |
| 3339 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3340 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3341 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3342 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3343 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3344 | /* Close-to-open cache consistency revalidation */ |
| 3345 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3346 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3347 | else |
| 3348 | calldata->arg.bitmask = NULL; |
| 3349 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3350 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3351 | calldata->arg.share_access = |
| 3352 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3353 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3354 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3355 | if (calldata->res.fattr == NULL) |
| 3356 | calldata->arg.bitmask = NULL; |
| 3357 | else if (calldata->arg.bitmask == NULL) |
| 3358 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3359 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3360 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3361 | &calldata->arg.seq_args, |
| 3362 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3363 | task) != 0) |
| 3364 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3365 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3366 | return; |
| 3367 | out_no_action: |
| 3368 | task->tk_action = NULL; |
| 3369 | out_wait: |
| 3370 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3373 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3374 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3375 | .rpc_call_done = nfs4_close_done, |
| 3376 | .rpc_release = nfs4_free_closedata, |
| 3377 | }; |
| 3378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | /* |
| 3380 | * It is possible for data to be read/written from a mem-mapped file |
| 3381 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3382 | * This means that we can't safely call nfsv4 close on a file until |
| 3383 | * the inode is cleared. This in turn means that we are not good |
| 3384 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3385 | * share state even when we are done with one of the three share |
| 3386 | * stateid's in the inode. |
| 3387 | * |
| 3388 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3389 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3390 | 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] | 3391 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3392 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3393 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3395 | struct nfs4_state_owner *sp = state->owner; |
| 3396 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3397 | struct rpc_message msg = { |
| 3398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3399 | .rpc_cred = state->owner->so_cred, |
| 3400 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3401 | struct rpc_task_setup task_setup_data = { |
| 3402 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3403 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3404 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3405 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3406 | .flags = RPC_TASK_ASYNC, |
| 3407 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3408 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3410 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3411 | &task_setup_data.rpc_client, &msg); |
| 3412 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3413 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3415 | goto out; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 3416 | 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] | 3417 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3419 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3420 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3421 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3423 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3424 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3425 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3426 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3427 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3428 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3429 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3430 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3431 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3432 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3433 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3434 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3435 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3436 | if (calldata->lr.roc) { |
| 3437 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3438 | calldata->res.lr_res = &calldata->lr.res; |
| 3439 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3440 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3441 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3442 | msg.rpc_argp = &calldata->arg; |
| 3443 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3444 | task_setup_data.callback_data = calldata; |
| 3445 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3446 | if (IS_ERR(task)) |
| 3447 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3448 | status = 0; |
| 3449 | if (wait) |
| 3450 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3451 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3452 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3453 | out_free_calldata: |
| 3454 | kfree(calldata); |
| 3455 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3456 | nfs4_put_open_state(state); |
| 3457 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3458 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3461 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3462 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3463 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3466 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3467 | |
| 3468 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3470 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3471 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3472 | |
| 3473 | nfs4_label_release_security(label); |
| 3474 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3475 | if (IS_ERR(state)) |
| 3476 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3477 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3480 | 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] | 3481 | { |
| 3482 | if (ctx->state == NULL) |
| 3483 | return; |
| 3484 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3485 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3486 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3487 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3490 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3491 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3492 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3495 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3496 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3497 | struct nfs4_server_caps_arg args = { |
| 3498 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3499 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | struct nfs4_server_caps_res res = {}; |
| 3502 | struct rpc_message msg = { |
| 3503 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3504 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | .rpc_resp = &res, |
| 3506 | }; |
| 3507 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3508 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3510 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3511 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3512 | FATTR4_WORD0_LINK_SUPPORT | |
| 3513 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3514 | FATTR4_WORD0_ACLSUPPORT; |
| 3515 | if (minorversion) |
| 3516 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3517 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3518 | 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] | 3519 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3520 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3521 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3522 | case 0: |
| 3523 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3524 | res.attr_bitmask[2] = 0; |
| 3525 | break; |
| 3526 | case 1: |
| 3527 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3528 | break; |
| 3529 | case 2: |
| 3530 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3533 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3534 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3535 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3536 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3537 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3538 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3539 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3540 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | server->caps |= NFS_CAP_ACLS; |
| 3542 | if (res.has_links != 0) |
| 3543 | server->caps |= NFS_CAP_HARDLINKS; |
| 3544 | if (res.has_symlinks != 0) |
| 3545 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3546 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3547 | server->caps |= NFS_CAP_FILEID; |
| 3548 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3549 | server->caps |= NFS_CAP_MODE; |
| 3550 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3551 | server->caps |= NFS_CAP_NLINK; |
| 3552 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3553 | server->caps |= NFS_CAP_OWNER; |
| 3554 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3555 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3556 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3557 | server->caps |= NFS_CAP_ATIME; |
| 3558 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3559 | server->caps |= NFS_CAP_CTIME; |
| 3560 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3561 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3562 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3563 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3564 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3565 | #endif |
| 3566 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3567 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3568 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3569 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3570 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3571 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3572 | 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] | 3573 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3574 | |
| 3575 | /* Avoid a regression due to buggy server */ |
| 3576 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3577 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3578 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3579 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3582 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | return status; |
| 3586 | } |
| 3587 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3588 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | { |
| 3590 | struct nfs4_exception exception = { }; |
| 3591 | int err; |
| 3592 | do { |
| 3593 | err = nfs4_handle_exception(server, |
| 3594 | _nfs4_server_capabilities(server, fhandle), |
| 3595 | &exception); |
| 3596 | } while (exception.retry); |
| 3597 | return err; |
| 3598 | } |
| 3599 | |
| 3600 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3601 | struct nfs_fsinfo *info) |
| 3602 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3603 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3605 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | }; |
| 3607 | struct nfs4_lookup_res res = { |
| 3608 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3609 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | .fh = fhandle, |
| 3611 | }; |
| 3612 | struct rpc_message msg = { |
| 3613 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3614 | .rpc_argp = &args, |
| 3615 | .rpc_resp = &res, |
| 3616 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3617 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3618 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3619 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3620 | /* |
| 3621 | * Process the label in the upcoming getfattr |
| 3622 | */ |
| 3623 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3624 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3625 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3626 | 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] | 3627 | } |
| 3628 | |
| 3629 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3630 | struct nfs_fsinfo *info) |
| 3631 | { |
| 3632 | struct nfs4_exception exception = { }; |
| 3633 | int err; |
| 3634 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3635 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3636 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3637 | switch (err) { |
| 3638 | case 0: |
| 3639 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3640 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3641 | default: |
| 3642 | err = nfs4_handle_exception(server, err, &exception); |
| 3643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3645 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | return err; |
| 3647 | } |
| 3648 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3649 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3650 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3651 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3652 | struct rpc_auth_create_args auth_args = { |
| 3653 | .pseudoflavor = flavor, |
| 3654 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3655 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3656 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3657 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3658 | if (IS_ERR(auth)) |
| 3659 | return -EACCES; |
| 3660 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3661 | } |
| 3662 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3663 | /* |
| 3664 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3665 | * |
| 3666 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3667 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3668 | * |
| 3669 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3670 | * negative errno value. |
| 3671 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3672 | 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] | 3673 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3675 | /* Per 3530bis 15.33.5 */ |
| 3676 | static const rpc_authflavor_t flav_array[] = { |
| 3677 | RPC_AUTH_GSS_KRB5P, |
| 3678 | RPC_AUTH_GSS_KRB5I, |
| 3679 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3680 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3681 | RPC_AUTH_NULL, |
| 3682 | }; |
| 3683 | int status = -EPERM; |
| 3684 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3686 | if (server->auth_info.flavor_len > 0) { |
| 3687 | /* try each flavor specified by user */ |
| 3688 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3689 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3690 | server->auth_info.flavors[i]); |
| 3691 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3692 | continue; |
| 3693 | break; |
| 3694 | } |
| 3695 | } else { |
| 3696 | /* no flavors specified by user, try default list */ |
| 3697 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3698 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3699 | flav_array[i]); |
| 3700 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3701 | continue; |
| 3702 | break; |
| 3703 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3704 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3705 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3706 | /* |
| 3707 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3708 | * to access the mount. It could also mean that we tried to mount |
| 3709 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3710 | * existing mount programs don't handle -EACCES very well so it should |
| 3711 | * be mapped to -EPERM instead. |
| 3712 | */ |
| 3713 | if (status == -EACCES) |
| 3714 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3715 | return status; |
| 3716 | } |
| 3717 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3718 | /** |
| 3719 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3720 | * @server: initialized nfs_server handle |
| 3721 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3722 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3723 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3724 | * |
| 3725 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3726 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3727 | 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] | 3728 | struct nfs_fsinfo *info, |
| 3729 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3730 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3731 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3732 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3733 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3734 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3735 | |
| 3736 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3737 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3738 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | if (status == 0) |
| 3741 | status = nfs4_server_capabilities(server, fhandle); |
| 3742 | if (status == 0) |
| 3743 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3744 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3745 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3748 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3749 | struct nfs_fsinfo *info) |
| 3750 | { |
| 3751 | int error; |
| 3752 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3753 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3754 | |
| 3755 | error = nfs4_server_capabilities(server, mntfh); |
| 3756 | if (error < 0) { |
| 3757 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3758 | return error; |
| 3759 | } |
| 3760 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3761 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3762 | if (IS_ERR(label)) |
| 3763 | return PTR_ERR(label); |
| 3764 | |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3765 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3766 | if (error < 0) { |
| 3767 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3768 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3772 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3773 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3774 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3775 | err_free_label: |
| 3776 | nfs4_label_free(label); |
| 3777 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3778 | return error; |
| 3779 | } |
| 3780 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3781 | /* |
| 3782 | * Get locations and (maybe) other attributes of a referral. |
| 3783 | * Note that we'll actually follow the referral later when |
| 3784 | * we detect fsid mismatch in inode revalidation |
| 3785 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3786 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3787 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3788 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3789 | { |
| 3790 | int status = -ENOMEM; |
| 3791 | struct page *page = NULL; |
| 3792 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3793 | |
| 3794 | page = alloc_page(GFP_KERNEL); |
| 3795 | if (page == NULL) |
| 3796 | goto out; |
| 3797 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3798 | if (locations == NULL) |
| 3799 | goto out; |
| 3800 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3801 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3802 | if (status != 0) |
| 3803 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3804 | |
| 3805 | /* |
| 3806 | * If the fsid didn't change, this is a migration event, not a |
| 3807 | * referral. Cause us to drop into the exception handler, which |
| 3808 | * will kick off migration recovery. |
| 3809 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3810 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3811 | dprintk("%s: server did not return a different fsid for" |
| 3812 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3813 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3814 | goto out; |
| 3815 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3816 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3817 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3818 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3819 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3820 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3821 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3822 | out: |
| 3823 | if (page) |
| 3824 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3825 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3826 | return status; |
| 3827 | } |
| 3828 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3829 | 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] | 3830 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3831 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | { |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3833 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | struct nfs4_getattr_arg args = { |
| 3835 | .fh = fhandle, |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3836 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | }; |
| 3838 | struct nfs4_getattr_res res = { |
| 3839 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3840 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | .server = server, |
| 3842 | }; |
| 3843 | struct rpc_message msg = { |
| 3844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3845 | .rpc_argp = &args, |
| 3846 | .rpc_resp = &res, |
| 3847 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3848 | |
Trond Myklebust | 771734f | 2018-04-07 13:54:23 -0400 | [diff] [blame] | 3849 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3850 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3851 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3852 | 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] | 3853 | } |
| 3854 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3855 | 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] | 3856 | struct nfs_fattr *fattr, struct nfs4_label *label, |
| 3857 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | { |
| 3859 | struct nfs4_exception exception = { }; |
| 3860 | int err; |
| 3861 | do { |
Trond Myklebust | a841b54 | 2018-04-07 13:50:59 -0400 | [diff] [blame] | 3862 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3863 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3864 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | &exception); |
| 3866 | } while (exception.retry); |
| 3867 | return err; |
| 3868 | } |
| 3869 | |
| 3870 | /* |
| 3871 | * The file is not closed if it is opened due to the a request to change |
| 3872 | * the size of the file. The open call will not be needed once the |
| 3873 | * VFS layer lookup-intents are implemented. |
| 3874 | * |
| 3875 | * Close is called when the inode is destroyed. |
| 3876 | * If we haven't opened the file for O_WRONLY, we |
| 3877 | * need to in the size_change case to obtain a stateid. |
| 3878 | * |
| 3879 | * Got race? |
| 3880 | * Because OPEN is always done by name in nfsv4, it is |
| 3881 | * possible that we opened a different file by the same |
| 3882 | * name. We can recognize this race condition, but we |
| 3883 | * can't do anything about it besides returning an error. |
| 3884 | * |
| 3885 | * This will be fixed with VFS changes (lookup-intent). |
| 3886 | */ |
| 3887 | static int |
| 3888 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3889 | struct iattr *sattr) |
| 3890 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3891 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3892 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3893 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3894 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | int status; |
| 3896 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3897 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3898 | sattr->ia_valid & ATTR_SIZE && |
| 3899 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3900 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3901 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3902 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3904 | /* Deal with open(O_TRUNC) */ |
| 3905 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3906 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3907 | |
| 3908 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3909 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3910 | return 0; |
| 3911 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3912 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3913 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3914 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3915 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3916 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3917 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3918 | } |
| 3919 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3920 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3921 | if (IS_ERR(label)) |
| 3922 | return PTR_ERR(label); |
| 3923 | |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3924 | /* Return any delegations if we're going to change ACLs */ |
| 3925 | if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 3926 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 199366f | 2018-03-20 16:43:18 -0400 | [diff] [blame] | 3927 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3928 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3929 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3930 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3931 | nfs_setsecurity(inode, fattr, label); |
| 3932 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3933 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | return status; |
| 3935 | } |
| 3936 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3937 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3938 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3939 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3940 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3941 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3942 | int status; |
| 3943 | struct nfs4_lookup_arg args = { |
| 3944 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3945 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3946 | .name = name, |
| 3947 | }; |
| 3948 | struct nfs4_lookup_res res = { |
| 3949 | .server = server, |
| 3950 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3951 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3952 | .fh = fhandle, |
| 3953 | }; |
| 3954 | struct rpc_message msg = { |
| 3955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3956 | .rpc_argp = &args, |
| 3957 | .rpc_resp = &res, |
| 3958 | }; |
| 3959 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3960 | args.bitmask = nfs4_bitmask(server, label); |
| 3961 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3962 | nfs_fattr_init(fattr); |
| 3963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3965 | 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] | 3966 | dprintk("NFS reply lookup: %d\n", status); |
| 3967 | return status; |
| 3968 | } |
| 3969 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3970 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3971 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3972 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3973 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3974 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3975 | fattr->nlink = 2; |
| 3976 | } |
| 3977 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3978 | 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] | 3979 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3980 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3981 | { |
| 3982 | struct nfs4_exception exception = { }; |
| 3983 | struct rpc_clnt *client = *clnt; |
| 3984 | int err; |
| 3985 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3986 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3987 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3988 | switch (err) { |
| 3989 | case -NFS4ERR_BADNAME: |
| 3990 | err = -ENOENT; |
| 3991 | goto out; |
| 3992 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3993 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3994 | if (err == -NFS4ERR_MOVED) |
| 3995 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3996 | goto out; |
| 3997 | case -NFS4ERR_WRONGSEC: |
| 3998 | err = -EPERM; |
| 3999 | if (client != *clnt) |
| 4000 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 4001 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4002 | if (IS_ERR(client)) |
| 4003 | return PTR_ERR(client); |
| 4004 | |
| 4005 | exception.retry = 1; |
| 4006 | break; |
| 4007 | default: |
| 4008 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 4009 | } |
| 4010 | } while (exception.retry); |
| 4011 | |
| 4012 | out: |
| 4013 | if (err == 0) |
| 4014 | *clnt = client; |
| 4015 | else if (client != *clnt) |
| 4016 | rpc_shutdown_client(client); |
| 4017 | |
| 4018 | return err; |
| 4019 | } |
| 4020 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4021 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4022 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4023 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4025 | int status; |
| 4026 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 4027 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4028 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 4029 | if (client != NFS_CLIENT(dir)) { |
| 4030 | rpc_shutdown_client(client); |
| 4031 | nfs_fixup_secinfo_attributes(fattr); |
| 4032 | } |
| 4033 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4036 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4037 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4038 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 4039 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4040 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4041 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4042 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4043 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4044 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4045 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 4046 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 4047 | } |
| 4048 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 4049 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 4050 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 4051 | struct nfs4_label *label) |
| 4052 | { |
| 4053 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 4054 | struct nfs_server *server = NFS_SERVER(inode); |
| 4055 | int status; |
| 4056 | struct nfs4_lookupp_arg args = { |
| 4057 | .bitmask = server->attr_bitmask, |
| 4058 | .fh = NFS_FH(inode), |
| 4059 | }; |
| 4060 | struct nfs4_lookupp_res res = { |
| 4061 | .server = server, |
| 4062 | .fattr = fattr, |
| 4063 | .label = label, |
| 4064 | .fh = fhandle, |
| 4065 | }; |
| 4066 | struct rpc_message msg = { |
| 4067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4068 | .rpc_argp = &args, |
| 4069 | .rpc_resp = &res, |
| 4070 | }; |
| 4071 | |
| 4072 | args.bitmask = nfs4_bitmask(server, label); |
| 4073 | |
| 4074 | nfs_fattr_init(fattr); |
| 4075 | |
| 4076 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4077 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4078 | &res.seq_res, 0); |
| 4079 | dprintk("NFS reply lookupp: %d\n", status); |
| 4080 | return status; |
| 4081 | } |
| 4082 | |
| 4083 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4084 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4085 | { |
| 4086 | struct nfs4_exception exception = { }; |
| 4087 | int err; |
| 4088 | do { |
| 4089 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4090 | trace_nfs4_lookupp(inode, err); |
| 4091 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4092 | &exception); |
| 4093 | } while (exception.retry); |
| 4094 | return err; |
| 4095 | } |
| 4096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4098 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4099 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | struct nfs4_accessargs args = { |
| 4101 | .fh = NFS_FH(inode), |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4102 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4104 | struct nfs4_accessres res = { |
| 4105 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4106 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | struct rpc_message msg = { |
| 4108 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4109 | .rpc_argp = &args, |
| 4110 | .rpc_resp = &res, |
| 4111 | .rpc_cred = entry->cred, |
| 4112 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4113 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | |
Trond Myklebust | 7c67265 | 2018-06-04 15:00:53 -0400 | [diff] [blame] | 4115 | if (!nfs4_have_delegation(inode, FMODE_READ)) { |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4116 | res.fattr = nfs_alloc_fattr(); |
| 4117 | if (res.fattr == NULL) |
| 4118 | return -ENOMEM; |
| 4119 | args.bitmask = server->cache_consistency_bitmask; |
| 4120 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4121 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4122 | 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] | 4123 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4124 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | 8bcbe7d | 2018-03-20 17:03:11 -0400 | [diff] [blame] | 4125 | if (res.fattr) |
| 4126 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4128 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | return status; |
| 4130 | } |
| 4131 | |
| 4132 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4133 | { |
| 4134 | struct nfs4_exception exception = { }; |
| 4135 | int err; |
| 4136 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4137 | err = _nfs4_proc_access(inode, entry); |
| 4138 | trace_nfs4_access(inode, err); |
| 4139 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | &exception); |
| 4141 | } while (exception.retry); |
| 4142 | return err; |
| 4143 | } |
| 4144 | |
| 4145 | /* |
| 4146 | * TODO: For the time being, we don't try to get any attributes |
| 4147 | * along with any of the zero-copy operations READ, READDIR, |
| 4148 | * READLINK, WRITE. |
| 4149 | * |
| 4150 | * In the case of the first three, we want to put the GETATTR |
| 4151 | * after the read-type operation -- this is because it is hard |
| 4152 | * to predict the length of a GETATTR response in v4, and thus |
| 4153 | * align the READ data correctly. This means that the GETATTR |
| 4154 | * may end up partially falling into the page cache, and we should |
| 4155 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4156 | * To do this efficiently, we need to know the total length |
| 4157 | * of data received, which doesn't seem to be available outside |
| 4158 | * of the RPC layer. |
| 4159 | * |
| 4160 | * In the case of WRITE, we also want to put the GETATTR after |
| 4161 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4162 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | * |
| 4164 | * Both of these changes to the XDR layer would in fact be quite |
| 4165 | * minor, but I decided to leave them for a subsequent patch. |
| 4166 | */ |
| 4167 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4168 | unsigned int pgbase, unsigned int pglen) |
| 4169 | { |
| 4170 | struct nfs4_readlink args = { |
| 4171 | .fh = NFS_FH(inode), |
| 4172 | .pgbase = pgbase, |
| 4173 | .pglen = pglen, |
| 4174 | .pages = &page, |
| 4175 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4176 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | struct rpc_message msg = { |
| 4178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4179 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4180 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | }; |
| 4182 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4183 | 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] | 4184 | } |
| 4185 | |
| 4186 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4187 | unsigned int pgbase, unsigned int pglen) |
| 4188 | { |
| 4189 | struct nfs4_exception exception = { }; |
| 4190 | int err; |
| 4191 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4192 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4193 | trace_nfs4_readlink(inode, err); |
| 4194 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | &exception); |
| 4196 | } while (exception.retry); |
| 4197 | return err; |
| 4198 | } |
| 4199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4201 | * 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] | 4202 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | static int |
| 4204 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4205 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4207 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4208 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4209 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | int status = 0; |
| 4212 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4213 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4214 | if (IS_ERR(ctx)) |
| 4215 | return PTR_ERR(ctx); |
| 4216 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4217 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4218 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4219 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4220 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4221 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | if (IS_ERR(state)) { |
| 4223 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4224 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4227 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4228 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | return status; |
| 4230 | } |
| 4231 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4232 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4234 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4235 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4237 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4239 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4240 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4241 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4243 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4244 | .rpc_argp = &args, |
| 4245 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4247 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4248 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4249 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4250 | 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] | 4251 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4252 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | return status; |
| 4254 | } |
| 4255 | |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4256 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
| 4257 | { |
| 4258 | struct nfs4_exception exception = { }; |
| 4259 | struct inode *inode = d_inode(dentry); |
| 4260 | int err; |
| 4261 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4262 | if (inode) { |
| 4263 | if (inode->i_nlink == 1) |
| 4264 | nfs4_inode_return_delegation(inode); |
| 4265 | else |
| 4266 | nfs4_inode_make_writeable(inode); |
| 4267 | } |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4268 | do { |
| 4269 | err = _nfs4_proc_remove(dir, &dentry->d_name); |
| 4270 | trace_nfs4_remove(dir, &dentry->d_name, err); |
| 4271 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
| 4272 | &exception); |
| 4273 | } while (exception.retry); |
| 4274 | return err; |
| 4275 | } |
| 4276 | |
| 4277 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | { |
| 4279 | struct nfs4_exception exception = { }; |
| 4280 | int err; |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 4281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4283 | err = _nfs4_proc_remove(dir, name); |
| 4284 | trace_nfs4_remove(dir, name, err); |
| 4285 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | &exception); |
| 4287 | } while (exception.retry); |
| 4288 | return err; |
| 4289 | } |
| 4290 | |
Trond Myklebust | ed7e9ad | 2018-05-30 16:11:52 -0400 | [diff] [blame] | 4291 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, |
| 4292 | struct dentry *dentry, |
| 4293 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4295 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4296 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4298 | res->server = NFS_SB(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4300 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1, 0); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4301 | |
| 4302 | nfs_fattr_init(res->dir_attr); |
Trond Myklebust | 977fcc2 | 2018-03-20 16:43:17 -0400 | [diff] [blame] | 4303 | |
| 4304 | if (inode) |
| 4305 | nfs4_inode_return_delegation(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4308 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4309 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4310 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4311 | &data->args.seq_args, |
| 4312 | &data->res.seq_res, |
| 4313 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | } |
| 4315 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4316 | 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] | 4317 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4318 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4319 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4320 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4321 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4322 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4323 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4324 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4325 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4326 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4327 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4328 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4331 | static void nfs4_proc_rename_setup(struct rpc_message *msg, |
| 4332 | struct dentry *old_dentry, |
| 4333 | struct dentry *new_dentry) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4334 | { |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4335 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4336 | struct nfs_renameres *res = msg->rpc_resp; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4337 | struct inode *old_inode = d_inode(old_dentry); |
| 4338 | struct inode *new_inode = d_inode(new_dentry); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4339 | |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4340 | if (old_inode) |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4341 | nfs4_inode_make_writeable(old_inode); |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4342 | if (new_inode) |
| 4343 | nfs4_inode_return_delegation(new_inode); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4344 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Trond Myklebust | f2c2c55 | 2018-03-20 16:43:16 -0400 | [diff] [blame] | 4345 | res->server = NFS_SB(old_dentry->d_sb); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4346 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1, 0); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4349 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4350 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4351 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4352 | &data->args.seq_args, |
| 4353 | &data->res.seq_res, |
| 4354 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4358 | struct inode *new_dir) |
| 4359 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4360 | struct nfs_renamedata *data = task->tk_calldata; |
| 4361 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4362 | |
| 4363 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4364 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4365 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4366 | return 0; |
| 4367 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4368 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4369 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4370 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4371 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4372 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4373 | return 1; |
| 4374 | } |
| 4375 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4376 | 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] | 4377 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4378 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4379 | __u32 bitmask[NFS4_BITMASK_SZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | struct nfs4_link_arg arg = { |
| 4381 | .fh = NFS_FH(inode), |
| 4382 | .dir_fh = NFS_FH(dir), |
| 4383 | .name = name, |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4384 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4386 | struct nfs4_link_res res = { |
| 4387 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4388 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4389 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | struct rpc_message msg = { |
| 4391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4392 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4393 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4395 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4397 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4398 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4399 | goto out; |
| 4400 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4401 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4402 | if (IS_ERR(res.label)) { |
| 4403 | status = PTR_ERR(res.label); |
| 4404 | goto out; |
| 4405 | } |
| 4406 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 4407 | nfs4_inode_make_writeable(inode); |
Trond Myklebust | 2f28dc3 | 2018-04-08 21:06:40 -0400 | [diff] [blame] | 4408 | nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); |
Trond Myklebust | 9f76827 | 2018-03-20 16:43:14 -0400 | [diff] [blame] | 4409 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4410 | 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] | 4411 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4412 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4413 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4414 | if (!status) |
| 4415 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4416 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4417 | |
| 4418 | |
| 4419 | nfs4_label_free(res.label); |
| 4420 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4421 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4422 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | return status; |
| 4424 | } |
| 4425 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4426 | 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] | 4427 | { |
| 4428 | struct nfs4_exception exception = { }; |
| 4429 | int err; |
| 4430 | do { |
| 4431 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4432 | _nfs4_proc_link(inode, dir, name), |
| 4433 | &exception); |
| 4434 | } while (exception.retry); |
| 4435 | return err; |
| 4436 | } |
| 4437 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4438 | struct nfs4_createdata { |
| 4439 | struct rpc_message msg; |
| 4440 | struct nfs4_create_arg arg; |
| 4441 | struct nfs4_create_res res; |
| 4442 | struct nfs_fh fh; |
| 4443 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4444 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4445 | }; |
| 4446 | |
| 4447 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4448 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4449 | { |
| 4450 | struct nfs4_createdata *data; |
| 4451 | |
| 4452 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4453 | if (data != NULL) { |
| 4454 | struct nfs_server *server = NFS_SERVER(dir); |
| 4455 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4456 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4457 | if (IS_ERR(data->label)) |
| 4458 | goto out_free; |
| 4459 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4460 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4461 | data->msg.rpc_argp = &data->arg; |
| 4462 | data->msg.rpc_resp = &data->res; |
| 4463 | data->arg.dir_fh = NFS_FH(dir); |
| 4464 | data->arg.server = server; |
| 4465 | data->arg.name = name; |
| 4466 | data->arg.attrs = sattr; |
| 4467 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4468 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4469 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4470 | data->res.server = server; |
| 4471 | data->res.fh = &data->fh; |
| 4472 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4473 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4474 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4475 | } |
| 4476 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4477 | out_free: |
| 4478 | kfree(data); |
| 4479 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4483 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4484 | 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] | 4485 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4486 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4487 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4488 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4489 | 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] | 4490 | } |
| 4491 | return status; |
| 4492 | } |
| 4493 | |
| 4494 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4495 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4496 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4497 | kfree(data); |
| 4498 | } |
| 4499 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4500 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4501 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4502 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4504 | struct nfs4_createdata *data; |
| 4505 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4507 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4508 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4509 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4510 | status = -ENOMEM; |
| 4511 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4512 | if (data == NULL) |
| 4513 | goto out; |
| 4514 | |
| 4515 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4516 | data->arg.u.symlink.pages = &page; |
| 4517 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4518 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4520 | status = nfs4_do_create(dir, dentry, data); |
| 4521 | |
| 4522 | nfs4_free_createdata(data); |
| 4523 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | return status; |
| 4525 | } |
| 4526 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4527 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4528 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | { |
| 4530 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4531 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4533 | |
| 4534 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4537 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4538 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4539 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | &exception); |
| 4541 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4542 | |
| 4543 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | return err; |
| 4545 | } |
| 4546 | |
| 4547 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4548 | struct iattr *sattr, struct nfs4_label *label) |
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 | struct nfs4_createdata *data; |
| 4551 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4553 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4554 | if (data == NULL) |
| 4555 | goto out; |
| 4556 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4557 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4558 | status = nfs4_do_create(dir, dentry, data); |
| 4559 | |
| 4560 | nfs4_free_createdata(data); |
| 4561 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | return status; |
| 4563 | } |
| 4564 | |
| 4565 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4566 | struct iattr *sattr) |
| 4567 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4568 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4570 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4572 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4573 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4574 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4575 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4576 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4578 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4579 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4580 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | &exception); |
| 4582 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4583 | nfs4_label_release_security(label); |
| 4584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | return err; |
| 4586 | } |
| 4587 | |
| 4588 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4589 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4591 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | struct nfs4_readdir_arg args = { |
| 4593 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4594 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | .pgbase = 0, |
| 4596 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4597 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4598 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | }; |
| 4600 | struct nfs4_readdir_res res; |
| 4601 | struct rpc_message msg = { |
| 4602 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4603 | .rpc_argp = &args, |
| 4604 | .rpc_resp = &res, |
| 4605 | .rpc_cred = cred, |
| 4606 | }; |
| 4607 | int status; |
| 4608 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4609 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4610 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4611 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4612 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4614 | 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] | 4615 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4616 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4617 | status += args.pgbase; |
| 4618 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4619 | |
| 4620 | nfs_invalidate_atime(dir); |
| 4621 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4622 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | return status; |
| 4624 | } |
| 4625 | |
| 4626 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4627 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | { |
| 4629 | struct nfs4_exception exception = { }; |
| 4630 | int err; |
| 4631 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4632 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4633 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4634 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4635 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | &exception); |
| 4637 | } while (exception.retry); |
| 4638 | return err; |
| 4639 | } |
| 4640 | |
| 4641 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4642 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4644 | struct nfs4_createdata *data; |
| 4645 | int mode = sattr->ia_mode; |
| 4646 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4648 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4649 | if (data == NULL) |
| 4650 | goto out; |
| 4651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4653 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4655 | data->arg.ftype = NF4BLK; |
| 4656 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4657 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | } |
| 4659 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4660 | data->arg.ftype = NF4CHR; |
| 4661 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4662 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4663 | } else if (!S_ISSOCK(mode)) { |
| 4664 | status = -EINVAL; |
| 4665 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4667 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4668 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4669 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4670 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4671 | nfs4_free_createdata(data); |
| 4672 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | return status; |
| 4674 | } |
| 4675 | |
| 4676 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4677 | struct iattr *sattr, dev_t rdev) |
| 4678 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4679 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4681 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4683 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4684 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4685 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4686 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4687 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4689 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4690 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4691 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | &exception); |
| 4693 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4694 | |
| 4695 | nfs4_label_release_security(label); |
| 4696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | return err; |
| 4698 | } |
| 4699 | |
| 4700 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4701 | struct nfs_fsstat *fsstat) |
| 4702 | { |
| 4703 | struct nfs4_statfs_arg args = { |
| 4704 | .fh = fhandle, |
| 4705 | .bitmask = server->attr_bitmask, |
| 4706 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4707 | struct nfs4_statfs_res res = { |
| 4708 | .fsstat = fsstat, |
| 4709 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | struct rpc_message msg = { |
| 4711 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4712 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4713 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | }; |
| 4715 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4716 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4717 | 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] | 4718 | } |
| 4719 | |
| 4720 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4721 | { |
| 4722 | struct nfs4_exception exception = { }; |
| 4723 | int err; |
| 4724 | do { |
| 4725 | err = nfs4_handle_exception(server, |
| 4726 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4727 | &exception); |
| 4728 | } while (exception.retry); |
| 4729 | return err; |
| 4730 | } |
| 4731 | |
| 4732 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4733 | struct nfs_fsinfo *fsinfo) |
| 4734 | { |
| 4735 | struct nfs4_fsinfo_arg args = { |
| 4736 | .fh = fhandle, |
| 4737 | .bitmask = server->attr_bitmask, |
| 4738 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4739 | struct nfs4_fsinfo_res res = { |
| 4740 | .fsinfo = fsinfo, |
| 4741 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | struct rpc_message msg = { |
| 4743 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4744 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4745 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | }; |
| 4747 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4748 | 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] | 4749 | } |
| 4750 | |
| 4751 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4752 | { |
| 4753 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4754 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | int err; |
| 4756 | |
| 4757 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4758 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4759 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4760 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4761 | nfs4_set_lease_period(server->nfs_client, |
| 4762 | fsinfo->lease_time * HZ, |
| 4763 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4764 | break; |
| 4765 | } |
| 4766 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | } while (exception.retry); |
| 4768 | return err; |
| 4769 | } |
| 4770 | |
| 4771 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4772 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4773 | int error; |
| 4774 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4775 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4776 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4777 | if (error == 0) { |
| 4778 | /* block layout checks this! */ |
| 4779 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4780 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4781 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4782 | |
| 4783 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4787 | struct nfs_pathconf *pathconf) |
| 4788 | { |
| 4789 | struct nfs4_pathconf_arg args = { |
| 4790 | .fh = fhandle, |
| 4791 | .bitmask = server->attr_bitmask, |
| 4792 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4793 | struct nfs4_pathconf_res res = { |
| 4794 | .pathconf = pathconf, |
| 4795 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | struct rpc_message msg = { |
| 4797 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4798 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4799 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | }; |
| 4801 | |
| 4802 | /* None of the pathconf attributes are mandatory to implement */ |
| 4803 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4804 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4805 | return 0; |
| 4806 | } |
| 4807 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4808 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4809 | 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] | 4810 | } |
| 4811 | |
| 4812 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4813 | struct nfs_pathconf *pathconf) |
| 4814 | { |
| 4815 | struct nfs4_exception exception = { }; |
| 4816 | int err; |
| 4817 | |
| 4818 | do { |
| 4819 | err = nfs4_handle_exception(server, |
| 4820 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4821 | &exception); |
| 4822 | } while (exception.retry); |
| 4823 | return err; |
| 4824 | } |
| 4825 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4826 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4827 | const struct nfs_open_context *ctx, |
| 4828 | const struct nfs_lock_context *l_ctx, |
| 4829 | fmode_t fmode) |
| 4830 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4831 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4832 | } |
| 4833 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4834 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4835 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4836 | const struct nfs_open_context *ctx, |
| 4837 | const struct nfs_lock_context *l_ctx, |
| 4838 | fmode_t fmode) |
| 4839 | { |
| 4840 | nfs4_stateid current_stateid; |
| 4841 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4842 | /* If the current stateid represents a lost lock, then exit */ |
| 4843 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4844 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4845 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4846 | } |
| 4847 | |
| 4848 | static bool nfs4_error_stateid_expired(int err) |
| 4849 | { |
| 4850 | switch (err) { |
| 4851 | case -NFS4ERR_DELEG_REVOKED: |
| 4852 | case -NFS4ERR_ADMIN_REVOKED: |
| 4853 | case -NFS4ERR_BAD_STATEID: |
| 4854 | case -NFS4ERR_STALE_STATEID: |
| 4855 | case -NFS4ERR_OLD_STATEID: |
| 4856 | case -NFS4ERR_OPENMODE: |
| 4857 | case -NFS4ERR_EXPIRED: |
| 4858 | return true; |
| 4859 | } |
| 4860 | return false; |
| 4861 | } |
| 4862 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4863 | 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] | 4864 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4865 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4867 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4868 | if (task->tk_status < 0) { |
| 4869 | struct nfs4_exception exception = { |
| 4870 | .inode = hdr->inode, |
| 4871 | .state = hdr->args.context->state, |
| 4872 | .stateid = &hdr->args.stateid, |
| 4873 | }; |
| 4874 | task->tk_status = nfs4_async_handle_exception(task, |
| 4875 | server, task->tk_status, &exception); |
| 4876 | if (exception.retry) { |
| 4877 | rpc_restart_call_prepare(task); |
| 4878 | return -EAGAIN; |
| 4879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4883 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4884 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | } |
| 4886 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4887 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4888 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4889 | { |
| 4890 | |
| 4891 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4892 | nfs4_stateid_is_current(&args->stateid, |
| 4893 | args->context, |
| 4894 | args->lock_context, |
| 4895 | FMODE_READ)) |
| 4896 | return false; |
| 4897 | rpc_restart_call_prepare(task); |
| 4898 | return true; |
| 4899 | } |
| 4900 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4901 | 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] | 4902 | { |
| 4903 | |
| 4904 | dprintk("--> %s\n", __func__); |
| 4905 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4906 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4907 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4908 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4909 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4910 | if (task->tk_status > 0) |
| 4911 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4912 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4913 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4916 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4917 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4919 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4920 | if (!hdr->pgio_done_cb) |
| 4921 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4922 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 4923 | 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] | 4924 | } |
| 4925 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4926 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4927 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4928 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4929 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4930 | &hdr->args.seq_args, |
| 4931 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4932 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4933 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4934 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4935 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4936 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4937 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4938 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4939 | return -EIO; |
| 4940 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4943 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4944 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4946 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4947 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4948 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4949 | if (task->tk_status < 0) { |
| 4950 | struct nfs4_exception exception = { |
| 4951 | .inode = hdr->inode, |
| 4952 | .state = hdr->args.context->state, |
| 4953 | .stateid = &hdr->args.stateid, |
| 4954 | }; |
| 4955 | task->tk_status = nfs4_async_handle_exception(task, |
| 4956 | NFS_SERVER(inode), task->tk_status, |
| 4957 | &exception); |
| 4958 | if (exception.retry) { |
| 4959 | rpc_restart_call_prepare(task); |
| 4960 | return -EAGAIN; |
| 4961 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4963 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4964 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4965 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4966 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4967 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4970 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4971 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4972 | { |
| 4973 | |
| 4974 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4975 | nfs4_stateid_is_current(&args->stateid, |
| 4976 | args->context, |
| 4977 | args->lock_context, |
| 4978 | FMODE_WRITE)) |
| 4979 | return false; |
| 4980 | rpc_restart_call_prepare(task); |
| 4981 | return true; |
| 4982 | } |
| 4983 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4984 | 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] | 4985 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4986 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4987 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4988 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4989 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4990 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4991 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4992 | } |
| 4993 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4994 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4995 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4996 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4997 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4998 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4999 | return false; |
| 5000 | /* Otherwise, request attributes if and only if we don't hold |
| 5001 | * a delegation |
| 5002 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 5003 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5004 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 5005 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5006 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
Anna Schumaker | fb91fb0 | 2018-05-04 16:22:48 -0400 | [diff] [blame] | 5007 | struct rpc_message *msg, |
| 5008 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5010 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5011 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5012 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 5013 | hdr->args.bitmask = NULL; |
| 5014 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 5015 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5016 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 5017 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 5018 | if (!hdr->pgio_done_cb) |
| 5019 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 5020 | hdr->res.server = server; |
| 5021 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5023 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5024 | 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] | 5025 | nfs4_state_protect_write(server->nfs_client, clnt, msg, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5028 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 5029 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5030 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5031 | &data->args.seq_args, |
| 5032 | &data->res.seq_res, |
| 5033 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | } |
| 5035 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5036 | 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] | 5037 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5039 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 5040 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5041 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 5042 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5043 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5044 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5046 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5049 | 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] | 5050 | { |
| 5051 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5052 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5053 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Anna Schumaker | e9ae1ee | 2018-05-04 16:22:49 -0400 | [diff] [blame] | 5056 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, |
| 5057 | struct rpc_clnt **clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5059 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 5060 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 5061 | if (data->commit_done_cb == NULL) |
| 5062 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 5063 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 5064 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 5065 | 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] | 5066 | 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] | 5067 | } |
| 5068 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5069 | struct nfs4_renewdata { |
| 5070 | struct nfs_client *client; |
| 5071 | unsigned long timestamp; |
| 5072 | }; |
| 5073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | /* |
| 5075 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 5076 | * standalone procedure for queueing an asynchronous RENEW. |
| 5077 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5078 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5079 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5080 | struct nfs4_renewdata *data = calldata; |
| 5081 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5082 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5083 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5084 | nfs4_schedule_state_renewal(clp); |
| 5085 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5086 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5087 | } |
| 5088 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5089 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5091 | struct nfs4_renewdata *data = calldata; |
| 5092 | struct nfs_client *clp = data->client; |
| 5093 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5095 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 5096 | switch (task->tk_status) { |
| 5097 | case 0: |
| 5098 | break; |
| 5099 | case -NFS4ERR_LEASE_MOVED: |
| 5100 | nfs4_schedule_lease_moved_recovery(clp); |
| 5101 | break; |
| 5102 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 5103 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5104 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5105 | return; |
| 5106 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5107 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5108 | return; |
| 5109 | } |
| 5110 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5112 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | } |
| 5114 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5115 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5116 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5117 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5118 | }; |
| 5119 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5120 | 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] | 5121 | { |
| 5122 | struct rpc_message msg = { |
| 5123 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5124 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5125 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5127 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5129 | if (renew_flags == 0) |
| 5130 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5131 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5132 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5133 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5134 | if (data == NULL) { |
| 5135 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5136 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5137 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5138 | data->client = clp; |
| 5139 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5140 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5141 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5144 | 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] | 5145 | { |
| 5146 | struct rpc_message msg = { |
| 5147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5148 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5149 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | }; |
| 5151 | unsigned long now = jiffies; |
| 5152 | int status; |
| 5153 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5154 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | if (status < 0) |
| 5156 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5157 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | return 0; |
| 5159 | } |
| 5160 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5161 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5162 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5163 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5166 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5167 | * 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] | 5168 | * the stack. |
| 5169 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5170 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5171 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5172 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5173 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5174 | { |
| 5175 | struct page *newpage, **spages; |
| 5176 | int rc = 0; |
| 5177 | size_t len; |
| 5178 | spages = pages; |
| 5179 | |
| 5180 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5181 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5182 | newpage = alloc_page(GFP_KERNEL); |
| 5183 | |
| 5184 | if (newpage == NULL) |
| 5185 | goto unwind; |
| 5186 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5187 | buf += len; |
| 5188 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5189 | *pages++ = newpage; |
| 5190 | rc++; |
| 5191 | } while (buflen != 0); |
| 5192 | |
| 5193 | return rc; |
| 5194 | |
| 5195 | unwind: |
| 5196 | for(; rc > 0; rc--) |
| 5197 | __free_page(spages[rc-1]); |
| 5198 | return -ENOMEM; |
| 5199 | } |
| 5200 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5201 | struct nfs4_cached_acl { |
| 5202 | int cached; |
| 5203 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5204 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5205 | }; |
| 5206 | |
| 5207 | 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] | 5208 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5209 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5210 | |
| 5211 | spin_lock(&inode->i_lock); |
| 5212 | kfree(nfsi->nfs4_acl); |
| 5213 | nfsi->nfs4_acl = acl; |
| 5214 | spin_unlock(&inode->i_lock); |
| 5215 | } |
| 5216 | |
| 5217 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5218 | { |
| 5219 | nfs4_set_cached_acl(inode, NULL); |
| 5220 | } |
| 5221 | |
| 5222 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5223 | { |
| 5224 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5225 | struct nfs4_cached_acl *acl; |
| 5226 | int ret = -ENOENT; |
| 5227 | |
| 5228 | spin_lock(&inode->i_lock); |
| 5229 | acl = nfsi->nfs4_acl; |
| 5230 | if (acl == NULL) |
| 5231 | goto out; |
| 5232 | if (buf == NULL) /* user is just asking for length */ |
| 5233 | goto out_len; |
| 5234 | if (acl->cached == 0) |
| 5235 | goto out; |
| 5236 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5237 | if (acl->len > buflen) |
| 5238 | goto out; |
| 5239 | memcpy(buf, acl->data, acl->len); |
| 5240 | out_len: |
| 5241 | ret = acl->len; |
| 5242 | out: |
| 5243 | spin_unlock(&inode->i_lock); |
| 5244 | return ret; |
| 5245 | } |
| 5246 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5247 | 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] | 5248 | { |
| 5249 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5250 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5251 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5252 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5253 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5254 | if (acl == NULL) |
| 5255 | goto out; |
| 5256 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5257 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5258 | } else { |
| 5259 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5260 | if (acl == NULL) |
| 5261 | goto out; |
| 5262 | acl->cached = 0; |
| 5263 | } |
| 5264 | acl->len = acl_len; |
| 5265 | out: |
| 5266 | nfs4_set_cached_acl(inode, acl); |
| 5267 | } |
| 5268 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5269 | /* |
| 5270 | * The getxattr API returns the required buffer length when called with a |
| 5271 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5272 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5273 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5274 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5275 | * the cache. If not so, we throw away the page, and cache the required |
| 5276 | * length. The next getxattr call will then produce another round trip to |
| 5277 | * the server, this time with the input buf of the required size. |
| 5278 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5279 | 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] | 5280 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5281 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5282 | struct nfs_getaclargs args = { |
| 5283 | .fh = NFS_FH(inode), |
| 5284 | .acl_pages = pages, |
| 5285 | .acl_len = buflen, |
| 5286 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5287 | struct nfs_getaclres res = { |
| 5288 | .acl_len = buflen, |
| 5289 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5290 | struct rpc_message msg = { |
| 5291 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5292 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5293 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5294 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5295 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5296 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5297 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5298 | if (npages > ARRAY_SIZE(pages)) |
| 5299 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5300 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5301 | for (i = 0; i < npages; i++) { |
| 5302 | pages[i] = alloc_page(GFP_KERNEL); |
| 5303 | if (!pages[i]) |
| 5304 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5305 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5306 | |
| 5307 | /* for decoding across pages */ |
| 5308 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5309 | if (!res.acl_scratch) |
| 5310 | goto out_free; |
| 5311 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5312 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5313 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5314 | 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] | 5315 | __func__, buf, buflen, npages, args.acl_len); |
| 5316 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5317 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5318 | if (ret) |
| 5319 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5320 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5321 | /* Handle the case where the passed-in buffer is too short */ |
| 5322 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5323 | /* Did the user only issue a request for the acl length? */ |
| 5324 | if (buf == NULL) |
| 5325 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5326 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5327 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5328 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5329 | 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] | 5330 | if (buf) { |
| 5331 | if (res.acl_len > buflen) { |
| 5332 | ret = -ERANGE; |
| 5333 | goto out_free; |
| 5334 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5335 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5336 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5337 | out_ok: |
| 5338 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5339 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5340 | for (i = 0; i < npages; i++) |
| 5341 | if (pages[i]) |
| 5342 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5343 | if (res.acl_scratch) |
| 5344 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5345 | return ret; |
| 5346 | } |
| 5347 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5348 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5349 | { |
| 5350 | struct nfs4_exception exception = { }; |
| 5351 | ssize_t ret; |
| 5352 | do { |
| 5353 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5354 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5355 | if (ret >= 0) |
| 5356 | break; |
| 5357 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5358 | } while (exception.retry); |
| 5359 | return ret; |
| 5360 | } |
| 5361 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5362 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5363 | { |
| 5364 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5365 | int ret; |
| 5366 | |
| 5367 | if (!nfs4_server_supports_acls(server)) |
| 5368 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5369 | ret = nfs_revalidate_inode(server, inode); |
| 5370 | if (ret < 0) |
| 5371 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5372 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5373 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5374 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5375 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5376 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5377 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5378 | return ret; |
| 5379 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5382 | 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] | 5383 | { |
| 5384 | struct nfs_server *server = NFS_SERVER(inode); |
| 5385 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5386 | struct nfs_setaclargs arg = { |
| 5387 | .fh = NFS_FH(inode), |
| 5388 | .acl_pages = pages, |
| 5389 | .acl_len = buflen, |
| 5390 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5391 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5392 | struct rpc_message msg = { |
| 5393 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5394 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5395 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5396 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5397 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5398 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5399 | |
| 5400 | if (!nfs4_server_supports_acls(server)) |
| 5401 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5402 | if (npages > ARRAY_SIZE(pages)) |
| 5403 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5404 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5405 | if (i < 0) |
| 5406 | return i; |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 5407 | nfs4_inode_make_writeable(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5408 | 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] | 5409 | |
| 5410 | /* |
| 5411 | * Free each page after tx, so the only ref left is |
| 5412 | * held by the network stack |
| 5413 | */ |
| 5414 | for (; i > 0; i--) |
| 5415 | put_page(pages[i-1]); |
| 5416 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5417 | /* |
| 5418 | * Acl update can result in inode attribute update. |
| 5419 | * so mark the attribute cache invalid. |
| 5420 | */ |
| 5421 | spin_lock(&inode->i_lock); |
Trond Myklebust | 16e1437 | 2018-03-20 16:53:31 -0400 | [diff] [blame] | 5422 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE |
Trond Myklebust | 472f761 | 2018-04-08 18:14:43 -0400 | [diff] [blame] | 5423 | | NFS_INO_INVALID_CTIME |
| 5424 | | NFS_INO_REVAL_FORCED; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5425 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5426 | nfs_access_zap_cache(inode); |
| 5427 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5428 | return ret; |
| 5429 | } |
| 5430 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5431 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5432 | { |
| 5433 | struct nfs4_exception exception = { }; |
| 5434 | int err; |
| 5435 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5436 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5437 | trace_nfs4_set_acl(inode, err); |
| 5438 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5439 | &exception); |
| 5440 | } while (exception.retry); |
| 5441 | return err; |
| 5442 | } |
| 5443 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5444 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5445 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5446 | size_t buflen) |
| 5447 | { |
| 5448 | struct nfs_server *server = NFS_SERVER(inode); |
| 5449 | struct nfs_fattr fattr; |
| 5450 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5451 | |
| 5452 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5453 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5454 | .fh = NFS_FH(inode), |
| 5455 | .bitmask = bitmask, |
| 5456 | }; |
| 5457 | struct nfs4_getattr_res res = { |
| 5458 | .fattr = &fattr, |
| 5459 | .label = &label, |
| 5460 | .server = server, |
| 5461 | }; |
| 5462 | struct rpc_message msg = { |
| 5463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5464 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5465 | .rpc_resp = &res, |
| 5466 | }; |
| 5467 | int ret; |
| 5468 | |
| 5469 | nfs_fattr_init(&fattr); |
| 5470 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5471 | 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] | 5472 | if (ret) |
| 5473 | return ret; |
| 5474 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5475 | return -ENOENT; |
| 5476 | if (buflen < label.len) |
| 5477 | return -ERANGE; |
| 5478 | return 0; |
| 5479 | } |
| 5480 | |
| 5481 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5482 | size_t buflen) |
| 5483 | { |
| 5484 | struct nfs4_exception exception = { }; |
| 5485 | int err; |
| 5486 | |
| 5487 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5488 | return -EOPNOTSUPP; |
| 5489 | |
| 5490 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5491 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5492 | trace_nfs4_get_security_label(inode, err); |
| 5493 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5494 | &exception); |
| 5495 | } while (exception.retry); |
| 5496 | return err; |
| 5497 | } |
| 5498 | |
| 5499 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5500 | struct nfs4_label *ilabel, |
| 5501 | struct nfs_fattr *fattr, |
| 5502 | struct nfs4_label *olabel) |
| 5503 | { |
| 5504 | |
| 5505 | struct iattr sattr = {0}; |
| 5506 | struct nfs_server *server = NFS_SERVER(inode); |
| 5507 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5508 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5509 | .fh = NFS_FH(inode), |
| 5510 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5511 | .server = server, |
| 5512 | .bitmask = bitmask, |
| 5513 | .label = ilabel, |
| 5514 | }; |
| 5515 | struct nfs_setattrres res = { |
| 5516 | .fattr = fattr, |
| 5517 | .label = olabel, |
| 5518 | .server = server, |
| 5519 | }; |
| 5520 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5522 | .rpc_argp = &arg, |
| 5523 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5524 | }; |
| 5525 | int status; |
| 5526 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5527 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5528 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5529 | 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] | 5530 | if (status) |
| 5531 | dprintk("%s failed: %d\n", __func__, status); |
| 5532 | |
| 5533 | return status; |
| 5534 | } |
| 5535 | |
| 5536 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5537 | struct nfs4_label *ilabel, |
| 5538 | struct nfs_fattr *fattr, |
| 5539 | struct nfs4_label *olabel) |
| 5540 | { |
| 5541 | struct nfs4_exception exception = { }; |
| 5542 | int err; |
| 5543 | |
| 5544 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5545 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5546 | fattr, olabel); |
| 5547 | trace_nfs4_set_security_label(inode, err); |
| 5548 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5549 | &exception); |
| 5550 | } while (exception.retry); |
| 5551 | return err; |
| 5552 | } |
| 5553 | |
| 5554 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5555 | 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] | 5556 | { |
| 5557 | struct nfs4_label ilabel, *olabel = NULL; |
| 5558 | struct nfs_fattr fattr; |
| 5559 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5560 | int status; |
| 5561 | |
| 5562 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5563 | return -EOPNOTSUPP; |
| 5564 | |
| 5565 | nfs_fattr_init(&fattr); |
| 5566 | |
| 5567 | ilabel.pi = 0; |
| 5568 | ilabel.lfs = 0; |
| 5569 | ilabel.label = (char *)buf; |
| 5570 | ilabel.len = buflen; |
| 5571 | |
| 5572 | cred = rpc_lookup_cred(); |
| 5573 | if (IS_ERR(cred)) |
| 5574 | return PTR_ERR(cred); |
| 5575 | |
| 5576 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5577 | if (IS_ERR(olabel)) { |
| 5578 | status = -PTR_ERR(olabel); |
| 5579 | goto out; |
| 5580 | } |
| 5581 | |
| 5582 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5583 | if (status == 0) |
| 5584 | nfs_setsecurity(inode, &fattr, olabel); |
| 5585 | |
| 5586 | nfs4_label_free(olabel); |
| 5587 | out: |
| 5588 | put_rpccred(cred); |
| 5589 | return status; |
| 5590 | } |
| 5591 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5592 | |
| 5593 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5594 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5595 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5596 | { |
| 5597 | __be32 verf[2]; |
| 5598 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5599 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5600 | /* An impossible timestamp guarantees this value |
| 5601 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5602 | verf[0] = cpu_to_be32(U32_MAX); |
| 5603 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5604 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5605 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5606 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5607 | |
| 5608 | verf[0] = cpu_to_be32(ns >> 32); |
| 5609 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5610 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5611 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5612 | } |
| 5613 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5614 | static int |
| 5615 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5616 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5617 | size_t len; |
| 5618 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5619 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5620 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5621 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5622 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5623 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5624 | len = 14 + |
| 5625 | strlen(clp->cl_rpcclient->cl_nodename) + |
| 5626 | 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5627 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5628 | 1; |
| 5629 | rcu_read_unlock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5630 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 5631 | len += strlen(nfs4_client_id_uniquifier) + 1; |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5632 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5633 | return -EINVAL; |
| 5634 | |
| 5635 | /* |
| 5636 | * Since this string is allocated at mount time, and held until the |
| 5637 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5638 | * about a memory-reclaim deadlock. |
| 5639 | */ |
| 5640 | str = kmalloc(len, GFP_KERNEL); |
| 5641 | if (!str) |
| 5642 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5643 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5644 | rcu_read_lock(); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5645 | if (nfs4_client_id_uniquifier[0] != '\0') |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5646 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5647 | clp->cl_rpcclient->cl_nodename, |
| 5648 | nfs4_client_id_uniquifier, |
| 5649 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5650 | RPC_DISPLAY_ADDR)); |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5651 | else |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5652 | scnprintf(str, len, "Linux NFSv4.0 %s/%s", |
Chuck Lever | 848a4eb | 2018-06-04 10:53:29 -0400 | [diff] [blame] | 5653 | clp->cl_rpcclient->cl_nodename, |
| 5654 | rpc_peeraddr2str(clp->cl_rpcclient, |
Chuck Lever | 025bb9f | 2018-06-04 10:53:34 -0400 | [diff] [blame] | 5655 | RPC_DISPLAY_ADDR)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5656 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5657 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5658 | clp->cl_owner_id = str; |
| 5659 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5660 | } |
| 5661 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5662 | static int |
| 5663 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5664 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5665 | size_t len; |
| 5666 | char *str; |
| 5667 | |
| 5668 | len = 10 + 10 + 1 + 10 + 1 + |
| 5669 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5670 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5671 | |
| 5672 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5673 | return -EINVAL; |
| 5674 | |
| 5675 | /* |
| 5676 | * Since this string is allocated at mount time, and held until the |
| 5677 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5678 | * about a memory-reclaim deadlock. |
| 5679 | */ |
| 5680 | str = kmalloc(len, GFP_KERNEL); |
| 5681 | if (!str) |
| 5682 | return -ENOMEM; |
| 5683 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5684 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5685 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5686 | nfs4_client_id_uniquifier, |
| 5687 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5688 | clp->cl_owner_id = str; |
| 5689 | return 0; |
| 5690 | } |
| 5691 | |
| 5692 | static int |
| 5693 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5694 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5695 | size_t len; |
| 5696 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5697 | |
| 5698 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5699 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5700 | |
| 5701 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5702 | return nfs4_init_uniquifier_client_string(clp); |
| 5703 | |
| 5704 | len = 10 + 10 + 1 + 10 + 1 + |
| 5705 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5706 | |
| 5707 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5708 | return -EINVAL; |
| 5709 | |
| 5710 | /* |
| 5711 | * Since this string is allocated at mount time, and held until the |
| 5712 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5713 | * about a memory-reclaim deadlock. |
| 5714 | */ |
| 5715 | str = kmalloc(len, GFP_KERNEL); |
| 5716 | if (!str) |
| 5717 | return -ENOMEM; |
| 5718 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5719 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5720 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5721 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5722 | clp->cl_owner_id = str; |
| 5723 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5724 | } |
| 5725 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5726 | /* |
| 5727 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5728 | * services. Advertise one based on the address family of the |
| 5729 | * clientaddr. |
| 5730 | */ |
| 5731 | static unsigned int |
| 5732 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5733 | { |
| 5734 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5735 | return scnprintf(buf, len, "tcp6"); |
| 5736 | else |
| 5737 | return scnprintf(buf, len, "tcp"); |
| 5738 | } |
| 5739 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5740 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5741 | { |
| 5742 | struct nfs4_setclientid *sc = calldata; |
| 5743 | |
| 5744 | if (task->tk_status == 0) |
| 5745 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5746 | } |
| 5747 | |
| 5748 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5749 | .rpc_call_done = nfs4_setclientid_done, |
| 5750 | }; |
| 5751 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5752 | /** |
| 5753 | * nfs4_proc_setclientid - Negotiate client ID |
| 5754 | * @clp: state data structure |
| 5755 | * @program: RPC program for NFSv4 callback service |
| 5756 | * @port: IP port number for NFS4 callback service |
| 5757 | * @cred: RPC credential to use for this call |
| 5758 | * @res: where to place the result |
| 5759 | * |
| 5760 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5761 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5762 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5763 | unsigned short port, struct rpc_cred *cred, |
| 5764 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5765 | { |
| 5766 | nfs4_verifier sc_verifier; |
| 5767 | struct nfs4_setclientid setclientid = { |
| 5768 | .sc_verifier = &sc_verifier, |
| 5769 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5770 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | }; |
| 5772 | struct rpc_message msg = { |
| 5773 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5774 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5775 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5776 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5777 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5778 | struct rpc_task *task; |
| 5779 | struct rpc_task_setup task_setup_data = { |
| 5780 | .rpc_client = clp->cl_rpcclient, |
| 5781 | .rpc_message = &msg, |
| 5782 | .callback_ops = &nfs4_setclientid_ops, |
| 5783 | .callback_data = &setclientid, |
| 5784 | .flags = RPC_TASK_TIMEOUT, |
| 5785 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5786 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5788 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5789 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5790 | |
| 5791 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5792 | status = nfs4_init_uniform_client_string(clp); |
| 5793 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5794 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5795 | |
| 5796 | if (status) |
| 5797 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5798 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5799 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5800 | setclientid.sc_netid_len = |
| 5801 | nfs4_init_callback_netid(clp, |
| 5802 | setclientid.sc_netid, |
| 5803 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5804 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5805 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5807 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5808 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5809 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5810 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5811 | task = rpc_run_task(&task_setup_data); |
| 5812 | if (IS_ERR(task)) { |
| 5813 | status = PTR_ERR(task); |
| 5814 | goto out; |
| 5815 | } |
| 5816 | status = task->tk_status; |
| 5817 | if (setclientid.sc_cred) { |
| 5818 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5819 | put_rpccred(setclientid.sc_cred); |
| 5820 | } |
| 5821 | rpc_put_task(task); |
| 5822 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5823 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5824 | dprintk("NFS reply setclientid: %d\n", status); |
| 5825 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5828 | /** |
| 5829 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5830 | * @clp: state data structure |
| 5831 | * @res: result of a previous SETCLIENTID |
| 5832 | * @cred: RPC credential to use for this call |
| 5833 | * |
| 5834 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5835 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5836 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5837 | struct nfs4_setclientid_res *arg, |
| 5838 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | struct rpc_message msg = { |
| 5841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5842 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5843 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5845 | int status; |
| 5846 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5847 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5848 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5849 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5850 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5851 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5852 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | return status; |
| 5854 | } |
| 5855 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5856 | struct nfs4_delegreturndata { |
| 5857 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5858 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5859 | struct nfs_fh fh; |
| 5860 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5861 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5862 | struct { |
| 5863 | struct nfs4_layoutreturn_args arg; |
| 5864 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5865 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5866 | u32 roc_barrier; |
| 5867 | bool roc; |
| 5868 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5869 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5870 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5871 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5872 | }; |
| 5873 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5874 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5875 | { |
| 5876 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5877 | struct nfs4_exception exception = { |
| 5878 | .inode = data->inode, |
| 5879 | .stateid = &data->stateid, |
| 5880 | }; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5881 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5882 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5883 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5884 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5885 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5886 | |
| 5887 | /* Handle Layoutreturn errors */ |
| 5888 | if (data->args.lr_args && task->tk_status != 0) { |
| 5889 | switch(data->res.lr_ret) { |
| 5890 | default: |
| 5891 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5892 | break; |
| 5893 | case 0: |
| 5894 | data->args.lr_args = NULL; |
| 5895 | data->res.lr_res = NULL; |
| 5896 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5897 | case -NFS4ERR_OLD_STATEID: |
| 5898 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5899 | data->inode)) |
| 5900 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5901 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5902 | case -NFS4ERR_ADMIN_REVOKED: |
| 5903 | case -NFS4ERR_DELEG_REVOKED: |
| 5904 | case -NFS4ERR_EXPIRED: |
| 5905 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5906 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5907 | case -NFS4ERR_WRONG_CRED: |
| 5908 | data->args.lr_args = NULL; |
| 5909 | data->res.lr_res = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5910 | goto lr_restart; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5914 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5915 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5916 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5917 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5918 | case -NFS4ERR_ADMIN_REVOKED: |
| 5919 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5920 | case -NFS4ERR_EXPIRED: |
| 5921 | nfs4_free_revoked_stateid(data->res.server, |
| 5922 | data->args.stateid, |
| 5923 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5924 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5925 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5926 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5927 | task->tk_status = 0; |
| 5928 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5929 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5930 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
| 5931 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5932 | task->tk_status = 0; |
| 5933 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5934 | case -NFS4ERR_ACCESS: |
| 5935 | if (data->args.bitmask) { |
| 5936 | data->args.bitmask = NULL; |
| 5937 | data->res.fattr = NULL; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5938 | goto out_restart; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5939 | } |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5940 | /* Fallthrough */ |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5941 | default: |
Trond Myklebust | e0dba01 | 2017-11-07 11:02:32 -0500 | [diff] [blame] | 5942 | task->tk_status = nfs4_async_handle_exception(task, |
| 5943 | data->res.server, task->tk_status, |
| 5944 | &exception); |
| 5945 | if (exception.retry) |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5946 | goto out_restart; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5947 | } |
| 5948 | data->rpc_status = task->tk_status; |
Trond Myklebust | 140087fd | 2017-11-06 15:28:10 -0500 | [diff] [blame] | 5949 | return; |
| 5950 | lr_restart: |
| 5951 | data->res.lr_ret = 0; |
| 5952 | out_restart: |
| 5953 | task->tk_status = 0; |
| 5954 | rpc_restart_call_prepare(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | static void nfs4_delegreturn_release(void *calldata) |
| 5958 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5959 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5960 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5961 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5962 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5963 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5964 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5965 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5966 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5967 | nfs_iput_and_deactive(inode); |
| 5968 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5969 | kfree(calldata); |
| 5970 | } |
| 5971 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5972 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5973 | { |
| 5974 | struct nfs4_delegreturndata *d_data; |
| 5975 | |
| 5976 | d_data = (struct nfs4_delegreturndata *)data; |
| 5977 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5978 | 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] | 5979 | return; |
| 5980 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5981 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5982 | &d_data->args.seq_args, |
| 5983 | &d_data->res.seq_res, |
| 5984 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5985 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5986 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5987 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5988 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5989 | .rpc_call_done = nfs4_delegreturn_done, |
| 5990 | .rpc_release = nfs4_delegreturn_release, |
| 5991 | }; |
| 5992 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5993 | 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] | 5994 | { |
| 5995 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5996 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5997 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5998 | struct rpc_message msg = { |
| 5999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 6000 | .rpc_cred = cred, |
| 6001 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6002 | struct rpc_task_setup task_setup_data = { |
| 6003 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6004 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6005 | .callback_ops = &nfs4_delegreturn_ops, |
| 6006 | .flags = RPC_TASK_ASYNC, |
| 6007 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6008 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6009 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6010 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6011 | if (data == NULL) |
| 6012 | return -ENOMEM; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6013 | 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] | 6014 | |
| 6015 | nfs4_state_protect(server->nfs_client, |
| 6016 | NFS_SP4_MACH_CRED_CLEANUP, |
| 6017 | &task_setup_data.rpc_client, &msg); |
| 6018 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6019 | data->args.fhandle = &data->fh; |
| 6020 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 6021 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6022 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6023 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 6024 | data->res.fattr = &data->fattr; |
| 6025 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 6026 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 6027 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6028 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6029 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6030 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6031 | 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] | 6032 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6033 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6034 | if (data->lr.roc) { |
| 6035 | data->args.lr_args = &data->lr.arg; |
| 6036 | data->res.lr_res = &data->lr.res; |
| 6037 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 6038 | } else if (data->lr.roc) { |
| 6039 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 6040 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 6041 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6042 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6043 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6044 | msg.rpc_argp = &data->args; |
| 6045 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6046 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6047 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6048 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6049 | if (!issync) |
| 6050 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6051 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6052 | if (status != 0) |
| 6053 | goto out; |
| 6054 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6055 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6056 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 6057 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6060 | 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] | 6061 | { |
| 6062 | struct nfs_server *server = NFS_SERVER(inode); |
| 6063 | struct nfs4_exception exception = { }; |
| 6064 | int err; |
| 6065 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 6066 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6067 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | switch (err) { |
| 6069 | case -NFS4ERR_STALE_STATEID: |
| 6070 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6071 | case 0: |
| 6072 | return 0; |
| 6073 | } |
| 6074 | err = nfs4_handle_exception(server, err, &exception); |
| 6075 | } while (exception.retry); |
| 6076 | return err; |
| 6077 | } |
| 6078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6079 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6080 | { |
| 6081 | struct inode *inode = state->inode; |
| 6082 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6083 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6084 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6086 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6088 | struct nfs_lockt_res res = { |
| 6089 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6090 | }; |
| 6091 | struct rpc_message msg = { |
| 6092 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 6093 | .rpc_argp = &arg, |
| 6094 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | .rpc_cred = state->owner->so_cred, |
| 6096 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6097 | struct nfs4_lock_state *lsp; |
| 6098 | int status; |
| 6099 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6100 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6101 | status = nfs4_set_lock_state(state, request); |
| 6102 | if (status != 0) |
| 6103 | goto out; |
| 6104 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6105 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6106 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6107 | 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] | 6108 | switch (status) { |
| 6109 | case 0: |
| 6110 | request->fl_type = F_UNLCK; |
| 6111 | break; |
| 6112 | case -NFS4ERR_DENIED: |
| 6113 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6114 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 6115 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6116 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6117 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6118 | return status; |
| 6119 | } |
| 6120 | |
| 6121 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6122 | { |
| 6123 | struct nfs4_exception exception = { }; |
| 6124 | int err; |
| 6125 | |
| 6126 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6127 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6128 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6129 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | &exception); |
| 6131 | } while (exception.retry); |
| 6132 | return err; |
| 6133 | } |
| 6134 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6135 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6136 | struct nfs_locku_args arg; |
| 6137 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6138 | struct nfs4_lock_state *lsp; |
| 6139 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6140 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6141 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6142 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6143 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6144 | }; |
| 6145 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6146 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6147 | struct nfs_open_context *ctx, |
| 6148 | struct nfs4_lock_state *lsp, |
| 6149 | struct nfs_seqid *seqid) |
| 6150 | { |
| 6151 | struct nfs4_unlockdata *p; |
| 6152 | struct inode *inode = lsp->ls_state->inode; |
| 6153 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6154 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6155 | if (p == NULL) |
| 6156 | return NULL; |
| 6157 | p->arg.fh = NFS_FH(inode); |
| 6158 | p->arg.fl = &p->fl; |
| 6159 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6160 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6161 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6162 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6163 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6164 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6165 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6166 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6167 | p->server = NFS_SERVER(inode); |
| 6168 | return p; |
| 6169 | } |
| 6170 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6171 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6172 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6173 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6174 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6175 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6176 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6177 | put_nfs_open_context(calldata->ctx); |
| 6178 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6181 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6182 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6183 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6184 | struct nfs4_exception exception = { |
| 6185 | .inode = calldata->lsp->ls_state->inode, |
| 6186 | .stateid = &calldata->arg.stateid, |
| 6187 | }; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6188 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6189 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6190 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6191 | switch (task->tk_status) { |
| 6192 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6193 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6194 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6195 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6196 | &calldata->res.stateid)) |
| 6197 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6198 | case -NFS4ERR_ADMIN_REVOKED: |
| 6199 | case -NFS4ERR_EXPIRED: |
| 6200 | nfs4_free_revoked_stateid(calldata->server, |
| 6201 | &calldata->arg.stateid, |
| 6202 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6203 | case -NFS4ERR_BAD_STATEID: |
| 6204 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6205 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6206 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6207 | &calldata->lsp->ls_stateid)) |
| 6208 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6209 | break; |
| 6210 | default: |
Trond Myklebust | 8257155 | 2017-11-07 11:14:49 -0500 | [diff] [blame] | 6211 | task->tk_status = nfs4_async_handle_exception(task, |
| 6212 | calldata->server, task->tk_status, |
| 6213 | &exception); |
| 6214 | if (exception.retry) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6215 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6216 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6217 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6220 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6221 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6222 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6224 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6225 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6226 | return; |
| 6227 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6228 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6229 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6230 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6231 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6232 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6233 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6234 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6235 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6236 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6237 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6238 | &calldata->res.seq_res, |
| 6239 | task) != 0) |
| 6240 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6241 | return; |
| 6242 | out_no_action: |
| 6243 | task->tk_action = NULL; |
| 6244 | out_wait: |
| 6245 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | } |
| 6247 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6248 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6249 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6250 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6251 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6252 | }; |
| 6253 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6254 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6255 | struct nfs_open_context *ctx, |
| 6256 | struct nfs4_lock_state *lsp, |
| 6257 | struct nfs_seqid *seqid) |
| 6258 | { |
| 6259 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6260 | struct rpc_message msg = { |
| 6261 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6262 | .rpc_cred = ctx->cred, |
| 6263 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6264 | struct rpc_task_setup task_setup_data = { |
| 6265 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6266 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6267 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6268 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6269 | .flags = RPC_TASK_ASYNC, |
| 6270 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6271 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6272 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6273 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6274 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6275 | /* Ensure this is an unlock - when canceling a lock, the |
| 6276 | * canceled lock is passed in, and it won't be an unlock. |
| 6277 | */ |
| 6278 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6279 | if (fl->fl_flags & FL_CLOSE) |
| 6280 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6281 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6282 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6283 | if (data == NULL) { |
| 6284 | nfs_free_seqid(seqid); |
| 6285 | return ERR_PTR(-ENOMEM); |
| 6286 | } |
| 6287 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6288 | 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] | 6289 | msg.rpc_argp = &data->arg; |
| 6290 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6291 | task_setup_data.callback_data = data; |
| 6292 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6293 | } |
| 6294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6296 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6297 | struct inode *inode = state->inode; |
| 6298 | struct nfs4_state_owner *sp = state->owner; |
| 6299 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6300 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6301 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6302 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6303 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6304 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6305 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6307 | status = nfs4_set_lock_state(state, request); |
| 6308 | /* Unlock _before_ we do the RPC call */ |
| 6309 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6310 | /* Exclude nfs_delegation_claim_locks() */ |
| 6311 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6312 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6313 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6314 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6315 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6316 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6317 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6318 | } |
| 6319 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6320 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6321 | if (status != 0) |
| 6322 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6323 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6324 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6325 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6326 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6327 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6328 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6329 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6330 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6331 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6332 | 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] | 6333 | status = PTR_ERR(task); |
| 6334 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6335 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6336 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6337 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6338 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6339 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6340 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6341 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | } |
| 6343 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6344 | struct nfs4_lockdata { |
| 6345 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6346 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6347 | struct nfs4_lock_state *lsp; |
| 6348 | struct nfs_open_context *ctx; |
| 6349 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6350 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6351 | int rpc_status; |
| 6352 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6353 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6354 | }; |
| 6355 | |
| 6356 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6357 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6358 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6359 | { |
| 6360 | struct nfs4_lockdata *p; |
| 6361 | struct inode *inode = lsp->ls_state->inode; |
| 6362 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6363 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6364 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6365 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6366 | if (p == NULL) |
| 6367 | return NULL; |
| 6368 | |
| 6369 | p->arg.fh = NFS_FH(inode); |
| 6370 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6371 | 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] | 6372 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6373 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6374 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6375 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6376 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6377 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6378 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6379 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6380 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6381 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6382 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6383 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6384 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6385 | p->ctx = get_nfs_open_context(ctx); |
| 6386 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6387 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6388 | out_free_seqid: |
| 6389 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6390 | out_free: |
| 6391 | kfree(p); |
| 6392 | return NULL; |
| 6393 | } |
| 6394 | |
| 6395 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6396 | { |
| 6397 | struct nfs4_lockdata *data = calldata; |
| 6398 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6400 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6401 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6402 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6403 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6404 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6405 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6406 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6407 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6408 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6409 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6410 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6411 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6412 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6413 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6414 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6415 | &data->lsp->ls_stateid); |
| 6416 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6417 | if (!nfs4_valid_open_stateid(state)) { |
| 6418 | data->rpc_status = -EBADF; |
| 6419 | task->tk_action = NULL; |
| 6420 | goto out_release_open_seqid; |
| 6421 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6422 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6423 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6424 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6425 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6426 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6427 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6428 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6429 | nfs_release_seqid(data->arg.open_seqid); |
| 6430 | out_release_lock_seqid: |
| 6431 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6432 | out_wait: |
| 6433 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6434 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6435 | } |
| 6436 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6437 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6438 | { |
| 6439 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6440 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6441 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6442 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6443 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6444 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6445 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6446 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6447 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6448 | switch (task->tk_status) { |
| 6449 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6450 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6451 | data->timestamp); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6452 | if (data->arg.new_lock && !data->cancelled) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6453 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6454 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6455 | break; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6456 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6457 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6458 | if (data->arg.new_lock_owner != 0) { |
| 6459 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6460 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6461 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6462 | goto out_done; |
| 6463 | } else if (nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6464 | goto out_done; |
| 6465 | |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6466 | break; |
| 6467 | case -NFS4ERR_BAD_STATEID: |
| 6468 | case -NFS4ERR_OLD_STATEID: |
| 6469 | case -NFS4ERR_STALE_STATEID: |
| 6470 | case -NFS4ERR_EXPIRED: |
| 6471 | if (data->arg.new_lock_owner != 0) { |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6472 | if (nfs4_stateid_match(&data->arg.open_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6473 | &lsp->ls_state->open_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6474 | goto out_done; |
| 6475 | } else if (nfs4_stateid_match(&data->arg.lock_stateid, |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6476 | &lsp->ls_stateid)) |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6477 | goto out_done; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6478 | } |
Benjamin Coddington | a3cf9bc | 2018-05-03 07:12:57 -0400 | [diff] [blame] | 6479 | if (!data->cancelled) |
| 6480 | rpc_restart_call_prepare(task); |
| 6481 | out_done: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6482 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | static void nfs4_lock_release(void *calldata) |
| 6486 | { |
| 6487 | struct nfs4_lockdata *data = calldata; |
| 6488 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6489 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6490 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6491 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6492 | struct rpc_task *task; |
| 6493 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6494 | data->arg.lock_seqid); |
| 6495 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6496 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6497 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6498 | } else |
| 6499 | nfs_free_seqid(data->arg.lock_seqid); |
| 6500 | nfs4_put_lock_state(data->lsp); |
| 6501 | put_nfs_open_context(data->ctx); |
| 6502 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6503 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6504 | } |
| 6505 | |
| 6506 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6507 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6508 | .rpc_call_done = nfs4_lock_done, |
| 6509 | .rpc_release = nfs4_lock_release, |
| 6510 | }; |
| 6511 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6512 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6513 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6514 | switch (error) { |
| 6515 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6516 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6517 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6518 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6519 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6520 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6521 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6522 | break; |
| 6523 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6524 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6525 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6526 | }; |
| 6527 | } |
| 6528 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6529 | 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] | 6530 | { |
| 6531 | struct nfs4_lockdata *data; |
| 6532 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6533 | struct rpc_message msg = { |
| 6534 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6535 | .rpc_cred = state->owner->so_cred, |
| 6536 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6537 | struct rpc_task_setup task_setup_data = { |
| 6538 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6539 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6540 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6541 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6542 | .flags = RPC_TASK_ASYNC, |
| 6543 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6544 | int ret; |
| 6545 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6546 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6547 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6548 | fl->fl_u.nfs4_fl.owner, |
| 6549 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6550 | if (data == NULL) |
| 6551 | return -ENOMEM; |
| 6552 | if (IS_SETLKW(cmd)) |
| 6553 | data->arg.block = 1; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6554 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1, |
| 6555 | recovery_type > NFS_LOCK_NEW); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6556 | msg.rpc_argp = &data->arg; |
| 6557 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6558 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6559 | if (recovery_type > NFS_LOCK_NEW) { |
| 6560 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6561 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6562 | } else |
| 6563 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6564 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6565 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6566 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6567 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6568 | if (ret == 0) { |
| 6569 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6570 | if (ret) |
| 6571 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6572 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6573 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6574 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6575 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6576 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6577 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6578 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6582 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6583 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6584 | struct nfs4_exception exception = { |
| 6585 | .inode = state->inode, |
| 6586 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6587 | int err; |
| 6588 | |
| 6589 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6590 | /* Cache the lock if possible... */ |
| 6591 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6592 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6593 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6594 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6595 | break; |
| 6596 | nfs4_handle_exception(server, err, &exception); |
| 6597 | } while (exception.retry); |
| 6598 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6602 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6603 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6604 | struct nfs4_exception exception = { |
| 6605 | .inode = state->inode, |
| 6606 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6607 | int err; |
| 6608 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6609 | err = nfs4_set_lock_state(state, request); |
| 6610 | if (err != 0) |
| 6611 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6612 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6613 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6614 | return 0; |
| 6615 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6616 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6617 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6618 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6619 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6620 | switch (err) { |
| 6621 | default: |
| 6622 | goto out; |
| 6623 | case -NFS4ERR_GRACE: |
| 6624 | case -NFS4ERR_DELAY: |
| 6625 | nfs4_handle_exception(server, err, &exception); |
| 6626 | err = 0; |
| 6627 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6628 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6629 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6630 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6633 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6634 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6635 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6636 | struct nfs4_lock_state *lsp; |
| 6637 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6638 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6639 | status = nfs4_set_lock_state(state, request); |
| 6640 | if (status != 0) |
| 6641 | return status; |
| 6642 | lsp = request->fl_u.nfs4_fl.owner; |
| 6643 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6644 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6645 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6646 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6647 | } |
| 6648 | #endif |
| 6649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6650 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6651 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6652 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6653 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6654 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6655 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6656 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6657 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6658 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6659 | if (status < 0) |
| 6660 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6661 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6662 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6663 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6664 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6665 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6666 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6667 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6668 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6669 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6670 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6671 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6672 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6673 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6674 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6675 | out: |
| 6676 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6677 | return status; |
| 6678 | } |
| 6679 | |
| 6680 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6681 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6682 | struct nfs4_exception exception = { |
| 6683 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6684 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6685 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6686 | int err; |
| 6687 | |
| 6688 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6689 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6690 | if (err == -NFS4ERR_DENIED) |
| 6691 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6692 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6693 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6694 | } while (exception.retry); |
| 6695 | return err; |
| 6696 | } |
| 6697 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6698 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6699 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6700 | |
| 6701 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6702 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6703 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6704 | { |
| 6705 | int status = -ERESTARTSYS; |
| 6706 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6707 | |
| 6708 | while(!signalled()) { |
| 6709 | status = nfs4_proc_setlk(state, cmd, request); |
| 6710 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6711 | break; |
| 6712 | freezable_schedule_timeout_interruptible(timeout); |
| 6713 | timeout *= 2; |
| 6714 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6715 | status = -ERESTARTSYS; |
| 6716 | } |
| 6717 | return status; |
| 6718 | } |
| 6719 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6720 | #ifdef CONFIG_NFS_V4_1 |
| 6721 | struct nfs4_lock_waiter { |
| 6722 | struct task_struct *task; |
| 6723 | struct inode *inode; |
| 6724 | struct nfs_lowner *owner; |
| 6725 | bool notified; |
| 6726 | }; |
| 6727 | |
| 6728 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6729 | 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] | 6730 | { |
| 6731 | int ret; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6732 | struct nfs4_lock_waiter *waiter = wait->private; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6733 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6734 | /* NULL key means to wake up everyone */ |
| 6735 | if (key) { |
| 6736 | struct cb_notify_lock_args *cbnl = key; |
| 6737 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6738 | *wowner = waiter->owner; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6739 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6740 | /* Only wake if the callback was for the same owner. */ |
| 6741 | if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) |
| 6742 | return 0; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6743 | |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 6744 | /* Make sure it's for the right inode */ |
| 6745 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6746 | return 0; |
| 6747 | |
| 6748 | waiter->notified = true; |
| 6749 | } |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6750 | |
| 6751 | /* override "private" so we can use default_wake_function */ |
| 6752 | wait->private = waiter->task; |
| 6753 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6754 | wait->private = waiter; |
| 6755 | return ret; |
| 6756 | } |
| 6757 | |
| 6758 | static int |
| 6759 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6760 | { |
| 6761 | int status = -ERESTARTSYS; |
| 6762 | unsigned long flags; |
| 6763 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6764 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6765 | struct nfs_client *clp = server->nfs_client; |
| 6766 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6767 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6768 | .id = lsp->ls_seqid.owner_id, |
| 6769 | .s_dev = server->s_dev }; |
| 6770 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6771 | .inode = state->inode, |
| 6772 | .owner = &owner, |
| 6773 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6774 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6775 | |
| 6776 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6777 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6778 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6779 | |
| 6780 | init_wait(&wait); |
| 6781 | wait.private = &waiter; |
| 6782 | wait.func = nfs4_wake_lock_waiter; |
| 6783 | add_wait_queue(q, &wait); |
| 6784 | |
| 6785 | while(!signalled()) { |
Jeff Layton | 41a7462 | 2018-03-18 08:37:01 -0400 | [diff] [blame] | 6786 | waiter.notified = false; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6787 | status = nfs4_proc_setlk(state, cmd, request); |
| 6788 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6789 | break; |
| 6790 | |
| 6791 | status = -ERESTARTSYS; |
| 6792 | spin_lock_irqsave(&q->lock, flags); |
| 6793 | if (waiter.notified) { |
| 6794 | spin_unlock_irqrestore(&q->lock, flags); |
| 6795 | continue; |
| 6796 | } |
| 6797 | set_current_state(TASK_INTERRUPTIBLE); |
| 6798 | spin_unlock_irqrestore(&q->lock, flags); |
| 6799 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6800 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6801 | } |
| 6802 | |
| 6803 | finish_wait(q, &wait); |
| 6804 | return status; |
| 6805 | } |
| 6806 | #else /* !CONFIG_NFS_V4_1 */ |
| 6807 | static inline int |
| 6808 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6809 | { |
| 6810 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6811 | } |
| 6812 | #endif |
| 6813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6814 | static int |
| 6815 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6816 | { |
| 6817 | struct nfs_open_context *ctx; |
| 6818 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6819 | int status; |
| 6820 | |
| 6821 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6822 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6823 | state = ctx->state; |
| 6824 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6825 | if (IS_GETLK(cmd)) { |
| 6826 | if (state != NULL) |
| 6827 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6828 | return 0; |
| 6829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6830 | |
| 6831 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6832 | return -EINVAL; |
| 6833 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6834 | if (request->fl_type == F_UNLCK) { |
| 6835 | if (state != NULL) |
| 6836 | return nfs4_proc_unlck(state, cmd, request); |
| 6837 | return 0; |
| 6838 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6839 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6840 | if (state == NULL) |
| 6841 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6842 | |
| 6843 | if ((request->fl_flags & FL_POSIX) && |
| 6844 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6845 | return -ENOLCK; |
| 6846 | |
Benjamin Coddington | fcfa447 | 2017-11-10 06:27:49 -0500 | [diff] [blame] | 6847 | /* |
| 6848 | * Don't rely on the VFS having checked the file open mode, |
| 6849 | * since it won't do this for flock() locks. |
| 6850 | */ |
| 6851 | switch (request->fl_type) { |
| 6852 | case F_RDLCK: |
| 6853 | if (!(filp->f_mode & FMODE_READ)) |
| 6854 | return -EBADF; |
| 6855 | break; |
| 6856 | case F_WRLCK: |
| 6857 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6858 | return -EBADF; |
| 6859 | } |
| 6860 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6861 | status = nfs4_set_lock_state(state, request); |
| 6862 | if (status != 0) |
| 6863 | return status; |
| 6864 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6865 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | } |
| 6867 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6868 | 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] | 6869 | { |
| 6870 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6871 | int err; |
| 6872 | |
| 6873 | err = nfs4_set_lock_state(state, fl); |
| 6874 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6875 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6876 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
NeilBrown | dce2630 | 2017-12-13 09:57:09 +1100 | [diff] [blame] | 6877 | return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6878 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6879 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6880 | struct nfs_release_lockowner_data { |
| 6881 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6882 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6883 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6884 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6885 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6886 | }; |
| 6887 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6888 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6889 | { |
| 6890 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6891 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6892 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6893 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6894 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6895 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6899 | { |
| 6900 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6901 | struct nfs_server *server = data->server; |
| 6902 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6903 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6904 | |
| 6905 | switch (task->tk_status) { |
| 6906 | case 0: |
| 6907 | renew_lease(server, data->timestamp); |
| 6908 | break; |
| 6909 | case -NFS4ERR_STALE_CLIENTID: |
| 6910 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6911 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6912 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6913 | case -NFS4ERR_LEASE_MOVED: |
| 6914 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6915 | if (nfs4_async_handle_error(task, server, |
| 6916 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6917 | rpc_restart_call_prepare(task); |
| 6918 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6919 | } |
| 6920 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6921 | static void nfs4_release_lockowner_release(void *calldata) |
| 6922 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6923 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6924 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6925 | kfree(calldata); |
| 6926 | } |
| 6927 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6928 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6929 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6930 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6931 | .rpc_release = nfs4_release_lockowner_release, |
| 6932 | }; |
| 6933 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6934 | static void |
| 6935 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6936 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6937 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6938 | struct rpc_message msg = { |
| 6939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6940 | }; |
| 6941 | |
| 6942 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6943 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6944 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6945 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6946 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6947 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6948 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6949 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6950 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6951 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6952 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6953 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6954 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6955 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 6956 | 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] | 6957 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6958 | } |
| 6959 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6960 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6961 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6962 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6963 | struct dentry *unused, struct inode *inode, |
| 6964 | const char *key, const void *buf, |
| 6965 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6966 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6967 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6970 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6971 | struct dentry *unused, struct inode *inode, |
| 6972 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6973 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6974 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6975 | } |
| 6976 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6977 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6978 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6979 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6980 | } |
| 6981 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6982 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6983 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6984 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6985 | struct dentry *unused, struct inode *inode, |
| 6986 | const char *key, const void *buf, |
| 6987 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6988 | { |
| 6989 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6990 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6991 | |
| 6992 | return -EOPNOTSUPP; |
| 6993 | } |
| 6994 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6995 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6996 | struct dentry *unused, struct inode *inode, |
| 6997 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6998 | { |
| 6999 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 7000 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7001 | return -EOPNOTSUPP; |
| 7002 | } |
| 7003 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7004 | static ssize_t |
| 7005 | 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] | 7006 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7007 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7008 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7009 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 7010 | len = security_inode_listsecurity(inode, list, list_len); |
| 7011 | if (list_len && len > list_len) |
| 7012 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7013 | } |
| 7014 | return len; |
| 7015 | } |
| 7016 | |
| 7017 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 7018 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7019 | .get = nfs4_xattr_get_nfs4_label, |
| 7020 | .set = nfs4_xattr_set_nfs4_label, |
| 7021 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7022 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 7023 | #else |
| 7024 | |
| 7025 | static ssize_t |
| 7026 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 7027 | { |
| 7028 | return 0; |
| 7029 | } |
| 7030 | |
| 7031 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 7032 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7033 | /* |
| 7034 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 7035 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7036 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 7037 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7038 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 7039 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 7040 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7041 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7042 | return; |
| 7043 | |
| 7044 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 7045 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 7046 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 7047 | fattr->nlink = 2; |
| 7048 | } |
| 7049 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7050 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7051 | const struct qstr *name, |
| 7052 | struct nfs4_fs_locations *fs_locations, |
| 7053 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7054 | { |
| 7055 | struct nfs_server *server = NFS_SERVER(dir); |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7056 | u32 bitmask[3]; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7057 | struct nfs4_fs_locations_arg args = { |
| 7058 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7059 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7060 | .page = page, |
| 7061 | .bitmask = bitmask, |
| 7062 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7063 | struct nfs4_fs_locations_res res = { |
| 7064 | .fs_locations = fs_locations, |
| 7065 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7066 | struct rpc_message msg = { |
| 7067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7068 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 7069 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7070 | }; |
| 7071 | int status; |
| 7072 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 7073 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7074 | |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7075 | bitmask[0] = nfs4_fattr_bitmap[0] | FATTR4_WORD0_FS_LOCATIONS; |
| 7076 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 7077 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7078 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 7079 | * is not supported */ |
| 7080 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7081 | bitmask[0] &= ~FATTR4_WORD0_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7082 | else |
Chuck Lever | c05cefc | 2017-11-05 15:45:22 -0500 | [diff] [blame] | 7083 | bitmask[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 7084 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 7085 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7086 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 7087 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7088 | 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] | 7089 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 7090 | return status; |
| 7091 | } |
| 7092 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 7093 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 7094 | const struct qstr *name, |
| 7095 | struct nfs4_fs_locations *fs_locations, |
| 7096 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7097 | { |
| 7098 | struct nfs4_exception exception = { }; |
| 7099 | int err; |
| 7100 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7101 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 7102 | fs_locations, page); |
| 7103 | trace_nfs4_get_fs_locations(dir, name, err); |
| 7104 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 7105 | &exception); |
| 7106 | } while (exception.retry); |
| 7107 | return err; |
| 7108 | } |
| 7109 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7110 | /* |
| 7111 | * This operation also signals the server that this client is |
| 7112 | * performing migration recovery. The server can stop returning |
| 7113 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 7114 | * appended to this compound to identify the client ID which is |
| 7115 | * performing recovery. |
| 7116 | */ |
| 7117 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 7118 | struct nfs4_fs_locations *locations, |
| 7119 | struct page *page, struct rpc_cred *cred) |
| 7120 | { |
| 7121 | struct nfs_server *server = NFS_SERVER(inode); |
| 7122 | struct rpc_clnt *clnt = server->client; |
| 7123 | u32 bitmask[2] = { |
| 7124 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7125 | }; |
| 7126 | struct nfs4_fs_locations_arg args = { |
| 7127 | .clientid = server->nfs_client->cl_clientid, |
| 7128 | .fh = NFS_FH(inode), |
| 7129 | .page = page, |
| 7130 | .bitmask = bitmask, |
| 7131 | .migration = 1, /* skip LOOKUP */ |
| 7132 | .renew = 1, /* append RENEW */ |
| 7133 | }; |
| 7134 | struct nfs4_fs_locations_res res = { |
| 7135 | .fs_locations = locations, |
| 7136 | .migration = 1, |
| 7137 | .renew = 1, |
| 7138 | }; |
| 7139 | struct rpc_message msg = { |
| 7140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7141 | .rpc_argp = &args, |
| 7142 | .rpc_resp = &res, |
| 7143 | .rpc_cred = cred, |
| 7144 | }; |
| 7145 | unsigned long now = jiffies; |
| 7146 | int status; |
| 7147 | |
| 7148 | nfs_fattr_init(&locations->fattr); |
| 7149 | locations->server = server; |
| 7150 | locations->nlocations = 0; |
| 7151 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7152 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7153 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7154 | &args.seq_args, &res.seq_res); |
| 7155 | if (status) |
| 7156 | return status; |
| 7157 | |
| 7158 | renew_lease(server, now); |
| 7159 | return 0; |
| 7160 | } |
| 7161 | |
| 7162 | #ifdef CONFIG_NFS_V4_1 |
| 7163 | |
| 7164 | /* |
| 7165 | * This operation also signals the server that this client is |
| 7166 | * performing migration recovery. The server can stop asserting |
| 7167 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7168 | * performing this operation is identified in the SEQUENCE |
| 7169 | * operation in this compound. |
| 7170 | * |
| 7171 | * When the client supports GETATTR(fs_locations_info), it can |
| 7172 | * be plumbed in here. |
| 7173 | */ |
| 7174 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7175 | struct nfs4_fs_locations *locations, |
| 7176 | struct page *page, struct rpc_cred *cred) |
| 7177 | { |
| 7178 | struct nfs_server *server = NFS_SERVER(inode); |
| 7179 | struct rpc_clnt *clnt = server->client; |
| 7180 | u32 bitmask[2] = { |
| 7181 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7182 | }; |
| 7183 | struct nfs4_fs_locations_arg args = { |
| 7184 | .fh = NFS_FH(inode), |
| 7185 | .page = page, |
| 7186 | .bitmask = bitmask, |
| 7187 | .migration = 1, /* skip LOOKUP */ |
| 7188 | }; |
| 7189 | struct nfs4_fs_locations_res res = { |
| 7190 | .fs_locations = locations, |
| 7191 | .migration = 1, |
| 7192 | }; |
| 7193 | struct rpc_message msg = { |
| 7194 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7195 | .rpc_argp = &args, |
| 7196 | .rpc_resp = &res, |
| 7197 | .rpc_cred = cred, |
| 7198 | }; |
| 7199 | int status; |
| 7200 | |
| 7201 | nfs_fattr_init(&locations->fattr); |
| 7202 | locations->server = server; |
| 7203 | locations->nlocations = 0; |
| 7204 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7205 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 7206 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7207 | &args.seq_args, &res.seq_res); |
| 7208 | if (status == NFS4_OK && |
| 7209 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7210 | status = -NFS4ERR_LEASE_MOVED; |
| 7211 | return status; |
| 7212 | } |
| 7213 | |
| 7214 | #endif /* CONFIG_NFS_V4_1 */ |
| 7215 | |
| 7216 | /** |
| 7217 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7218 | * @inode: inode on FSID that is migrating |
| 7219 | * @locations: result of query |
| 7220 | * @page: buffer |
| 7221 | * @cred: credential to use for this operation |
| 7222 | * |
| 7223 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7224 | * operation failed, or a negative errno if a local error occurred. |
| 7225 | * |
| 7226 | * On success, "locations" is filled in, but if the server has |
| 7227 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7228 | * asserted. |
| 7229 | * |
| 7230 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7231 | * from this client that require migration recovery. |
| 7232 | */ |
| 7233 | int nfs4_proc_get_locations(struct inode *inode, |
| 7234 | struct nfs4_fs_locations *locations, |
| 7235 | struct page *page, struct rpc_cred *cred) |
| 7236 | { |
| 7237 | struct nfs_server *server = NFS_SERVER(inode); |
| 7238 | struct nfs_client *clp = server->nfs_client; |
| 7239 | const struct nfs4_mig_recovery_ops *ops = |
| 7240 | clp->cl_mvops->mig_recovery_ops; |
| 7241 | struct nfs4_exception exception = { }; |
| 7242 | int status; |
| 7243 | |
| 7244 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7245 | (unsigned long long)server->fsid.major, |
| 7246 | (unsigned long long)server->fsid.minor, |
| 7247 | clp->cl_hostname); |
| 7248 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7249 | |
| 7250 | do { |
| 7251 | status = ops->get_locations(inode, locations, page, cred); |
| 7252 | if (status != -NFS4ERR_DELAY) |
| 7253 | break; |
| 7254 | nfs4_handle_exception(server, status, &exception); |
| 7255 | } while (exception.retry); |
| 7256 | return status; |
| 7257 | } |
| 7258 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7259 | /* |
| 7260 | * This operation also signals the server that this client is |
| 7261 | * performing "lease moved" recovery. The server can stop |
| 7262 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7263 | * is appended to this compound to identify the client ID which is |
| 7264 | * performing recovery. |
| 7265 | */ |
| 7266 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7267 | { |
| 7268 | struct nfs_server *server = NFS_SERVER(inode); |
| 7269 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7270 | struct rpc_clnt *clnt = server->client; |
| 7271 | struct nfs4_fsid_present_arg args = { |
| 7272 | .fh = NFS_FH(inode), |
| 7273 | .clientid = clp->cl_clientid, |
| 7274 | .renew = 1, /* append RENEW */ |
| 7275 | }; |
| 7276 | struct nfs4_fsid_present_res res = { |
| 7277 | .renew = 1, |
| 7278 | }; |
| 7279 | struct rpc_message msg = { |
| 7280 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7281 | .rpc_argp = &args, |
| 7282 | .rpc_resp = &res, |
| 7283 | .rpc_cred = cred, |
| 7284 | }; |
| 7285 | unsigned long now = jiffies; |
| 7286 | int status; |
| 7287 | |
| 7288 | res.fh = nfs_alloc_fhandle(); |
| 7289 | if (res.fh == NULL) |
| 7290 | return -ENOMEM; |
| 7291 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7292 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7293 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7294 | &args.seq_args, &res.seq_res); |
| 7295 | nfs_free_fhandle(res.fh); |
| 7296 | if (status) |
| 7297 | return status; |
| 7298 | |
| 7299 | do_renew_lease(clp, now); |
| 7300 | return 0; |
| 7301 | } |
| 7302 | |
| 7303 | #ifdef CONFIG_NFS_V4_1 |
| 7304 | |
| 7305 | /* |
| 7306 | * This operation also signals the server that this client is |
| 7307 | * performing "lease moved" recovery. The server can stop asserting |
| 7308 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7309 | * this operation is identified in the SEQUENCE operation in this |
| 7310 | * compound. |
| 7311 | */ |
| 7312 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7313 | { |
| 7314 | struct nfs_server *server = NFS_SERVER(inode); |
| 7315 | struct rpc_clnt *clnt = server->client; |
| 7316 | struct nfs4_fsid_present_arg args = { |
| 7317 | .fh = NFS_FH(inode), |
| 7318 | }; |
| 7319 | struct nfs4_fsid_present_res res = { |
| 7320 | }; |
| 7321 | struct rpc_message msg = { |
| 7322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7323 | .rpc_argp = &args, |
| 7324 | .rpc_resp = &res, |
| 7325 | .rpc_cred = cred, |
| 7326 | }; |
| 7327 | int status; |
| 7328 | |
| 7329 | res.fh = nfs_alloc_fhandle(); |
| 7330 | if (res.fh == NULL) |
| 7331 | return -ENOMEM; |
| 7332 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 7333 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7334 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7335 | &args.seq_args, &res.seq_res); |
| 7336 | nfs_free_fhandle(res.fh); |
| 7337 | if (status == NFS4_OK && |
| 7338 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7339 | status = -NFS4ERR_LEASE_MOVED; |
| 7340 | return status; |
| 7341 | } |
| 7342 | |
| 7343 | #endif /* CONFIG_NFS_V4_1 */ |
| 7344 | |
| 7345 | /** |
| 7346 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7347 | * @inode: inode on FSID to check |
| 7348 | * @cred: credential to use for this operation |
| 7349 | * |
| 7350 | * Server indicates whether the FSID is present, moved, or not |
| 7351 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7352 | * condition for this client ID. |
| 7353 | * |
| 7354 | * Returns NFS4_OK if the FSID is present on this server, |
| 7355 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7356 | * NFS4ERR code if some error occurred on the server, or a |
| 7357 | * negative errno if a local failure occurred. |
| 7358 | */ |
| 7359 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7360 | { |
| 7361 | struct nfs_server *server = NFS_SERVER(inode); |
| 7362 | struct nfs_client *clp = server->nfs_client; |
| 7363 | const struct nfs4_mig_recovery_ops *ops = |
| 7364 | clp->cl_mvops->mig_recovery_ops; |
| 7365 | struct nfs4_exception exception = { }; |
| 7366 | int status; |
| 7367 | |
| 7368 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7369 | (unsigned long long)server->fsid.major, |
| 7370 | (unsigned long long)server->fsid.minor, |
| 7371 | clp->cl_hostname); |
| 7372 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7373 | |
| 7374 | do { |
| 7375 | status = ops->fsid_present(inode, cred); |
| 7376 | if (status != -NFS4ERR_DELAY) |
| 7377 | break; |
| 7378 | nfs4_handle_exception(server, status, &exception); |
| 7379 | } while (exception.retry); |
| 7380 | return status; |
| 7381 | } |
| 7382 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7383 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7384 | * If 'use_integrity' is true and the state managment nfs_client |
| 7385 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7386 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7387 | * Considerations sections. Otherwise, just use the user cred with the |
| 7388 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7389 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7390 | 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] | 7391 | { |
| 7392 | int status; |
| 7393 | struct nfs4_secinfo_arg args = { |
| 7394 | .dir_fh = NFS_FH(dir), |
| 7395 | .name = name, |
| 7396 | }; |
| 7397 | struct nfs4_secinfo_res res = { |
| 7398 | .flavors = flavors, |
| 7399 | }; |
| 7400 | struct rpc_message msg = { |
| 7401 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7402 | .rpc_argp = &args, |
| 7403 | .rpc_resp = &res, |
| 7404 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7405 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7406 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7407 | |
| 7408 | if (use_integrity) { |
| 7409 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7410 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7411 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7412 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7413 | |
| 7414 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7415 | |
| 7416 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7417 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7418 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7419 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7420 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7421 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7422 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7423 | if (cred) |
| 7424 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7425 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7426 | return status; |
| 7427 | } |
| 7428 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7429 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7430 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7431 | { |
| 7432 | struct nfs4_exception exception = { }; |
| 7433 | int err; |
| 7434 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7435 | err = -NFS4ERR_WRONGSEC; |
| 7436 | |
| 7437 | /* try to use integrity protection with machine cred */ |
| 7438 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7439 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7440 | |
| 7441 | /* |
| 7442 | * if unable to use integrity protection, or SECINFO with |
| 7443 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7444 | * disallowed by spec, but exists in deployed servers) use |
| 7445 | * the current filesystem's rpc_client and the user cred. |
| 7446 | */ |
| 7447 | if (err == -NFS4ERR_WRONGSEC) |
| 7448 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7449 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7450 | trace_nfs4_secinfo(dir, name, err); |
| 7451 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7452 | &exception); |
| 7453 | } while (exception.retry); |
| 7454 | return err; |
| 7455 | } |
| 7456 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7457 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7458 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7459 | * Check the exchange flags returned by the server for invalid flags, having |
| 7460 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7461 | * DS flags set. |
| 7462 | */ |
| 7463 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7464 | { |
| 7465 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7466 | goto out_inval; |
| 7467 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7468 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7469 | goto out_inval; |
| 7470 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7471 | goto out_inval; |
| 7472 | return NFS_OK; |
| 7473 | out_inval: |
| 7474 | return -NFS4ERR_INVAL; |
| 7475 | } |
| 7476 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7477 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7478 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7479 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7480 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7481 | if (a->server_scope_sz != b->server_scope_sz) |
| 7482 | return false; |
| 7483 | 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] | 7484 | } |
| 7485 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7486 | static void |
| 7487 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7488 | { |
| 7489 | } |
| 7490 | |
| 7491 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7492 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7493 | }; |
| 7494 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7495 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7496 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7497 | * |
| 7498 | * The 4.1 client currently uses the same TCP connection for the |
| 7499 | * fore and backchannel. |
| 7500 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7501 | static |
| 7502 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7503 | struct rpc_xprt *xprt, |
| 7504 | struct nfs_client *clp, |
| 7505 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7506 | { |
| 7507 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7508 | struct nfs41_bind_conn_to_session_args args = { |
| 7509 | .client = clp, |
| 7510 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7511 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7512 | struct nfs41_bind_conn_to_session_res res; |
| 7513 | struct rpc_message msg = { |
| 7514 | .rpc_proc = |
| 7515 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7516 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7517 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7518 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7519 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7520 | struct rpc_task_setup task_setup_data = { |
| 7521 | .rpc_client = clnt, |
| 7522 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7523 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7524 | .rpc_message = &msg, |
| 7525 | .flags = RPC_TASK_TIMEOUT, |
| 7526 | }; |
| 7527 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7528 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7529 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7530 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7531 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7532 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7533 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7534 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7535 | args.dir = NFS4_CDFC4_FORE; |
| 7536 | |
| 7537 | task = rpc_run_task(&task_setup_data); |
| 7538 | if (!IS_ERR(task)) { |
| 7539 | status = task->tk_status; |
| 7540 | rpc_put_task(task); |
| 7541 | } else |
| 7542 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7543 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7544 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7545 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7546 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7547 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7548 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7549 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7550 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7551 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7552 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7553 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7554 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7555 | 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] | 7556 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7557 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7558 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7559 | } |
| 7560 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7561 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7562 | return status; |
| 7563 | } |
| 7564 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7565 | struct rpc_bind_conn_calldata { |
| 7566 | struct nfs_client *clp; |
| 7567 | struct rpc_cred *cred; |
| 7568 | }; |
| 7569 | |
| 7570 | static int |
| 7571 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7572 | struct rpc_xprt *xprt, |
| 7573 | void *calldata) |
| 7574 | { |
| 7575 | struct rpc_bind_conn_calldata *p = calldata; |
| 7576 | |
| 7577 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7578 | } |
| 7579 | |
| 7580 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7581 | { |
| 7582 | struct rpc_bind_conn_calldata data = { |
| 7583 | .clp = clp, |
| 7584 | .cred = cred, |
| 7585 | }; |
| 7586 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7587 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7588 | } |
| 7589 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7590 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7591 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7592 | * 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] | 7593 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7594 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7595 | .how = SP4_MACH_CRED, |
| 7596 | .enforce.u.words = { |
| 7597 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7598 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7599 | 1 << (OP_CREATE_SESSION - 32) | |
| 7600 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7601 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7602 | }, |
| 7603 | .allow.u.words = { |
| 7604 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7605 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7606 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7607 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7608 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7609 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7610 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7611 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7612 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7613 | 1 << (OP_FREE_STATEID - 32) | |
| 7614 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7615 | } |
| 7616 | }; |
| 7617 | |
| 7618 | /* |
| 7619 | * Select the state protection mode for client `clp' given the server results |
| 7620 | * from exchange_id in `sp'. |
| 7621 | * |
| 7622 | * Returns 0 on success, negative errno otherwise. |
| 7623 | */ |
| 7624 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7625 | struct nfs41_state_protection *sp) |
| 7626 | { |
| 7627 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7628 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7629 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7630 | 1 << (OP_CREATE_SESSION - 32) | |
| 7631 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7632 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7633 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7634 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7635 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7636 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7637 | |
| 7638 | if (sp->how == SP4_MACH_CRED) { |
| 7639 | /* Print state protect result */ |
| 7640 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7641 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7642 | if (test_bit(i, sp->enforce.u.longs)) |
| 7643 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7644 | if (test_bit(i, sp->allow.u.longs)) |
| 7645 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7646 | } |
| 7647 | |
| 7648 | /* make sure nothing is on enforce list that isn't supported */ |
| 7649 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7650 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7651 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7652 | ret = -EINVAL; |
| 7653 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7654 | } |
| 7655 | } |
| 7656 | |
| 7657 | /* |
| 7658 | * Minimal mode - state operations are allowed to use machine |
| 7659 | * credential. Note this already happens by default, so the |
| 7660 | * client doesn't have to do anything more than the negotiation. |
| 7661 | * |
| 7662 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7663 | * we're already using the machine cred for exchange_id |
| 7664 | * and will never use a different cred. |
| 7665 | */ |
| 7666 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7667 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7668 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7669 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7670 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7671 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7672 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7673 | } else { |
| 7674 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7675 | ret = -EINVAL; |
| 7676 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7677 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7678 | |
| 7679 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7680 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7681 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7682 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7683 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7684 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7685 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7686 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7687 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7688 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7689 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7690 | } |
| 7691 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7692 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7693 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7694 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7695 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7696 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7697 | |
| 7698 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7699 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7700 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7701 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7702 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7703 | |
| 7704 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7705 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7706 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7710 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7711 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7712 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7713 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7714 | out: |
| 7715 | clp->cl_sp4_flags = flags; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7716 | return 0; |
| 7717 | } |
| 7718 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7719 | struct nfs41_exchange_id_data { |
| 7720 | struct nfs41_exchange_id_res res; |
| 7721 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7722 | }; |
| 7723 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7724 | static void nfs4_exchange_id_release(void *data) |
| 7725 | { |
| 7726 | struct nfs41_exchange_id_data *cdata = |
| 7727 | (struct nfs41_exchange_id_data *)data; |
| 7728 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7729 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7730 | kfree(cdata->res.impl_id); |
| 7731 | kfree(cdata->res.server_scope); |
| 7732 | kfree(cdata->res.server_owner); |
| 7733 | kfree(cdata); |
| 7734 | } |
| 7735 | |
| 7736 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7737 | .rpc_release = nfs4_exchange_id_release, |
| 7738 | }; |
| 7739 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7740 | /* |
| 7741 | * _nfs4_proc_exchange_id() |
| 7742 | * |
| 7743 | * Wrapper for EXCHANGE_ID operation. |
| 7744 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7745 | static struct rpc_task * |
| 7746 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7747 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7748 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7749 | struct rpc_message msg = { |
| 7750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7751 | .rpc_cred = cred, |
| 7752 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7753 | struct rpc_task_setup task_setup_data = { |
| 7754 | .rpc_client = clp->cl_rpcclient, |
| 7755 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7756 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7757 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7758 | }; |
| 7759 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7760 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7761 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7762 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7763 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7764 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7765 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7766 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7767 | if (!calldata) |
| 7768 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7769 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7770 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7771 | |
| 7772 | status = nfs4_init_uniform_client_string(clp); |
| 7773 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7774 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7775 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7776 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7777 | GFP_NOFS); |
| 7778 | status = -ENOMEM; |
| 7779 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7780 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7781 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7782 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7783 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7784 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7785 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7786 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7787 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7788 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7789 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7790 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7791 | switch (sp4_how) { |
| 7792 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7793 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7794 | break; |
| 7795 | |
| 7796 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7797 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7798 | break; |
| 7799 | |
| 7800 | default: |
| 7801 | /* unsupported! */ |
| 7802 | WARN_ON_ONCE(1); |
| 7803 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7804 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7805 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7806 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7807 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7808 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7809 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7810 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7811 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7812 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7813 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7814 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7815 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7816 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7817 | #endif |
| 7818 | msg.rpc_argp = &calldata->args; |
| 7819 | msg.rpc_resp = &calldata->res; |
| 7820 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7821 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7822 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7823 | |
| 7824 | out_impl_id: |
| 7825 | kfree(calldata->res.impl_id); |
| 7826 | out_server_scope: |
| 7827 | kfree(calldata->res.server_scope); |
| 7828 | out_server_owner: |
| 7829 | kfree(calldata->res.server_owner); |
| 7830 | out_calldata: |
| 7831 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7832 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7833 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7834 | return ERR_PTR(status); |
| 7835 | } |
| 7836 | |
| 7837 | /* |
| 7838 | * _nfs4_proc_exchange_id() |
| 7839 | * |
| 7840 | * Wrapper for EXCHANGE_ID operation. |
| 7841 | */ |
| 7842 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7843 | u32 sp4_how) |
| 7844 | { |
| 7845 | struct rpc_task *task; |
| 7846 | struct nfs41_exchange_id_args *argp; |
| 7847 | struct nfs41_exchange_id_res *resp; |
| 7848 | int status; |
| 7849 | |
| 7850 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7851 | if (IS_ERR(task)) |
| 7852 | return PTR_ERR(task); |
| 7853 | |
| 7854 | argp = task->tk_msg.rpc_argp; |
| 7855 | resp = task->tk_msg.rpc_resp; |
| 7856 | status = task->tk_status; |
| 7857 | if (status != 0) |
| 7858 | goto out; |
| 7859 | |
| 7860 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7861 | if (status != 0) |
| 7862 | goto out; |
| 7863 | |
| 7864 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7865 | if (status != 0) |
| 7866 | goto out; |
| 7867 | |
| 7868 | clp->cl_clientid = resp->clientid; |
| 7869 | clp->cl_exchange_flags = resp->flags; |
| 7870 | clp->cl_seqid = resp->seqid; |
| 7871 | /* Client ID is not confirmed */ |
| 7872 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7873 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7874 | &clp->cl_session->session_state); |
| 7875 | |
| 7876 | if (clp->cl_serverscope != NULL && |
| 7877 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7878 | resp->server_scope)) { |
| 7879 | dprintk("%s: server_scope mismatch detected\n", |
| 7880 | __func__); |
| 7881 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7882 | } |
| 7883 | |
| 7884 | swap(clp->cl_serverowner, resp->server_owner); |
| 7885 | swap(clp->cl_serverscope, resp->server_scope); |
| 7886 | swap(clp->cl_implid, resp->impl_id); |
| 7887 | |
| 7888 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7889 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 7890 | sizeof(clp->cl_confirm.data)); |
| 7891 | out: |
| 7892 | trace_nfs4_exchange_id(clp, status); |
| 7893 | rpc_put_task(task); |
| 7894 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7895 | } |
| 7896 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7897 | /* |
| 7898 | * nfs4_proc_exchange_id() |
| 7899 | * |
| 7900 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7901 | * |
| 7902 | * Since the clientid has expired, all compounds using sessions |
| 7903 | * associated with the stale clientid will be returning |
| 7904 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7905 | * be in some phase of session reset. |
| 7906 | * |
| 7907 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7908 | */ |
| 7909 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7910 | { |
| 7911 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7912 | int status; |
| 7913 | |
| 7914 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7915 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7916 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7917 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7918 | if (!status) |
| 7919 | return 0; |
| 7920 | } |
| 7921 | |
| 7922 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7923 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7924 | } |
| 7925 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7926 | /** |
| 7927 | * nfs4_test_session_trunk |
| 7928 | * |
| 7929 | * This is an add_xprt_test() test function called from |
| 7930 | * rpc_clnt_setup_test_and_add_xprt. |
| 7931 | * |
| 7932 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7933 | * and is dereferrenced in nfs4_exchange_id_release |
| 7934 | * |
| 7935 | * Upon success, add the new transport to the rpc_clnt |
| 7936 | * |
| 7937 | * @clnt: struct rpc_clnt to get new transport |
| 7938 | * @xprt: the rpc_xprt to test |
| 7939 | * @data: call data for _nfs4_proc_exchange_id. |
| 7940 | */ |
| 7941 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7942 | void *data) |
| 7943 | { |
| 7944 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7945 | struct rpc_task *task; |
| 7946 | int status; |
| 7947 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7948 | u32 sp4_how; |
| 7949 | |
| 7950 | dprintk("--> %s try %s\n", __func__, |
| 7951 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7952 | |
| 7953 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7954 | |
| 7955 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7956 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7957 | if (IS_ERR(task)) |
| 7958 | return PTR_ERR(task); |
| 7959 | |
| 7960 | status = task->tk_status; |
| 7961 | if (status == 0) |
| 7962 | status = nfs4_detect_session_trunking(adata->clp, |
| 7963 | task->tk_msg.rpc_resp, xprt); |
| 7964 | |
| 7965 | rpc_put_task(task); |
| 7966 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7967 | } |
| 7968 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7969 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7970 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7971 | struct rpc_cred *cred) |
| 7972 | { |
| 7973 | struct rpc_message msg = { |
| 7974 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7975 | .rpc_argp = clp, |
| 7976 | .rpc_cred = cred, |
| 7977 | }; |
| 7978 | int status; |
| 7979 | |
| 7980 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7981 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7982 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7983 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7984 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7985 | return status; |
| 7986 | } |
| 7987 | |
| 7988 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7989 | struct rpc_cred *cred) |
| 7990 | { |
| 7991 | unsigned int loop; |
| 7992 | int ret; |
| 7993 | |
| 7994 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7995 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7996 | switch (ret) { |
| 7997 | case -NFS4ERR_DELAY: |
| 7998 | case -NFS4ERR_CLIENTID_BUSY: |
| 7999 | ssleep(1); |
| 8000 | break; |
| 8001 | default: |
| 8002 | return ret; |
| 8003 | } |
| 8004 | } |
| 8005 | return 0; |
| 8006 | } |
| 8007 | |
| 8008 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 8009 | { |
| 8010 | struct rpc_cred *cred; |
| 8011 | int ret = 0; |
| 8012 | |
| 8013 | if (clp->cl_mvops->minor_version < 1) |
| 8014 | goto out; |
| 8015 | if (clp->cl_exchange_flags == 0) |
| 8016 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8017 | if (clp->cl_preserve_clid) |
| 8018 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 8019 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 8020 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 8021 | if (cred) |
| 8022 | put_rpccred(cred); |
| 8023 | switch (ret) { |
| 8024 | case 0: |
| 8025 | case -NFS4ERR_STALE_CLIENTID: |
| 8026 | clp->cl_exchange_flags = 0; |
| 8027 | } |
| 8028 | out: |
| 8029 | return ret; |
| 8030 | } |
| 8031 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8032 | struct nfs4_get_lease_time_data { |
| 8033 | struct nfs4_get_lease_time_args *args; |
| 8034 | struct nfs4_get_lease_time_res *res; |
| 8035 | struct nfs_client *clp; |
| 8036 | }; |
| 8037 | |
| 8038 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 8039 | void *calldata) |
| 8040 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8041 | struct nfs4_get_lease_time_data *data = |
| 8042 | (struct nfs4_get_lease_time_data *)calldata; |
| 8043 | |
| 8044 | dprintk("--> %s\n", __func__); |
| 8045 | /* just setup sequence, do not trigger session recovery |
| 8046 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8047 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8048 | &data->args->la_seq_args, |
| 8049 | &data->res->lr_seq_res, |
| 8050 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8051 | dprintk("<-- %s\n", __func__); |
| 8052 | } |
| 8053 | |
| 8054 | /* |
| 8055 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 8056 | * from sequence operation or clientid errors. |
| 8057 | */ |
| 8058 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 8059 | { |
| 8060 | struct nfs4_get_lease_time_data *data = |
| 8061 | (struct nfs4_get_lease_time_data *)calldata; |
| 8062 | |
| 8063 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8064 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 8065 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8066 | switch (task->tk_status) { |
| 8067 | case -NFS4ERR_DELAY: |
| 8068 | case -NFS4ERR_GRACE: |
| 8069 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 8070 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 8071 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8072 | /* fall through */ |
| 8073 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8074 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8075 | return; |
| 8076 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8077 | dprintk("<-- %s\n", __func__); |
| 8078 | } |
| 8079 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8080 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8081 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 8082 | .rpc_call_done = nfs4_get_lease_time_done, |
| 8083 | }; |
| 8084 | |
| 8085 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 8086 | { |
| 8087 | struct rpc_task *task; |
| 8088 | struct nfs4_get_lease_time_args args; |
| 8089 | struct nfs4_get_lease_time_res res = { |
| 8090 | .lr_fsinfo = fsinfo, |
| 8091 | }; |
| 8092 | struct nfs4_get_lease_time_data data = { |
| 8093 | .args = &args, |
| 8094 | .res = &res, |
| 8095 | .clp = clp, |
| 8096 | }; |
| 8097 | struct rpc_message msg = { |
| 8098 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 8099 | .rpc_argp = &args, |
| 8100 | .rpc_resp = &res, |
| 8101 | }; |
| 8102 | struct rpc_task_setup task_setup = { |
| 8103 | .rpc_client = clp->cl_rpcclient, |
| 8104 | .rpc_message = &msg, |
| 8105 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8106 | .callback_data = &data, |
| 8107 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8108 | }; |
| 8109 | int status; |
| 8110 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8111 | 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] | 8112 | task = rpc_run_task(&task_setup); |
| 8113 | |
| 8114 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8115 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8116 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 8117 | status = task->tk_status; |
| 8118 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 8119 | return status; |
| 8120 | } |
| 8121 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8122 | /* |
| 8123 | * Initialize the values to be used by the client in CREATE_SESSION |
| 8124 | * If nfs4_init_session set the fore channel request and response sizes, |
| 8125 | * use them. |
| 8126 | * |
| 8127 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 8128 | * always set csa_cachethis to FALSE because the current implementation |
| 8129 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 8130 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8131 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 8132 | struct rpc_clnt *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 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8135 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8136 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8137 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 8138 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8139 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8140 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8141 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8142 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8143 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8144 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8145 | |
| 8146 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8147 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8148 | __func__, |
| 8149 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8150 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8151 | |
| 8152 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8153 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8154 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8155 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8156 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8157 | 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] | 8158 | |
| 8159 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8160 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8161 | __func__, |
| 8162 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8163 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8164 | args->bc_attrs.max_reqs); |
| 8165 | } |
| 8166 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8167 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8168 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8169 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8170 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8171 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8172 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8173 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8174 | return -EINVAL; |
| 8175 | /* |
| 8176 | * Our requested max_ops is the minimum we need; we're not |
| 8177 | * prepared to break up compounds into smaller pieces than that. |
| 8178 | * So, no point even trying to continue if the server won't |
| 8179 | * cooperate: |
| 8180 | */ |
| 8181 | if (rcvd->max_ops < sent->max_ops) |
| 8182 | return -EINVAL; |
| 8183 | if (rcvd->max_reqs == 0) |
| 8184 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8185 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8186 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8187 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8188 | } |
| 8189 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8190 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8191 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8192 | { |
| 8193 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8194 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8195 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8196 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8197 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8198 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8199 | return -EINVAL; |
| 8200 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8201 | return -EINVAL; |
| 8202 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8203 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8204 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8205 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8206 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8207 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8208 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8209 | return 0; |
| 8210 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8211 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8212 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8213 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8214 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8215 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8216 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8217 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8218 | if (ret) |
| 8219 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8220 | return nfs4_verify_back_channel_attrs(args, res); |
| 8221 | } |
| 8222 | |
| 8223 | static void nfs4_update_session(struct nfs4_session *session, |
| 8224 | struct nfs41_create_session_res *res) |
| 8225 | { |
| 8226 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8227 | /* Mark client id and session as being confirmed */ |
| 8228 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8229 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8230 | session->flags = res->flags; |
| 8231 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8232 | if (res->flags & SESSION4_BACK_CHAN) |
| 8233 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8234 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8235 | } |
| 8236 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8237 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8238 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8239 | { |
| 8240 | struct nfs4_session *session = clp->cl_session; |
| 8241 | struct nfs41_create_session_args args = { |
| 8242 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8243 | .clientid = clp->cl_clientid, |
| 8244 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8245 | .cb_program = NFS4_CALLBACK, |
| 8246 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8247 | struct nfs41_create_session_res res; |
| 8248 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8249 | struct rpc_message msg = { |
| 8250 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8251 | .rpc_argp = &args, |
| 8252 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8253 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8254 | }; |
| 8255 | int status; |
| 8256 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8257 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8258 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8259 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8260 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8261 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8262 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8263 | switch (status) { |
| 8264 | case -NFS4ERR_STALE_CLIENTID: |
| 8265 | case -NFS4ERR_DELAY: |
| 8266 | case -ETIMEDOUT: |
| 8267 | case -EACCES: |
| 8268 | case -EAGAIN: |
| 8269 | goto out; |
| 8270 | }; |
| 8271 | |
| 8272 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8273 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8274 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8275 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8276 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8277 | if (status) |
| 8278 | goto out; |
| 8279 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8280 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8281 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8282 | return status; |
| 8283 | } |
| 8284 | |
| 8285 | /* |
| 8286 | * Issues a CREATE_SESSION operation to the server. |
| 8287 | * It is the responsibility of the caller to verify the session is |
| 8288 | * expired before calling this routine. |
| 8289 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8290 | 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] | 8291 | { |
| 8292 | int status; |
| 8293 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8294 | struct nfs4_session *session = clp->cl_session; |
| 8295 | |
| 8296 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8297 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8298 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8299 | if (status) |
| 8300 | goto out; |
| 8301 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8302 | /* Init or reset the session slot tables */ |
| 8303 | status = nfs4_setup_session_slot_tables(session); |
| 8304 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8305 | if (status) |
| 8306 | goto out; |
| 8307 | |
| 8308 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8309 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8310 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8311 | out: |
| 8312 | dprintk("<-- %s\n", __func__); |
| 8313 | return status; |
| 8314 | } |
| 8315 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8316 | /* |
| 8317 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8318 | * The caller must serialize access to this routine. |
| 8319 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8320 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8321 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8322 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8323 | struct rpc_message msg = { |
| 8324 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8325 | .rpc_argp = session, |
| 8326 | .rpc_cred = cred, |
| 8327 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8328 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8329 | |
| 8330 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8331 | |
| 8332 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8333 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8334 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8335 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8336 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8337 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8338 | |
| 8339 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8340 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8341 | "Session has been destroyed regardless...\n", status); |
| 8342 | |
| 8343 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8344 | return status; |
| 8345 | } |
| 8346 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8347 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8348 | * Renew the cl_session lease. |
| 8349 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8350 | struct nfs4_sequence_data { |
| 8351 | struct nfs_client *clp; |
| 8352 | struct nfs4_sequence_args args; |
| 8353 | struct nfs4_sequence_res res; |
| 8354 | }; |
| 8355 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8356 | static void nfs41_sequence_release(void *data) |
| 8357 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8358 | struct nfs4_sequence_data *calldata = data; |
| 8359 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8360 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8361 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8362 | nfs4_schedule_state_renewal(clp); |
| 8363 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8364 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8365 | } |
| 8366 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8367 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8368 | { |
| 8369 | switch(task->tk_status) { |
| 8370 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8371 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8372 | return -EAGAIN; |
| 8373 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8374 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8375 | } |
| 8376 | return 0; |
| 8377 | } |
| 8378 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8379 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8380 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8381 | struct nfs4_sequence_data *calldata = data; |
| 8382 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8383 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8384 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8385 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8386 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8387 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8388 | if (task->tk_status < 0) { |
| 8389 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8390 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8391 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8392 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8393 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8394 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8395 | return; |
| 8396 | } |
| 8397 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8398 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8399 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8400 | dprintk("<-- %s\n", __func__); |
| 8401 | } |
| 8402 | |
| 8403 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8404 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8405 | struct nfs4_sequence_data *calldata = data; |
| 8406 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8407 | struct nfs4_sequence_args *args; |
| 8408 | struct nfs4_sequence_res *res; |
| 8409 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8410 | args = task->tk_msg.rpc_argp; |
| 8411 | res = task->tk_msg.rpc_resp; |
| 8412 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8413 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8417 | .rpc_call_done = nfs41_sequence_call_done, |
| 8418 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8419 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8420 | }; |
| 8421 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8422 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8423 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8424 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8425 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8426 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8427 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8428 | struct rpc_message msg = { |
| 8429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8430 | .rpc_cred = cred, |
| 8431 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8432 | struct rpc_task_setup task_setup_data = { |
| 8433 | .rpc_client = clp->cl_rpcclient, |
| 8434 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8435 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8436 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8437 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8438 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8439 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8440 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8441 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8442 | goto out_err; |
| 8443 | |
| 8444 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8445 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8446 | if (calldata == NULL) |
| 8447 | goto out_put_clp; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8448 | nfs4_init_sequence(&calldata->args, &calldata->res, 0, is_privileged); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8449 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8450 | msg.rpc_argp = &calldata->args; |
| 8451 | msg.rpc_resp = &calldata->res; |
| 8452 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8453 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8454 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8455 | ret = rpc_run_task(&task_setup_data); |
| 8456 | if (IS_ERR(ret)) |
| 8457 | goto out_err; |
| 8458 | return ret; |
| 8459 | out_put_clp: |
| 8460 | nfs_put_client(clp); |
| 8461 | out_err: |
| 8462 | nfs41_release_slot(slot); |
| 8463 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8464 | } |
| 8465 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8466 | 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] | 8467 | { |
| 8468 | struct rpc_task *task; |
| 8469 | int ret = 0; |
| 8470 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8471 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8472 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8473 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8474 | if (IS_ERR(task)) |
| 8475 | ret = PTR_ERR(task); |
| 8476 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8477 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8478 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8479 | return ret; |
| 8480 | } |
| 8481 | |
| 8482 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8483 | { |
| 8484 | struct rpc_task *task; |
| 8485 | int ret; |
| 8486 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8487 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8488 | if (IS_ERR(task)) { |
| 8489 | ret = PTR_ERR(task); |
| 8490 | goto out; |
| 8491 | } |
| 8492 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8493 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8494 | ret = task->tk_status; |
| 8495 | rpc_put_task(task); |
| 8496 | out: |
| 8497 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8498 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8499 | } |
| 8500 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8501 | struct nfs4_reclaim_complete_data { |
| 8502 | struct nfs_client *clp; |
| 8503 | struct nfs41_reclaim_complete_args arg; |
| 8504 | struct nfs41_reclaim_complete_res res; |
| 8505 | }; |
| 8506 | |
| 8507 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8508 | { |
| 8509 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8510 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8511 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8512 | &calldata->arg.seq_args, |
| 8513 | &calldata->res.seq_res, |
| 8514 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8515 | } |
| 8516 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8517 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8518 | { |
| 8519 | switch(task->tk_status) { |
| 8520 | case 0: |
Jeff Layton | 5717459 | 2018-03-18 08:37:03 -0400 | [diff] [blame] | 8521 | wake_up_all(&clp->cl_lock_waitq); |
| 8522 | /* Fallthrough */ |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8523 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8524 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8525 | break; |
| 8526 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8527 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8528 | /* fall through */ |
| 8529 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8530 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8531 | case -NFS4ERR_BADSESSION: |
| 8532 | case -NFS4ERR_DEADSESSION: |
| 8533 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8534 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8535 | task->tk_status); |
| 8536 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8537 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8538 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8539 | } |
| 8540 | return 0; |
| 8541 | } |
| 8542 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8543 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8544 | { |
| 8545 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8546 | struct nfs_client *clp = calldata->clp; |
| 8547 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8548 | |
| 8549 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8550 | if (!nfs41_sequence_done(task, res)) |
| 8551 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8552 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8553 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8554 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8555 | rpc_restart_call_prepare(task); |
| 8556 | return; |
| 8557 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8558 | dprintk("<-- %s\n", __func__); |
| 8559 | } |
| 8560 | |
| 8561 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8562 | { |
| 8563 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8564 | |
| 8565 | kfree(calldata); |
| 8566 | } |
| 8567 | |
| 8568 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8569 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8570 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8571 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8572 | }; |
| 8573 | |
| 8574 | /* |
| 8575 | * Issue a global reclaim complete. |
| 8576 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8577 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8578 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8579 | { |
| 8580 | struct nfs4_reclaim_complete_data *calldata; |
| 8581 | struct rpc_task *task; |
| 8582 | struct rpc_message msg = { |
| 8583 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8584 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8585 | }; |
| 8586 | struct rpc_task_setup task_setup_data = { |
| 8587 | .rpc_client = clp->cl_rpcclient, |
| 8588 | .rpc_message = &msg, |
| 8589 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8590 | .flags = RPC_TASK_ASYNC, |
| 8591 | }; |
| 8592 | int status = -ENOMEM; |
| 8593 | |
| 8594 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8595 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8596 | if (calldata == NULL) |
| 8597 | goto out; |
| 8598 | calldata->clp = clp; |
| 8599 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8600 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8601 | 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] | 8602 | msg.rpc_argp = &calldata->arg; |
| 8603 | msg.rpc_resp = &calldata->res; |
| 8604 | task_setup_data.callback_data = calldata; |
| 8605 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8606 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8607 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8608 | goto out; |
| 8609 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8610 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8611 | if (status == 0) |
| 8612 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8613 | rpc_put_task(task); |
| 8614 | out: |
| 8615 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8616 | return status; |
| 8617 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8618 | |
| 8619 | static void |
| 8620 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8621 | { |
| 8622 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8623 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8624 | |
| 8625 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8626 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8627 | &lgp->res.seq_res, task); |
| 8628 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8629 | } |
| 8630 | |
| 8631 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8632 | { |
| 8633 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8634 | |
| 8635 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8636 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8637 | dprintk("<-- %s\n", __func__); |
| 8638 | } |
| 8639 | |
| 8640 | static int |
| 8641 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8642 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8643 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8644 | struct inode *inode = lgp->args.inode; |
| 8645 | struct nfs_server *server = NFS_SERVER(inode); |
| 8646 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8647 | int nfs4err = task->tk_status; |
| 8648 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8649 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8650 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8651 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8652 | |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame^] | 8653 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
| 8654 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8655 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8656 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8657 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8658 | |
| 8659 | /* |
| 8660 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8661 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8662 | * retry go inband. |
| 8663 | */ |
| 8664 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8665 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8666 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8667 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8668 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8669 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8670 | */ |
| 8671 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8672 | status = -EOVERFLOW; |
| 8673 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8674 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8675 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8676 | * (or clients) writing to the same RAID stripe except when |
| 8677 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8678 | * |
| 8679 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8680 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8681 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8682 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8683 | if (lgp->args.minlength == 0) { |
| 8684 | status = -EOVERFLOW; |
| 8685 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8686 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8687 | status = -EBUSY; |
| 8688 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8689 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8690 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8691 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8692 | case -NFS4ERR_DELEG_REVOKED: |
| 8693 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8694 | case -NFS4ERR_EXPIRED: |
| 8695 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8696 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8697 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8698 | lo = NFS_I(inode)->layout; |
| 8699 | /* If the open stateid was bad, then recover it. */ |
| 8700 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8701 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8702 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8703 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8704 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8705 | break; |
| 8706 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8707 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8708 | /* |
| 8709 | * Mark the bad layout state as invalid, then retry |
| 8710 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8711 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8712 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8713 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8714 | pnfs_free_lseg_list(&head); |
| 8715 | status = -EAGAIN; |
| 8716 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8717 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8718 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8719 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8720 | if (!status) { |
| 8721 | if (exception->retry) |
| 8722 | status = -EAGAIN; |
| 8723 | else |
| 8724 | status = err; |
| 8725 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8726 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8727 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8728 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8729 | } |
| 8730 | |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8731 | size_t max_response_pages(struct nfs_server *server) |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8732 | { |
| 8733 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8734 | return nfs_page_array_len(0, max_resp_sz); |
| 8735 | } |
| 8736 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8737 | static void nfs4_layoutget_release(void *calldata) |
| 8738 | { |
| 8739 | struct nfs4_layoutget *lgp = calldata; |
| 8740 | |
| 8741 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8742 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | 29a8bfe | 2018-05-30 17:16:20 -0400 | [diff] [blame] | 8743 | pnfs_layoutget_free(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8744 | dprintk("<-- %s\n", __func__); |
| 8745 | } |
| 8746 | |
| 8747 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8748 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8749 | .rpc_call_done = nfs4_layoutget_done, |
| 8750 | .rpc_release = nfs4_layoutget_release, |
| 8751 | }; |
| 8752 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8753 | struct pnfs_layout_segment * |
Fred Isaman | dacb452 | 2016-09-19 17:47:09 -0400 | [diff] [blame] | 8754 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8755 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8756 | struct inode *inode = lgp->args.inode; |
| 8757 | struct nfs_server *server = NFS_SERVER(inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8758 | struct rpc_task *task; |
| 8759 | struct rpc_message msg = { |
| 8760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8761 | .rpc_argp = &lgp->args, |
| 8762 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8763 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8764 | }; |
| 8765 | struct rpc_task_setup task_setup_data = { |
| 8766 | .rpc_client = server->client, |
| 8767 | .rpc_message = &msg, |
| 8768 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8769 | .callback_data = lgp, |
| 8770 | .flags = RPC_TASK_ASYNC, |
| 8771 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8772 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8773 | struct nfs4_exception exception = { |
| 8774 | .inode = inode, |
| 8775 | .timeout = *timeout, |
| 8776 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8777 | int status = 0; |
| 8778 | |
| 8779 | dprintk("--> %s\n", __func__); |
| 8780 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8781 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8782 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8783 | |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8784 | 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] | 8785 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8786 | task = rpc_run_task(&task_setup_data); |
| 8787 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8788 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8789 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame^] | 8790 | if (status != 0) |
| 8791 | goto out; |
| 8792 | |
| 8793 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8794 | if (task->tk_status < 0 || lgp->res.layoutp->len == 0) { |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8795 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8796 | *timeout = exception.timeout; |
Trond Myklebust | 2dbf8df | 2018-06-15 15:58:45 -0400 | [diff] [blame^] | 8797 | } else |
| 8798 | lseg = pnfs_layout_process(lgp); |
| 8799 | out: |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8800 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8801 | &lgp->args.range, |
| 8802 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8803 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8804 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8805 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8806 | rpc_put_task(task); |
| 8807 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8808 | if (status) |
| 8809 | return ERR_PTR(status); |
| 8810 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8811 | } |
| 8812 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8813 | static void |
| 8814 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8815 | { |
| 8816 | struct nfs4_layoutreturn *lrp = calldata; |
| 8817 | |
| 8818 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8819 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8820 | &lrp->args.seq_args, |
| 8821 | &lrp->res.seq_res, |
| 8822 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8823 | } |
| 8824 | |
| 8825 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8826 | { |
| 8827 | struct nfs4_layoutreturn *lrp = calldata; |
| 8828 | struct nfs_server *server; |
| 8829 | |
| 8830 | dprintk("--> %s\n", __func__); |
| 8831 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8832 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8833 | return; |
| 8834 | |
| 8835 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8836 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8837 | case -NFS4ERR_OLD_STATEID: |
| 8838 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, |
| 8839 | lrp->args.inode)) |
| 8840 | goto out_restart; |
| 8841 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8842 | default: |
| 8843 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8844 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8845 | case 0: |
| 8846 | break; |
| 8847 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8848 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8849 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8850 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8851 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8852 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8853 | return; |
| 8854 | out_restart: |
| 8855 | task->tk_status = 0; |
| 8856 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8857 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8858 | } |
| 8859 | |
| 8860 | static void nfs4_layoutreturn_release(void *calldata) |
| 8861 | { |
| 8862 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8863 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8864 | |
| 8865 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8866 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8867 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8868 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8869 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8870 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8871 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8872 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8873 | kfree(calldata); |
| 8874 | dprintk("<-- %s\n", __func__); |
| 8875 | } |
| 8876 | |
| 8877 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8878 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8879 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8880 | .rpc_release = nfs4_layoutreturn_release, |
| 8881 | }; |
| 8882 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8883 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8884 | { |
| 8885 | struct rpc_task *task; |
| 8886 | struct rpc_message msg = { |
| 8887 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8888 | .rpc_argp = &lrp->args, |
| 8889 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8890 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8891 | }; |
| 8892 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8893 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8894 | .rpc_message = &msg, |
| 8895 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8896 | .callback_data = lrp, |
| 8897 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8898 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8899 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8900 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8901 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8902 | &task_setup_data.rpc_client, &msg); |
| 8903 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8904 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8905 | if (!sync) { |
| 8906 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8907 | if (!lrp->inode) { |
| 8908 | nfs4_layoutreturn_release(lrp); |
| 8909 | return -EAGAIN; |
| 8910 | } |
| 8911 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8912 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 8913 | 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] | 8914 | task = rpc_run_task(&task_setup_data); |
| 8915 | if (IS_ERR(task)) |
| 8916 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8917 | if (sync) |
| 8918 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8919 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8920 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8921 | rpc_put_task(task); |
| 8922 | return status; |
| 8923 | } |
| 8924 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8925 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8926 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8927 | struct pnfs_device *pdev, |
| 8928 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8929 | { |
| 8930 | struct nfs4_getdeviceinfo_args args = { |
| 8931 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8932 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8933 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8934 | }; |
| 8935 | struct nfs4_getdeviceinfo_res res = { |
| 8936 | .pdev = pdev, |
| 8937 | }; |
| 8938 | struct rpc_message msg = { |
| 8939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8940 | .rpc_argp = &args, |
| 8941 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8942 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8943 | }; |
| 8944 | int status; |
| 8945 | |
| 8946 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8947 | 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] | 8948 | if (res.notification & ~args.notify_types) |
| 8949 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8950 | if (res.notification != args.notify_types) |
| 8951 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8952 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8953 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8954 | |
| 8955 | return status; |
| 8956 | } |
| 8957 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8958 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8959 | struct pnfs_device *pdev, |
| 8960 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8961 | { |
| 8962 | struct nfs4_exception exception = { }; |
| 8963 | int err; |
| 8964 | |
| 8965 | do { |
| 8966 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8967 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8968 | &exception); |
| 8969 | } while (exception.retry); |
| 8970 | return err; |
| 8971 | } |
| 8972 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8973 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8974 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8975 | { |
| 8976 | struct nfs4_layoutcommit_data *data = calldata; |
| 8977 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8978 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8979 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8980 | &data->args.seq_args, |
| 8981 | &data->res.seq_res, |
| 8982 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | static void |
| 8986 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8987 | { |
| 8988 | struct nfs4_layoutcommit_data *data = calldata; |
| 8989 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8990 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8991 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8992 | return; |
| 8993 | |
| 8994 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8995 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8996 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8997 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8998 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8999 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9000 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9001 | break; |
| 9002 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9003 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 9004 | rpc_restart_call_prepare(task); |
| 9005 | return; |
| 9006 | } |
| 9007 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9008 | } |
| 9009 | |
| 9010 | static void nfs4_layoutcommit_release(void *calldata) |
| 9011 | { |
| 9012 | struct nfs4_layoutcommit_data *data = calldata; |
| 9013 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 9014 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 9015 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 9016 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9017 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9018 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9019 | kfree(data); |
| 9020 | } |
| 9021 | |
| 9022 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 9023 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 9024 | .rpc_call_done = nfs4_layoutcommit_done, |
| 9025 | .rpc_release = nfs4_layoutcommit_release, |
| 9026 | }; |
| 9027 | |
| 9028 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 9029 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9030 | { |
| 9031 | struct rpc_message msg = { |
| 9032 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 9033 | .rpc_argp = &data->args, |
| 9034 | .rpc_resp = &data->res, |
| 9035 | .rpc_cred = data->cred, |
| 9036 | }; |
| 9037 | struct rpc_task_setup task_setup_data = { |
| 9038 | .task = &data->task, |
| 9039 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 9040 | .rpc_message = &msg, |
| 9041 | .callback_ops = &nfs4_layoutcommit_ops, |
| 9042 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9043 | }; |
| 9044 | struct rpc_task *task; |
| 9045 | int status = 0; |
| 9046 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 9047 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 9048 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9049 | data->args.lastbytewritten, |
| 9050 | data->args.inode->i_ino); |
| 9051 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9052 | if (!sync) { |
| 9053 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 9054 | if (data->inode == NULL) { |
| 9055 | nfs4_layoutcommit_release(data); |
| 9056 | return -EAGAIN; |
| 9057 | } |
| 9058 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 9059 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9060 | 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] | 9061 | task = rpc_run_task(&task_setup_data); |
| 9062 | if (IS_ERR(task)) |
| 9063 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 9064 | if (sync) |
| 9065 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 9066 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 9067 | dprintk("%s: status %d\n", __func__, status); |
| 9068 | rpc_put_task(task); |
| 9069 | return status; |
| 9070 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9071 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 9072 | /** |
| 9073 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 9074 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 9075 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9076 | static int |
| 9077 | _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] | 9078 | struct nfs_fsinfo *info, |
| 9079 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9080 | { |
| 9081 | struct nfs41_secinfo_no_name_args args = { |
| 9082 | .style = SECINFO_STYLE_CURRENT_FH, |
| 9083 | }; |
| 9084 | struct nfs4_secinfo_res res = { |
| 9085 | .flavors = flavors, |
| 9086 | }; |
| 9087 | struct rpc_message msg = { |
| 9088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9089 | .rpc_argp = &args, |
| 9090 | .rpc_resp = &res, |
| 9091 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9092 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9093 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9094 | int status; |
| 9095 | |
| 9096 | if (use_integrity) { |
| 9097 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9098 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9099 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9100 | } |
| 9101 | |
| 9102 | dprintk("--> %s\n", __func__); |
| 9103 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9104 | &res.seq_res, 0); |
| 9105 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9106 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9107 | if (cred) |
| 9108 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9109 | |
| 9110 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9111 | } |
| 9112 | |
| 9113 | static int |
| 9114 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9115 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9116 | { |
| 9117 | struct nfs4_exception exception = { }; |
| 9118 | int err; |
| 9119 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9120 | /* first try using integrity protection */ |
| 9121 | err = -NFS4ERR_WRONGSEC; |
| 9122 | |
| 9123 | /* try to use integrity protection with machine cred */ |
| 9124 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9125 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9126 | flavors, true); |
| 9127 | |
| 9128 | /* |
| 9129 | * if unable to use integrity protection, or SECINFO with |
| 9130 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9131 | * disallowed by spec, but exists in deployed servers) use |
| 9132 | * the current filesystem's rpc_client and the user cred. |
| 9133 | */ |
| 9134 | if (err == -NFS4ERR_WRONGSEC) |
| 9135 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9136 | flavors, false); |
| 9137 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9138 | switch (err) { |
| 9139 | case 0: |
| 9140 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9141 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9142 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9143 | default: |
| 9144 | err = nfs4_handle_exception(server, err, &exception); |
| 9145 | } |
| 9146 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9147 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9148 | return err; |
| 9149 | } |
| 9150 | |
| 9151 | static int |
| 9152 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9153 | struct nfs_fsinfo *info) |
| 9154 | { |
| 9155 | int err; |
| 9156 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9157 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9158 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9159 | struct nfs4_secinfo4 *secinfo; |
| 9160 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9161 | |
| 9162 | page = alloc_page(GFP_KERNEL); |
| 9163 | if (!page) { |
| 9164 | err = -ENOMEM; |
| 9165 | goto out; |
| 9166 | } |
| 9167 | |
| 9168 | flavors = page_address(page); |
| 9169 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9170 | |
| 9171 | /* |
| 9172 | * Fall back on "guess and check" method if |
| 9173 | * the server doesn't support SECINFO_NO_NAME |
| 9174 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9175 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9176 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9177 | goto out_freepage; |
| 9178 | } |
| 9179 | if (err) |
| 9180 | goto out_freepage; |
| 9181 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9182 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9183 | secinfo = &flavors->flavors[i]; |
| 9184 | |
| 9185 | switch (secinfo->flavor) { |
| 9186 | case RPC_AUTH_NULL: |
| 9187 | case RPC_AUTH_UNIX: |
| 9188 | case RPC_AUTH_GSS: |
| 9189 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9190 | &secinfo->flavor_info); |
| 9191 | break; |
| 9192 | default: |
| 9193 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9194 | break; |
| 9195 | } |
| 9196 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9197 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9198 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9199 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9200 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9201 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9202 | info, flavor); |
| 9203 | if (!err) |
| 9204 | break; |
| 9205 | } |
| 9206 | } |
| 9207 | |
| 9208 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9209 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9210 | |
| 9211 | out_freepage: |
| 9212 | put_page(page); |
| 9213 | if (err == -EACCES) |
| 9214 | return -EPERM; |
| 9215 | out: |
| 9216 | return err; |
| 9217 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9218 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9219 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9220 | nfs4_stateid *stateid, |
| 9221 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9222 | { |
| 9223 | int status; |
| 9224 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9225 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9226 | }; |
| 9227 | struct nfs41_test_stateid_res res; |
| 9228 | struct rpc_message msg = { |
| 9229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9230 | .rpc_argp = &args, |
| 9231 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9232 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9233 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9234 | struct rpc_clnt *rpc_client = server->client; |
| 9235 | |
| 9236 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9237 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9238 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9239 | dprintk("NFS call test_stateid %p\n", stateid); |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9240 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 1); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9241 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9242 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9243 | if (status != NFS_OK) { |
| 9244 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9245 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9246 | } |
| 9247 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9248 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9249 | } |
| 9250 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9251 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9252 | int err, struct nfs4_exception *exception) |
| 9253 | { |
| 9254 | exception->retry = 0; |
| 9255 | switch(err) { |
| 9256 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9257 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9258 | nfs4_handle_exception(server, err, exception); |
| 9259 | break; |
| 9260 | case -NFS4ERR_BADSESSION: |
| 9261 | case -NFS4ERR_BADSLOT: |
| 9262 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9263 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9264 | case -NFS4ERR_DEADSESSION: |
| 9265 | nfs4_do_handle_exception(server, err, exception); |
| 9266 | } |
| 9267 | } |
| 9268 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9269 | /** |
| 9270 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9271 | * |
| 9272 | * @server: server / transport on which to perform the operation |
| 9273 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9274 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9275 | * |
| 9276 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9277 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9278 | * failed or the state ID is not currently valid. |
| 9279 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9280 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9281 | nfs4_stateid *stateid, |
| 9282 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9283 | { |
| 9284 | struct nfs4_exception exception = { }; |
| 9285 | int err; |
| 9286 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9287 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9288 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9289 | } while (exception.retry); |
| 9290 | return err; |
| 9291 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9292 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9293 | struct nfs_free_stateid_data { |
| 9294 | struct nfs_server *server; |
| 9295 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9296 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9297 | }; |
| 9298 | |
| 9299 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9300 | { |
| 9301 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9302 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9303 | &data->args.seq_args, |
| 9304 | &data->res.seq_res, |
| 9305 | task); |
| 9306 | } |
| 9307 | |
| 9308 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9309 | { |
| 9310 | struct nfs_free_stateid_data *data = calldata; |
| 9311 | |
| 9312 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9313 | |
| 9314 | switch (task->tk_status) { |
| 9315 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9316 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9317 | rpc_restart_call_prepare(task); |
| 9318 | } |
| 9319 | } |
| 9320 | |
| 9321 | static void nfs41_free_stateid_release(void *calldata) |
| 9322 | { |
| 9323 | kfree(calldata); |
| 9324 | } |
| 9325 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9326 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9327 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9328 | .rpc_call_done = nfs41_free_stateid_done, |
| 9329 | .rpc_release = nfs41_free_stateid_release, |
| 9330 | }; |
| 9331 | |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9332 | /** |
| 9333 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9334 | * |
| 9335 | * @server: server / transport on which to perform the operation |
| 9336 | * @stateid: state ID to release |
| 9337 | * @cred: credential |
| 9338 | * @is_recovery: set to true if this call needs to be privileged |
| 9339 | * |
| 9340 | * Note: this function is always asynchronous. |
| 9341 | */ |
| 9342 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9343 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9344 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9345 | bool privileged) |
| 9346 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9347 | struct rpc_message msg = { |
| 9348 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9349 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9350 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9351 | struct rpc_task_setup task_setup = { |
| 9352 | .rpc_client = server->client, |
| 9353 | .rpc_message = &msg, |
| 9354 | .callback_ops = &nfs41_free_stateid_ops, |
| 9355 | .flags = RPC_TASK_ASYNC, |
| 9356 | }; |
| 9357 | struct nfs_free_stateid_data *data; |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9358 | struct rpc_task *task; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9359 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9360 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9361 | &task_setup.rpc_client, &msg); |
| 9362 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9363 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9364 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9365 | if (!data) |
Anna Schumaker | 2f26102 | 2018-05-15 13:03:39 -0400 | [diff] [blame] | 9366 | return -ENOMEM; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9367 | data->server = server; |
| 9368 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9369 | |
| 9370 | task_setup.callback_data = data; |
| 9371 | |
| 9372 | msg.rpc_argp = &data->args; |
| 9373 | msg.rpc_resp = &data->res; |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 9374 | 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] | 9375 | task = rpc_run_task(&task_setup); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9376 | if (IS_ERR(task)) |
| 9377 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9378 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9379 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9380 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9381 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9382 | static void |
| 9383 | 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] | 9384 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9385 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9386 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9387 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9388 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9389 | } |
| 9390 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9391 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9392 | const nfs4_stateid *s2) |
| 9393 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9394 | if (s1->type != s2->type) |
| 9395 | return false; |
| 9396 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9397 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9398 | return false; |
| 9399 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9400 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9401 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9402 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9403 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9404 | } |
| 9405 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9406 | #endif /* CONFIG_NFS_V4_1 */ |
| 9407 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9408 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9409 | const nfs4_stateid *s2) |
| 9410 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9411 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9412 | } |
| 9413 | |
| 9414 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9415 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9416 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9417 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9418 | .recover_open = nfs4_open_reclaim, |
| 9419 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9420 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9421 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9422 | }; |
| 9423 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9424 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9425 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9426 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9427 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9428 | .recover_open = nfs4_open_reclaim, |
| 9429 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9430 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9431 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9432 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9433 | }; |
| 9434 | #endif /* CONFIG_NFS_V4_1 */ |
| 9435 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9436 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9437 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9438 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9439 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9440 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9441 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9442 | }; |
| 9443 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9444 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9445 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9446 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9447 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9448 | .recover_open = nfs41_open_expired, |
| 9449 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9450 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9451 | }; |
| 9452 | #endif /* CONFIG_NFS_V4_1 */ |
| 9453 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9454 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9455 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9456 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9457 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9458 | }; |
| 9459 | |
| 9460 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9461 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9462 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9463 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9464 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9465 | }; |
| 9466 | #endif |
| 9467 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9468 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9469 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9470 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9471 | }; |
| 9472 | |
| 9473 | #if defined(CONFIG_NFS_V4_1) |
| 9474 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9475 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9476 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9477 | }; |
| 9478 | #endif /* CONFIG_NFS_V4_1 */ |
| 9479 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9480 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9481 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9482 | .init_caps = NFS_CAP_READDIRPLUS |
| 9483 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9484 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9485 | .init_client = nfs40_init_client, |
| 9486 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9487 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9488 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9489 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9490 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9491 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9492 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9493 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9494 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9495 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9496 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9497 | }; |
| 9498 | |
| 9499 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9500 | static struct nfs_seqid * |
| 9501 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9502 | { |
| 9503 | return NULL; |
| 9504 | } |
| 9505 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9506 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9507 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9508 | .init_caps = NFS_CAP_READDIRPLUS |
| 9509 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9510 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9511 | | NFS_CAP_STATEID_NFSV41 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9512 | | NFS_CAP_ATOMIC_OPEN_V1 |
| 9513 | | NFS_CAP_LGOPEN, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9514 | .init_client = nfs41_init_client, |
| 9515 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9516 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9517 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9518 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9519 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9520 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9521 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9522 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9523 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9524 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9525 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9526 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9527 | }; |
| 9528 | #endif |
| 9529 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9530 | #if defined(CONFIG_NFS_V4_2) |
| 9531 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9532 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9533 | .init_caps = NFS_CAP_READDIRPLUS |
| 9534 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9535 | | NFS_CAP_POSIX_LOCK |
| 9536 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9537 | | NFS_CAP_ATOMIC_OPEN_V1 |
Fred Isaman | 6e01260 | 2016-10-04 15:26:41 -0400 | [diff] [blame] | 9538 | | NFS_CAP_LGOPEN |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9539 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9540 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9541 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9542 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9543 | | NFS_CAP_LAYOUTSTATS |
| 9544 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9545 | .init_client = nfs41_init_client, |
| 9546 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9547 | .match_stateid = nfs41_match_stateid, |
| 9548 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9549 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9550 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9551 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9552 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9553 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9554 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9555 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9556 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9557 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9558 | }; |
| 9559 | #endif |
| 9560 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9561 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9562 | [0] = &nfs_v4_0_minor_ops, |
| 9563 | #if defined(CONFIG_NFS_V4_1) |
| 9564 | [1] = &nfs_v4_1_minor_ops, |
| 9565 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9566 | #if defined(CONFIG_NFS_V4_2) |
| 9567 | [2] = &nfs_v4_2_minor_ops, |
| 9568 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9569 | }; |
| 9570 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9571 | 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] | 9572 | { |
| 9573 | ssize_t error, error2; |
| 9574 | |
| 9575 | error = generic_listxattr(dentry, list, size); |
| 9576 | if (error < 0) |
| 9577 | return error; |
| 9578 | if (list) { |
| 9579 | list += error; |
| 9580 | size -= error; |
| 9581 | } |
| 9582 | |
| 9583 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9584 | if (error2 < 0) |
| 9585 | return error2; |
| 9586 | return error + error2; |
| 9587 | } |
| 9588 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9589 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9590 | .create = nfs_create, |
| 9591 | .lookup = nfs_lookup, |
| 9592 | .atomic_open = nfs_atomic_open, |
| 9593 | .link = nfs_link, |
| 9594 | .unlink = nfs_unlink, |
| 9595 | .symlink = nfs_symlink, |
| 9596 | .mkdir = nfs_mkdir, |
| 9597 | .rmdir = nfs_rmdir, |
| 9598 | .mknod = nfs_mknod, |
| 9599 | .rename = nfs_rename, |
| 9600 | .permission = nfs_permission, |
| 9601 | .getattr = nfs_getattr, |
| 9602 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9603 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9604 | }; |
| 9605 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9606 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9607 | .permission = nfs_permission, |
| 9608 | .getattr = nfs_getattr, |
| 9609 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9610 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9611 | }; |
| 9612 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9613 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9614 | .version = 4, /* protocol version */ |
| 9615 | .dentry_ops = &nfs4_dentry_operations, |
| 9616 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9617 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9618 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9619 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9620 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9621 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9622 | .getattr = nfs4_proc_getattr, |
| 9623 | .setattr = nfs4_proc_setattr, |
| 9624 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9625 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9626 | .access = nfs4_proc_access, |
| 9627 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9628 | .create = nfs4_proc_create, |
| 9629 | .remove = nfs4_proc_remove, |
| 9630 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9631 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9632 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9633 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9634 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9635 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9636 | .link = nfs4_proc_link, |
| 9637 | .symlink = nfs4_proc_symlink, |
| 9638 | .mkdir = nfs4_proc_mkdir, |
Trond Myklebust | 912678d | 2018-03-20 16:43:15 -0400 | [diff] [blame] | 9639 | .rmdir = nfs4_proc_rmdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9640 | .readdir = nfs4_proc_readdir, |
| 9641 | .mknod = nfs4_proc_mknod, |
| 9642 | .statfs = nfs4_proc_statfs, |
| 9643 | .fsinfo = nfs4_proc_fsinfo, |
| 9644 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9645 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9646 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9647 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9648 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9649 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9650 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9651 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9652 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9653 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9654 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9655 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9656 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9657 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9658 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9659 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9660 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9661 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9662 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9663 | .create_server = nfs4_create_server, |
| 9664 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9665 | }; |
| 9666 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9667 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9668 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9669 | .list = nfs4_xattr_list_nfs4_acl, |
| 9670 | .get = nfs4_xattr_get_nfs4_acl, |
| 9671 | .set = nfs4_xattr_set_nfs4_acl, |
| 9672 | }; |
| 9673 | |
| 9674 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9675 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9676 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9677 | &nfs4_xattr_nfs4_label_handler, |
| 9678 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9679 | NULL |
| 9680 | }; |
| 9681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9682 | /* |
| 9683 | * Local variables: |
| 9684 | * c-basic-offset: 8 |
| 9685 | * End: |
| 9686 | */ |