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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 58 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 60 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 61 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 62 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 63 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 64 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 65 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 66 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 67 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 69 | #include "nfs4trace.h" |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 72 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 73 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 75 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 76 | /* file attributes which can be mapped to nfs attributes */ |
| 77 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 78 | | ATTR_UID \ |
| 79 | | ATTR_GID \ |
| 80 | | ATTR_SIZE \ |
| 81 | | ATTR_ATIME \ |
| 82 | | ATTR_MTIME \ |
| 83 | | ATTR_CTIME \ |
| 84 | | ATTR_ATIME_SET \ |
| 85 | | ATTR_MTIME_SET) |
| 86 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 87 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 88 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 89 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 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] | 91 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 92 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 93 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 94 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 95 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 96 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 98 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 99 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 100 | struct rpc_cred *cred, |
| 101 | struct nfs4_slot *slot, |
| 102 | bool is_privileged); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 103 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 104 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 105 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 106 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 107 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 108 | |
| 109 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 110 | static inline struct nfs4_label * |
| 111 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 112 | struct iattr *sattr, struct nfs4_label *label) |
| 113 | { |
| 114 | int err; |
| 115 | |
| 116 | if (label == NULL) |
| 117 | return NULL; |
| 118 | |
| 119 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 120 | return NULL; |
| 121 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 122 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 123 | &dentry->d_name, (void **)&label->label, &label->len); |
| 124 | if (err == 0) |
| 125 | return label; |
| 126 | |
| 127 | return NULL; |
| 128 | } |
| 129 | static inline void |
| 130 | nfs4_label_release_security(struct nfs4_label *label) |
| 131 | { |
| 132 | if (label) |
| 133 | security_release_secctx(label->label, label->len); |
| 134 | } |
| 135 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 136 | { |
| 137 | if (label) |
| 138 | return server->attr_bitmask; |
| 139 | |
| 140 | return server->attr_bitmask_nl; |
| 141 | } |
| 142 | #else |
| 143 | static inline struct nfs4_label * |
| 144 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 145 | struct iattr *sattr, struct nfs4_label *l) |
| 146 | { return NULL; } |
| 147 | static inline void |
| 148 | nfs4_label_release_security(struct nfs4_label *label) |
| 149 | { return; } |
| 150 | static inline u32 * |
| 151 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 152 | { return server->attr_bitmask; } |
| 153 | #endif |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 156 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 158 | if (err >= -1000) |
| 159 | return err; |
| 160 | switch (err) { |
| 161 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 162 | case -NFS4ERR_LAYOUTTRYLATER: |
| 163 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 164 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 165 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 166 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 167 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 168 | case -NFS4ERR_BADOWNER: |
| 169 | case -NFS4ERR_BADNAME: |
| 170 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 171 | case -NFS4ERR_SHARE_DENIED: |
| 172 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 173 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 174 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 175 | case -NFS4ERR_FILE_OPEN: |
| 176 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 179 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 180 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 182 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* |
| 186 | * This is our standard bitmap for GETATTR requests. |
| 187 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 188 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | FATTR4_WORD0_TYPE |
| 190 | | FATTR4_WORD0_CHANGE |
| 191 | | FATTR4_WORD0_SIZE |
| 192 | | FATTR4_WORD0_FSID |
| 193 | | FATTR4_WORD0_FILEID, |
| 194 | FATTR4_WORD1_MODE |
| 195 | | FATTR4_WORD1_NUMLINKS |
| 196 | | FATTR4_WORD1_OWNER |
| 197 | | FATTR4_WORD1_OWNER_GROUP |
| 198 | | FATTR4_WORD1_RAWDEV |
| 199 | | FATTR4_WORD1_SPACE_USED |
| 200 | | FATTR4_WORD1_TIME_ACCESS |
| 201 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 202 | | FATTR4_WORD1_TIME_MODIFY |
| 203 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 204 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 205 | FATTR4_WORD2_SECURITY_LABEL |
| 206 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 209 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 210 | FATTR4_WORD0_TYPE |
| 211 | | FATTR4_WORD0_CHANGE |
| 212 | | FATTR4_WORD0_SIZE |
| 213 | | FATTR4_WORD0_FSID |
| 214 | | FATTR4_WORD0_FILEID, |
| 215 | FATTR4_WORD1_MODE |
| 216 | | FATTR4_WORD1_NUMLINKS |
| 217 | | FATTR4_WORD1_OWNER |
| 218 | | FATTR4_WORD1_OWNER_GROUP |
| 219 | | FATTR4_WORD1_RAWDEV |
| 220 | | FATTR4_WORD1_SPACE_USED |
| 221 | | FATTR4_WORD1_TIME_ACCESS |
| 222 | | FATTR4_WORD1_TIME_METADATA |
| 223 | | FATTR4_WORD1_TIME_MODIFY, |
| 224 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 225 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 226 | | FATTR4_WORD2_SECURITY_LABEL |
| 227 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 228 | }; |
| 229 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 230 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 231 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 232 | | FATTR4_WORD0_FILEID, |
| 233 | }; |
| 234 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 235 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | FATTR4_WORD0_FILES_AVAIL |
| 237 | | FATTR4_WORD0_FILES_FREE |
| 238 | | FATTR4_WORD0_FILES_TOTAL, |
| 239 | FATTR4_WORD1_SPACE_AVAIL |
| 240 | | FATTR4_WORD1_SPACE_FREE |
| 241 | | FATTR4_WORD1_SPACE_TOTAL |
| 242 | }; |
| 243 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 244 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | FATTR4_WORD0_MAXLINK |
| 246 | | FATTR4_WORD0_MAXNAME, |
| 247 | 0 |
| 248 | }; |
| 249 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 250 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | | FATTR4_WORD0_MAXREAD |
| 252 | | FATTR4_WORD0_MAXWRITE |
| 253 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 254 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 255 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 256 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 257 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 260 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 261 | FATTR4_WORD0_TYPE |
| 262 | | FATTR4_WORD0_CHANGE |
| 263 | | FATTR4_WORD0_SIZE |
| 264 | | FATTR4_WORD0_FSID |
| 265 | | FATTR4_WORD0_FILEID |
| 266 | | FATTR4_WORD0_FS_LOCATIONS, |
| 267 | FATTR4_WORD1_MODE |
| 268 | | FATTR4_WORD1_NUMLINKS |
| 269 | | FATTR4_WORD1_OWNER |
| 270 | | FATTR4_WORD1_OWNER_GROUP |
| 271 | | FATTR4_WORD1_RAWDEV |
| 272 | | FATTR4_WORD1_SPACE_USED |
| 273 | | FATTR4_WORD1_TIME_ACCESS |
| 274 | | FATTR4_WORD1_TIME_METADATA |
| 275 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 276 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 277 | }; |
| 278 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 279 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | struct nfs4_readdir_arg *readdir) |
| 281 | { |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 282 | unsigned int attrs = FATTR4_WORD0_FILEID | FATTR4_WORD0_TYPE; |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 283 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 286 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | readdir->cookie = 0; |
| 292 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 293 | if (cookie == 2) |
| 294 | return; |
| 295 | |
| 296 | /* |
| 297 | * NFSv4 servers do not return entries for '.' and '..' |
| 298 | * Therefore, we fake these entries here. We let '.' |
| 299 | * have cookie 0 and '..' have cookie 1. Note that |
| 300 | * when talking to the server, we always send cookie 0 |
| 301 | * instead of 1 or 2. |
| 302 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 303 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | if (cookie == 0) { |
| 306 | *p++ = xdr_one; /* next */ |
| 307 | *p++ = xdr_zero; /* cookie, first word */ |
| 308 | *p++ = xdr_one; /* cookie, second word */ |
| 309 | *p++ = xdr_one; /* entry len */ |
| 310 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 311 | p++; |
| 312 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 313 | *p++ = htonl(attrs); /* bitmap */ |
| 314 | *p++ = htonl(12); /* attribute buffer length */ |
| 315 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 316 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | *p++ = xdr_one; /* next */ |
| 320 | *p++ = xdr_zero; /* cookie, first word */ |
| 321 | *p++ = xdr_two; /* cookie, second word */ |
| 322 | *p++ = xdr_two; /* entry len */ |
| 323 | memcpy(p, "..\0\0", 4); /* entry */ |
| 324 | p++; |
| 325 | *p++ = xdr_one; /* bitmap length */ |
Anna Schumaker | 18fe6a2 | 2017-06-16 12:06:59 -0400 | [diff] [blame] | 326 | *p++ = htonl(attrs); /* bitmap */ |
| 327 | *p++ = htonl(12); /* attribute buffer length */ |
| 328 | *p++ = htonl(NF4DIR); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 329 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | readdir->pgbase = (char *)p - (char *)start; |
| 332 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 333 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 336 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 337 | nfs4_stateid *stateid, |
| 338 | struct rpc_cred *cred) |
| 339 | { |
| 340 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 341 | |
| 342 | ops->test_and_free_expired(server, stateid, cred); |
| 343 | } |
| 344 | |
| 345 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 346 | nfs4_stateid *stateid, |
| 347 | struct rpc_cred *cred) |
| 348 | { |
| 349 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 350 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 351 | } |
| 352 | |
| 353 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 354 | const nfs4_stateid *stateid, |
| 355 | struct rpc_cred *cred) |
| 356 | { |
| 357 | nfs4_stateid tmp; |
| 358 | |
| 359 | nfs4_stateid_copy(&tmp, stateid); |
| 360 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 361 | } |
| 362 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 363 | static long nfs4_update_delay(long *timeout) |
| 364 | { |
| 365 | long ret; |
| 366 | if (!timeout) |
| 367 | return NFS4_POLL_RETRY_MAX; |
| 368 | if (*timeout <= 0) |
| 369 | *timeout = NFS4_POLL_RETRY_MIN; |
| 370 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 371 | *timeout = NFS4_POLL_RETRY_MAX; |
| 372 | ret = *timeout; |
| 373 | *timeout <<= 1; |
| 374 | return ret; |
| 375 | } |
| 376 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 377 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 378 | { |
| 379 | int res = 0; |
| 380 | |
| 381 | might_sleep(); |
| 382 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 383 | freezable_schedule_timeout_killable_unsafe( |
| 384 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 385 | if (fatal_signal_pending(current)) |
| 386 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 387 | return res; |
| 388 | } |
| 389 | |
| 390 | /* This is the error handling routine for processes that are allowed |
| 391 | * to sleep. |
| 392 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 393 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 394 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 395 | { |
| 396 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 397 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 398 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 399 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 400 | int ret = errorcode; |
| 401 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 402 | exception->delay = 0; |
| 403 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 405 | |
| 406 | if (stateid == NULL && state != NULL) |
| 407 | stateid = &state->stateid; |
| 408 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 409 | switch(errorcode) { |
| 410 | case 0: |
| 411 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 412 | case -NFS4ERR_DELEG_REVOKED: |
| 413 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 414 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 415 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 416 | if (inode != NULL && stateid != NULL) { |
| 417 | nfs_inode_find_state_and_recover(inode, |
| 418 | stateid); |
| 419 | goto wait_on_recovery; |
| 420 | } |
| 421 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 422 | if (inode) { |
| 423 | int err; |
| 424 | |
| 425 | err = nfs_async_inode_return_delegation(inode, |
| 426 | stateid); |
| 427 | if (err == 0) |
| 428 | goto wait_on_recovery; |
| 429 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 430 | exception->retry = 1; |
| 431 | break; |
| 432 | } |
| 433 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 434 | if (state == NULL) |
| 435 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 436 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 437 | if (ret < 0) |
| 438 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 439 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 440 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 441 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 442 | nfs4_schedule_lease_recovery(clp); |
| 443 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 444 | case -NFS4ERR_MOVED: |
| 445 | ret = nfs4_schedule_migration_recovery(server); |
| 446 | if (ret < 0) |
| 447 | break; |
| 448 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 449 | case -NFS4ERR_LEASE_MOVED: |
| 450 | nfs4_schedule_lease_moved_recovery(clp); |
| 451 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 452 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 453 | case -NFS4ERR_BADSESSION: |
| 454 | case -NFS4ERR_BADSLOT: |
| 455 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 456 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 457 | case -NFS4ERR_DEADSESSION: |
| 458 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 459 | case -NFS4ERR_SEQ_MISORDERED: |
| 460 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 461 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 462 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 463 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 464 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 465 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 466 | if (exception->timeout > HZ) { |
| 467 | /* We have retried a decent amount, time to |
| 468 | * fail |
| 469 | */ |
| 470 | ret = -EBUSY; |
| 471 | break; |
| 472 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 473 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 474 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 475 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 476 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 477 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 478 | exception->delay = 1; |
| 479 | return 0; |
| 480 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 481 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 482 | case -NFS4ERR_OLD_STATEID: |
| 483 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 484 | break; |
| 485 | case -NFS4ERR_BADOWNER: |
| 486 | /* The following works around a Linux server bug! */ |
| 487 | case -NFS4ERR_BADNAME: |
| 488 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 489 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 490 | exception->retry = 1; |
| 491 | printk(KERN_WARNING "NFS: v4 server %s " |
| 492 | "does not accept raw " |
| 493 | "uid/gids. " |
| 494 | "Reenabling the idmapper.\n", |
| 495 | server->nfs_client->cl_hostname); |
| 496 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 497 | } |
| 498 | /* We failed to handle the error */ |
| 499 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 500 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 501 | exception->recovering = 1; |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | /* This is the error handling routine for processes that are allowed |
| 506 | * to sleep. |
| 507 | */ |
| 508 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 509 | { |
| 510 | struct nfs_client *clp = server->nfs_client; |
| 511 | int ret; |
| 512 | |
| 513 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 514 | if (exception->delay) { |
| 515 | ret = nfs4_delay(server->client, &exception->timeout); |
| 516 | goto out_retry; |
| 517 | } |
| 518 | if (exception->recovering) { |
| 519 | ret = nfs4_wait_clnt_recover(clp); |
| 520 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 521 | return -EIO; |
| 522 | goto out_retry; |
| 523 | } |
| 524 | return ret; |
| 525 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 526 | if (ret == 0) |
| 527 | exception->retry = 1; |
| 528 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 531 | static int |
| 532 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 533 | int errorcode, struct nfs4_exception *exception) |
| 534 | { |
| 535 | struct nfs_client *clp = server->nfs_client; |
| 536 | int ret; |
| 537 | |
| 538 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 539 | if (exception->delay) { |
| 540 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 541 | goto out_retry; |
| 542 | } |
| 543 | if (exception->recovering) { |
| 544 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 545 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 546 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 547 | goto out_retry; |
| 548 | } |
| 549 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 550 | ret = -EIO; |
| 551 | return ret; |
| 552 | out_retry: |
| 553 | if (ret == 0) |
| 554 | exception->retry = 1; |
| 555 | return ret; |
| 556 | } |
| 557 | |
| 558 | static int |
| 559 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 560 | struct nfs4_state *state, long *timeout) |
| 561 | { |
| 562 | struct nfs4_exception exception = { |
| 563 | .state = state, |
| 564 | }; |
| 565 | |
| 566 | if (task->tk_status >= 0) |
| 567 | return 0; |
| 568 | if (timeout) |
| 569 | exception.timeout = *timeout; |
| 570 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 571 | task->tk_status, |
| 572 | &exception); |
| 573 | if (exception.delay && timeout) |
| 574 | *timeout = exception.timeout; |
| 575 | if (exception.retry) |
| 576 | return -EAGAIN; |
| 577 | return 0; |
| 578 | } |
| 579 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 580 | /* |
| 581 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 582 | * or 'false' otherwise. |
| 583 | */ |
| 584 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 585 | { |
| 586 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 587 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 588 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 589 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 590 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | spin_lock(&clp->cl_lock); |
| 593 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 594 | clp->cl_last_renewal = timestamp; |
| 595 | spin_unlock(&clp->cl_lock); |
| 596 | } |
| 597 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 598 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 599 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 600 | struct nfs_client *clp = server->nfs_client; |
| 601 | |
| 602 | if (!nfs4_has_session(clp)) |
| 603 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 606 | struct nfs4_call_sync_data { |
| 607 | const struct nfs_server *seq_server; |
| 608 | struct nfs4_sequence_args *seq_args; |
| 609 | struct nfs4_sequence_res *seq_res; |
| 610 | }; |
| 611 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 612 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 613 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 614 | { |
| 615 | args->sa_slot = NULL; |
| 616 | args->sa_cache_this = cache_reply; |
| 617 | args->sa_privileged = 0; |
| 618 | |
| 619 | res->sr_slot = NULL; |
| 620 | } |
| 621 | |
| 622 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 623 | { |
| 624 | args->sa_privileged = 1; |
| 625 | } |
| 626 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 627 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 628 | { |
| 629 | struct nfs4_slot *slot = res->sr_slot; |
| 630 | struct nfs4_slot_table *tbl; |
| 631 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 632 | tbl = slot->table; |
| 633 | spin_lock(&tbl->slot_tbl_lock); |
| 634 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 635 | nfs4_free_slot(tbl, slot); |
| 636 | spin_unlock(&tbl->slot_tbl_lock); |
| 637 | |
| 638 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static int nfs40_sequence_done(struct rpc_task *task, |
| 642 | struct nfs4_sequence_res *res) |
| 643 | { |
| 644 | if (res->sr_slot != NULL) |
| 645 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 646 | return 1; |
| 647 | } |
| 648 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 649 | #if defined(CONFIG_NFS_V4_1) |
| 650 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 651 | static void nfs41_release_slot(struct nfs4_slot *slot) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 652 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 653 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 654 | struct nfs4_slot_table *tbl; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 655 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 656 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 657 | if (!slot) |
| 658 | return; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 659 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 660 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 661 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 662 | /* Bump the slot sequence number */ |
| 663 | if (slot->seq_done) |
| 664 | slot->seq_nr++; |
| 665 | slot->seq_done = 0; |
| 666 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 667 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 668 | /* Be nice to the server: try to ensure that the last transmitted |
| 669 | * value for highest_user_slotid <= target_highest_slotid |
| 670 | */ |
| 671 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 672 | send_new_highest_used_slotid = true; |
| 673 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 674 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 675 | send_new_highest_used_slotid = false; |
| 676 | goto out_unlock; |
| 677 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 678 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 679 | |
| 680 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 681 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 682 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 683 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 684 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 685 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 686 | if (waitqueue_active(&tbl->slot_waitq)) |
| 687 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 690 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
| 691 | { |
| 692 | nfs41_release_slot(res->sr_slot); |
| 693 | res->sr_slot = NULL; |
| 694 | } |
| 695 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 696 | static int nfs41_sequence_process(struct rpc_task *task, |
| 697 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 698 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 699 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 700 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 701 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 702 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 703 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 704 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | if (slot == NULL) |
| 706 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 707 | /* don't increment the sequence number if the task wasn't sent */ |
| 708 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 709 | goto out; |
| 710 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 711 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 712 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 713 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 714 | if (res->sr_status != -NFS4ERR_DELAY) |
| 715 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 716 | interrupted = true; |
| 717 | } |
| 718 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 719 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 720 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 721 | switch (res->sr_status) { |
| 722 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 723 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 724 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 725 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 726 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 727 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 728 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 729 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 730 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 731 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 732 | case 1: |
| 733 | /* |
| 734 | * sr_status remains 1 if an RPC level error occurred. |
| 735 | * The server may or may not have processed the sequence |
| 736 | * operation.. |
| 737 | * Mark the slot as having hosted an interrupted RPC call. |
| 738 | */ |
| 739 | slot->interrupted = 1; |
| 740 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 741 | case -NFS4ERR_DELAY: |
| 742 | /* The server detected a resend of the RPC call and |
| 743 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 744 | * of RFC5661. |
| 745 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 746 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 747 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 748 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 749 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 750 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 751 | case -NFS4ERR_BADSLOT: |
| 752 | /* |
| 753 | * The slot id we used was probably retired. Try again |
| 754 | * using a different slot id. |
| 755 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 756 | if (slot->seq_nr < slot->table->target_highest_slotid) |
| 757 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 758 | goto retry_nowait; |
| 759 | case -NFS4ERR_SEQ_MISORDERED: |
| 760 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 761 | * Was the last operation on this sequence interrupted? |
| 762 | * If so, retry after bumping the sequence number. |
| 763 | */ |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 764 | if (interrupted) |
| 765 | goto retry_new_seq; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 766 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 767 | * Could this slot have been previously retired? |
| 768 | * If so, then the server may be expecting seq_nr = 1! |
| 769 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 770 | if (slot->seq_nr != 1) { |
| 771 | slot->seq_nr = 1; |
| 772 | goto retry_nowait; |
| 773 | } |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 774 | goto session_recover; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 775 | case -NFS4ERR_SEQ_FALSE_RETRY: |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 776 | if (interrupted) |
| 777 | goto retry_new_seq; |
| 778 | goto session_recover; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 779 | default: |
| 780 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 781 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 782 | } |
| 783 | out: |
| 784 | /* The session may be reset by one of the error handlers. */ |
| 785 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 786 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 787 | return ret; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 788 | session_recover: |
| 789 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 790 | goto retry_nowait; |
| 791 | retry_new_seq: |
| 792 | ++slot->seq_nr; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 793 | retry_nowait: |
| 794 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 795 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 796 | task->tk_status = 0; |
| 797 | ret = 0; |
| 798 | } |
| 799 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 800 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 801 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 802 | goto out; |
| 803 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 804 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 805 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 806 | |
| 807 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 808 | { |
| 809 | if (!nfs41_sequence_process(task, res)) |
| 810 | return 0; |
| 811 | if (res->sr_slot != NULL) |
| 812 | nfs41_sequence_free_slot(res); |
| 813 | return 1; |
| 814 | |
| 815 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 816 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 817 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 818 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 819 | { |
| 820 | if (res->sr_slot == NULL) |
| 821 | return 1; |
| 822 | if (res->sr_slot->table->session != NULL) |
| 823 | return nfs41_sequence_process(task, res); |
| 824 | return nfs40_sequence_done(task, res); |
| 825 | } |
| 826 | |
| 827 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 828 | { |
| 829 | if (res->sr_slot != NULL) { |
| 830 | if (res->sr_slot->table->session != NULL) |
| 831 | nfs41_sequence_free_slot(res); |
| 832 | else |
| 833 | nfs40_sequence_free_slot(res); |
| 834 | } |
| 835 | } |
| 836 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 837 | 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] | 838 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 839 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 840 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 841 | if (!res->sr_slot->table->session) |
| 842 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 843 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 844 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 845 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 846 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 847 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 848 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 849 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 850 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 851 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 852 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 853 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 854 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 855 | } |
| 856 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 857 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 858 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 859 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 860 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 861 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 862 | } |
| 863 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 864 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 865 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 866 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 867 | }; |
| 868 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 869 | static void |
| 870 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 871 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 872 | { |
| 873 | struct rpc_task *task; |
| 874 | |
| 875 | task = _nfs41_proc_sequence(client, cred, slot, true); |
| 876 | if (!IS_ERR(task)) |
| 877 | rpc_put_task_async(task); |
| 878 | } |
| 879 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 880 | #else /* !CONFIG_NFS_V4_1 */ |
| 881 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 882 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 883 | { |
| 884 | return nfs40_sequence_done(task, res); |
| 885 | } |
| 886 | |
| 887 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 888 | { |
| 889 | if (res->sr_slot != NULL) |
| 890 | nfs40_sequence_free_slot(res); |
| 891 | } |
| 892 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 893 | int nfs4_sequence_done(struct rpc_task *task, |
| 894 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 895 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 896 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 897 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 898 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 899 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 900 | static void |
| 901 | nfs4_sequence_process_interrupted(struct nfs_client *client, |
| 902 | struct nfs4_slot *slot, struct rpc_cred *cred) |
| 903 | { |
| 904 | WARN_ON_ONCE(1); |
| 905 | slot->interrupted = 0; |
| 906 | } |
| 907 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 908 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 909 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 910 | static |
| 911 | void nfs4_sequence_attach_slot(struct nfs4_sequence_args *args, |
| 912 | struct nfs4_sequence_res *res, |
| 913 | struct nfs4_slot *slot) |
| 914 | { |
| 915 | if (!slot) |
| 916 | return; |
| 917 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 918 | args->sa_slot = slot; |
| 919 | |
| 920 | res->sr_slot = slot; |
| 921 | res->sr_timestamp = jiffies; |
| 922 | res->sr_status_flags = 0; |
| 923 | res->sr_status = 1; |
| 924 | |
| 925 | } |
| 926 | |
| 927 | int nfs4_setup_sequence(struct nfs_client *client, |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 928 | struct nfs4_sequence_args *args, |
| 929 | struct nfs4_sequence_res *res, |
| 930 | struct rpc_task *task) |
| 931 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 932 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 933 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 934 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 935 | |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 936 | /* slot already allocated? */ |
| 937 | if (res->sr_slot != NULL) |
| 938 | goto out_start; |
| 939 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 940 | if (session) { |
| 941 | tbl = &session->fc_slot_table; |
| 942 | task->tk_timeout = 0; |
| 943 | } |
| 944 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 945 | for (;;) { |
| 946 | spin_lock(&tbl->slot_tbl_lock); |
| 947 | /* The state manager will wait until the slot table is empty */ |
| 948 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 949 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 950 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 951 | slot = nfs4_alloc_slot(tbl); |
| 952 | if (IS_ERR(slot)) { |
| 953 | /* Try again in 1/4 second */ |
| 954 | if (slot == ERR_PTR(-ENOMEM)) |
| 955 | task->tk_timeout = HZ >> 2; |
| 956 | goto out_sleep; |
| 957 | } |
| 958 | spin_unlock(&tbl->slot_tbl_lock); |
| 959 | |
| 960 | if (likely(!slot->interrupted)) |
| 961 | break; |
| 962 | nfs4_sequence_process_interrupted(client, |
| 963 | slot, task->tk_msg.rpc_cred); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 964 | } |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 965 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 966 | nfs4_sequence_attach_slot(args, res, slot); |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 967 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 968 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107f | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 969 | out_start: |
| 970 | rpc_call_start(task); |
| 971 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 972 | |
| 973 | out_sleep: |
| 974 | if (args->sa_privileged) |
| 975 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 976 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 977 | else |
| 978 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 979 | spin_unlock(&tbl->slot_tbl_lock); |
| 980 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 981 | } |
| 982 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 983 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 984 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 985 | { |
| 986 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 987 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 988 | data->seq_args, data->seq_res, task); |
| 989 | } |
| 990 | |
| 991 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 992 | { |
| 993 | struct nfs4_call_sync_data *data = calldata; |
| 994 | nfs4_sequence_done(task, data->seq_res); |
| 995 | } |
| 996 | |
| 997 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 998 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 999 | .rpc_call_done = nfs40_call_sync_done, |
| 1000 | }; |
| 1001 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1002 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1003 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1004 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1005 | struct nfs4_sequence_args *args, |
| 1006 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1007 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1008 | int ret; |
| 1009 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1010 | struct nfs_client *clp = server->nfs_client; |
| 1011 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1012 | .seq_server = server, |
| 1013 | .seq_args = args, |
| 1014 | .seq_res = res, |
| 1015 | }; |
| 1016 | struct rpc_task_setup task_setup = { |
| 1017 | .rpc_client = clnt, |
| 1018 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1019 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1020 | .callback_data = &data |
| 1021 | }; |
| 1022 | |
| 1023 | task = rpc_run_task(&task_setup); |
| 1024 | if (IS_ERR(task)) |
| 1025 | ret = PTR_ERR(task); |
| 1026 | else { |
| 1027 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1028 | rpc_put_task(task); |
| 1029 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1030 | return ret; |
| 1031 | } |
| 1032 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1033 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1034 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1035 | struct rpc_message *msg, |
| 1036 | struct nfs4_sequence_args *args, |
| 1037 | struct nfs4_sequence_res *res, |
| 1038 | int cache_reply) |
| 1039 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1040 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1041 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1042 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1044 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1045 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | { |
| 1047 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1048 | |
| 1049 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1050 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1051 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1052 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1053 | nfsi->attrtimeo_timestamp = jiffies; |
| 1054 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1056 | if (cinfo->before != dir->i_version) |
| 1057 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1058 | NFS_INO_INVALID_ACL; |
| 1059 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1060 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1061 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1062 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1063 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | spin_unlock(&dir->i_lock); |
| 1065 | } |
| 1066 | |
| 1067 | struct nfs4_opendata { |
| 1068 | struct kref kref; |
| 1069 | struct nfs_openargs o_arg; |
| 1070 | struct nfs_openres o_res; |
| 1071 | struct nfs_open_confirmargs c_arg; |
| 1072 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1073 | struct nfs4_string owner_name; |
| 1074 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1075 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1077 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1079 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | struct nfs4_state_owner *owner; |
| 1081 | struct nfs4_state *state; |
| 1082 | struct iattr attrs; |
| 1083 | unsigned long timestamp; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 1084 | bool rpc_done; |
| 1085 | bool file_created; |
| 1086 | bool is_recover; |
| 1087 | bool cancelled; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1088 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1090 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1091 | struct nfs4_open_createattrs { |
| 1092 | struct nfs4_label *label; |
| 1093 | struct iattr *sattr; |
| 1094 | const __u32 verf[2]; |
| 1095 | }; |
| 1096 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1097 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1098 | int err, struct nfs4_exception *exception) |
| 1099 | { |
| 1100 | if (err != -EINVAL) |
| 1101 | return false; |
| 1102 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1103 | return false; |
| 1104 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1105 | exception->retry = 1; |
| 1106 | return true; |
| 1107 | } |
| 1108 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1109 | static u32 |
| 1110 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1111 | fmode_t fmode, int openflags) |
| 1112 | { |
| 1113 | u32 res = 0; |
| 1114 | |
| 1115 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1116 | case FMODE_READ: |
| 1117 | res = NFS4_SHARE_ACCESS_READ; |
| 1118 | break; |
| 1119 | case FMODE_WRITE: |
| 1120 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1121 | break; |
| 1122 | case FMODE_READ|FMODE_WRITE: |
| 1123 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1124 | } |
| 1125 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1126 | goto out; |
| 1127 | /* Want no delegation if we're using O_DIRECT */ |
| 1128 | if (openflags & O_DIRECT) |
| 1129 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1130 | out: |
| 1131 | return res; |
| 1132 | } |
| 1133 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1134 | static enum open_claim_type4 |
| 1135 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1136 | enum open_claim_type4 claim) |
| 1137 | { |
| 1138 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1139 | return claim; |
| 1140 | switch (claim) { |
| 1141 | default: |
| 1142 | return claim; |
| 1143 | case NFS4_OPEN_CLAIM_FH: |
| 1144 | return NFS4_OPEN_CLAIM_NULL; |
| 1145 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1146 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1147 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1148 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1149 | } |
| 1150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
| 1152 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1153 | { |
| 1154 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1155 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1156 | p->o_res.seqid = p->o_arg.seqid; |
| 1157 | p->c_res.seqid = p->c_arg.seqid; |
| 1158 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1159 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1160 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1161 | 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] | 1162 | } |
| 1163 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1164 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1165 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1166 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1167 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1168 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1169 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1170 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1171 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1172 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1173 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1174 | struct nfs4_label *label = (c != NULL) ? c->label : NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1175 | struct nfs4_opendata *p; |
| 1176 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1177 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1178 | if (p == NULL) |
| 1179 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1180 | |
| 1181 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1182 | if (IS_ERR(p->f_label)) |
| 1183 | goto err_free_p; |
| 1184 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1185 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1186 | if (IS_ERR(p->a_label)) |
| 1187 | goto err_free_f; |
| 1188 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1189 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1190 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1191 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1192 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1193 | nfs_sb_active(dentry->d_sb); |
| 1194 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | p->dir = parent; |
| 1196 | p->owner = sp; |
| 1197 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1198 | p->o_arg.open_flags = flags; |
| 1199 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1200 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1201 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1202 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1203 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1204 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1205 | * will return permission denied for all bits until close */ |
| 1206 | if (!(flags & O_EXCL)) { |
| 1207 | /* ask server to check for all possible rights as results |
| 1208 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1209 | switch (p->o_arg.claim) { |
| 1210 | default: |
| 1211 | break; |
| 1212 | case NFS4_OPEN_CLAIM_NULL: |
| 1213 | case NFS4_OPEN_CLAIM_FH: |
| 1214 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1215 | NFS4_ACCESS_MODIFY | |
| 1216 | NFS4_ACCESS_EXTEND | |
| 1217 | NFS4_ACCESS_EXECUTE; |
| 1218 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1219 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1220 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1221 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1222 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1223 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1224 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1225 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1226 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1227 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1228 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1229 | case NFS4_OPEN_CLAIM_NULL: |
| 1230 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1231 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1232 | p->o_arg.fh = NFS_FH(dir); |
| 1233 | break; |
| 1234 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1235 | case NFS4_OPEN_CLAIM_FH: |
| 1236 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1237 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1238 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1239 | } |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1240 | if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1241 | p->o_arg.u.attrs = &p->attrs; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1242 | memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1243 | |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1244 | memcpy(p->o_arg.u.verifier.data, c->verf, |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1245 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1247 | p->c_arg.fh = &p->o_res.fh; |
| 1248 | p->c_arg.stateid = &p->o_res.stateid; |
| 1249 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1250 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1251 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1252 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1253 | |
| 1254 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1255 | nfs4_label_free(p->a_label); |
| 1256 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1257 | nfs4_label_free(p->f_label); |
| 1258 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1259 | kfree(p); |
| 1260 | err: |
| 1261 | dput(parent); |
| 1262 | return NULL; |
| 1263 | } |
| 1264 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1265 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1266 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1267 | struct nfs4_opendata *p = container_of(kref, |
| 1268 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1269 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1270 | |
| 1271 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1272 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1273 | if (p->state != NULL) |
| 1274 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1275 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1276 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1277 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1278 | nfs4_label_free(p->f_label); |
| 1279 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1280 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1281 | dput(p->dentry); |
| 1282 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1283 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1284 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1285 | kfree(p); |
| 1286 | } |
| 1287 | |
| 1288 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1289 | { |
| 1290 | if (p != NULL) |
| 1291 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1292 | } |
| 1293 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1294 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1295 | fmode_t fmode) |
| 1296 | { |
| 1297 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1298 | case FMODE_READ|FMODE_WRITE: |
| 1299 | return state->n_rdwr != 0; |
| 1300 | case FMODE_WRITE: |
| 1301 | return state->n_wronly != 0; |
| 1302 | case FMODE_READ: |
| 1303 | return state->n_rdonly != 0; |
| 1304 | } |
| 1305 | WARN_ON_ONCE(1); |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1309 | 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] | 1310 | { |
| 1311 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1312 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1313 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1314 | goto out; |
| 1315 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1316 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1317 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1318 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1319 | break; |
| 1320 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1321 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1322 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1323 | break; |
| 1324 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1325 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1326 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1327 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1328 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1329 | return ret; |
| 1330 | } |
| 1331 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1332 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1333 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1334 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1335 | if (delegation == NULL) |
| 1336 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1337 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1338 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1339 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1340 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1341 | switch (claim) { |
| 1342 | case NFS4_OPEN_CLAIM_NULL: |
| 1343 | case NFS4_OPEN_CLAIM_FH: |
| 1344 | break; |
| 1345 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1346 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1347 | break; |
| 1348 | default: |
| 1349 | return 0; |
| 1350 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1351 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1352 | return 1; |
| 1353 | } |
| 1354 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1356 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1357 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1358 | case FMODE_WRITE: |
| 1359 | state->n_wronly++; |
| 1360 | break; |
| 1361 | case FMODE_READ: |
| 1362 | state->n_rdonly++; |
| 1363 | break; |
| 1364 | case FMODE_READ|FMODE_WRITE: |
| 1365 | state->n_rdwr++; |
| 1366 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1367 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1368 | } |
| 1369 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1370 | #ifdef CONFIG_NFS_V4_1 |
| 1371 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1372 | { |
| 1373 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1374 | return true; |
| 1375 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1376 | return true; |
| 1377 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1378 | return true; |
| 1379 | return false; |
| 1380 | } |
| 1381 | #endif /* CONFIG_NFS_V4_1 */ |
| 1382 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1383 | static void nfs_state_log_update_open_stateid(struct nfs4_state *state) |
| 1384 | { |
| 1385 | if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
| 1386 | wake_up_all(&state->waitq); |
| 1387 | } |
| 1388 | |
| 1389 | static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
| 1390 | const nfs4_stateid *stateid) |
| 1391 | { |
| 1392 | u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
| 1393 | u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
| 1394 | |
| 1395 | if (stateid_seqid == state_seqid + 1U || |
| 1396 | (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
| 1397 | nfs_state_log_update_open_stateid(state); |
| 1398 | else |
| 1399 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
| 1400 | } |
| 1401 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1402 | 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] | 1403 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1404 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1405 | bool need_recover = false; |
| 1406 | |
| 1407 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1408 | need_recover = true; |
| 1409 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1410 | need_recover = true; |
| 1411 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1412 | need_recover = true; |
| 1413 | if (need_recover) |
| 1414 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1415 | } |
| 1416 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1417 | /* |
| 1418 | * Check for whether or not the caller may update the open stateid |
| 1419 | * to the value passed in by stateid. |
| 1420 | * |
| 1421 | * Note: This function relies heavily on the server implementing |
| 1422 | * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2 |
| 1423 | * correctly. |
| 1424 | * i.e. The stateid seqids have to be initialised to 1, and |
| 1425 | * are then incremented on every state transition. |
| 1426 | */ |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1427 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1428 | const nfs4_stateid *stateid) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1429 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1430 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
| 1431 | !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1432 | if (stateid->seqid == cpu_to_be32(1)) |
| 1433 | nfs_state_log_update_open_stateid(state); |
| 1434 | else |
| 1435 | set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1436 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1437 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1438 | |
| 1439 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
| 1440 | nfs_state_log_out_of_order_open_stateid(state, stateid); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1441 | return true; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1442 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1443 | return false; |
| 1444 | } |
| 1445 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1446 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1447 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1448 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1449 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1450 | if (state->n_wronly) |
| 1451 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1452 | if (state->n_rdonly) |
| 1453 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1454 | if (state->n_rdwr) |
| 1455 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1456 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1457 | } |
| 1458 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1459 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1460 | nfs4_stateid *stateid, fmode_t fmode) |
| 1461 | { |
| 1462 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1463 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1464 | case FMODE_WRITE: |
| 1465 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1466 | break; |
| 1467 | case FMODE_READ: |
| 1468 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1469 | break; |
| 1470 | case 0: |
| 1471 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1472 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1473 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1474 | } |
| 1475 | if (stateid == NULL) |
| 1476 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1477 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1478 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1479 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1480 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1481 | goto out; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1482 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1483 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1484 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1485 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1486 | trace_nfs4_open_stateid_update(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1487 | out: |
| 1488 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1489 | } |
| 1490 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1491 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1492 | nfs4_stateid *arg_stateid, |
| 1493 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1494 | { |
| 1495 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1496 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1497 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1498 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1499 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1500 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1501 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1502 | } |
| 1503 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1504 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1505 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1506 | { |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1507 | DEFINE_WAIT(wait); |
| 1508 | int status = 0; |
| 1509 | for (;;) { |
| 1510 | |
| 1511 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1512 | return; |
| 1513 | if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1514 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1515 | if (status) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1516 | break; |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1517 | /* Rely on seqids for serialisation with NFSv4.0 */ |
| 1518 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
| 1519 | break; |
| 1520 | |
| 1521 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
| 1522 | /* |
| 1523 | * Ensure we process the state changes in the same order |
| 1524 | * in which the server processed them by delaying the |
| 1525 | * update of the stateid until we are in sequence. |
| 1526 | */ |
| 1527 | write_sequnlock(&state->seqlock); |
| 1528 | spin_unlock(&state->owner->so_lock); |
| 1529 | rcu_read_unlock(); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1530 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1531 | if (!signal_pending(current)) { |
| 1532 | if (schedule_timeout(5*HZ) == 0) |
| 1533 | status = -EAGAIN; |
| 1534 | else |
| 1535 | status = 0; |
| 1536 | } else |
| 1537 | status = -EINTR; |
| 1538 | finish_wait(&state->waitq, &wait); |
| 1539 | rcu_read_lock(); |
| 1540 | spin_lock(&state->owner->so_lock); |
| 1541 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1542 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1543 | |
| 1544 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1545 | nfs4_stateid_copy(freeme, &state->open_stateid); |
| 1546 | nfs_test_and_clear_all_open_stateid(state); |
| 1547 | } |
| 1548 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1549 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1550 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1551 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | ad9e02d | 2017-11-06 15:28:02 -0500 | [diff] [blame] | 1552 | trace_nfs4_open_stateid_update(state->inode, stateid, status); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1553 | nfs_state_log_update_open_stateid(state); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1554 | } |
| 1555 | |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1556 | static void nfs_state_set_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1557 | const nfs4_stateid *open_stateid, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1558 | fmode_t fmode, |
| 1559 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1561 | /* |
| 1562 | * Protect the call to nfs4_state_set_mode_locked and |
| 1563 | * serialise the stateid update |
| 1564 | */ |
| 1565 | write_seqlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1566 | nfs_set_open_stateid_locked(state, open_stateid, freeme); |
| 1567 | switch (fmode) { |
| 1568 | case FMODE_READ: |
| 1569 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1570 | break; |
| 1571 | case FMODE_WRITE: |
| 1572 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1573 | break; |
| 1574 | case FMODE_READ|FMODE_WRITE: |
| 1575 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1576 | } |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1577 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1578 | write_sequnlock(&state->seqlock); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static void nfs_state_set_delegation(struct nfs4_state *state, |
| 1582 | const nfs4_stateid *deleg_stateid, |
| 1583 | fmode_t fmode) |
| 1584 | { |
| 1585 | /* |
| 1586 | * Protect the call to nfs4_state_set_mode_locked and |
| 1587 | * serialise the stateid update |
| 1588 | */ |
| 1589 | write_seqlock(&state->seqlock); |
| 1590 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
| 1591 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1592 | write_sequnlock(&state->seqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1595 | static int update_open_stateid(struct nfs4_state *state, |
| 1596 | const nfs4_stateid *open_stateid, |
| 1597 | const nfs4_stateid *delegation, |
| 1598 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1599 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1600 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1601 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1602 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1603 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1604 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1605 | int ret = 0; |
| 1606 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1607 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1608 | |
| 1609 | rcu_read_lock(); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1610 | spin_lock(&state->owner->so_lock); |
| 1611 | if (open_stateid != NULL) { |
| 1612 | nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); |
| 1613 | ret = 1; |
| 1614 | } |
| 1615 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1616 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1617 | if (deleg_cur == NULL) |
| 1618 | goto no_delegation; |
| 1619 | |
| 1620 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1621 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1622 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1623 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1624 | goto no_delegation_unlock; |
| 1625 | |
| 1626 | if (delegation == NULL) |
| 1627 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1628 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1629 | goto no_delegation_unlock; |
| 1630 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1631 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1632 | nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1633 | ret = 1; |
| 1634 | no_delegation_unlock: |
| 1635 | spin_unlock(&deleg_cur->lock); |
| 1636 | no_delegation: |
Trond Myklebust | c9399f2 | 2017-11-06 15:28:01 -0500 | [diff] [blame] | 1637 | if (ret) |
| 1638 | update_open_stateflags(state, fmode); |
| 1639 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1640 | rcu_read_unlock(); |
| 1641 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1642 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1643 | nfs4_schedule_state_manager(clp); |
| 1644 | if (freeme.type != 0) |
| 1645 | nfs4_test_and_free_stateid(server, &freeme, |
| 1646 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1647 | |
| 1648 | return ret; |
| 1649 | } |
| 1650 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1651 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1652 | const nfs4_stateid *stateid) |
| 1653 | { |
| 1654 | struct nfs4_state *state = lsp->ls_state; |
| 1655 | bool ret = false; |
| 1656 | |
| 1657 | spin_lock(&state->state_lock); |
| 1658 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1659 | goto out_noupdate; |
| 1660 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1661 | goto out_noupdate; |
| 1662 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1663 | ret = true; |
| 1664 | out_noupdate: |
| 1665 | spin_unlock(&state->state_lock); |
| 1666 | return ret; |
| 1667 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1668 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1669 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1670 | { |
| 1671 | struct nfs_delegation *delegation; |
| 1672 | |
| 1673 | rcu_read_lock(); |
| 1674 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1675 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1676 | rcu_read_unlock(); |
| 1677 | return; |
| 1678 | } |
| 1679 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1680 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1683 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1684 | { |
| 1685 | struct nfs4_state *state = opendata->state; |
| 1686 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1687 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1688 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1689 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1690 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1691 | nfs4_stateid stateid; |
| 1692 | int ret = -EAGAIN; |
| 1693 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1694 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1695 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1696 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1697 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1698 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1699 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1700 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1701 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1702 | rcu_read_lock(); |
| 1703 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1704 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1705 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1706 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1707 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1708 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1709 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1710 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1711 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1712 | if (!opendata->is_recover) { |
| 1713 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1714 | if (ret != 0) |
| 1715 | goto out; |
| 1716 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1717 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1718 | |
| 1719 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1720 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1721 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1722 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1723 | out: |
| 1724 | return ERR_PTR(ret); |
| 1725 | out_return_state: |
| 1726 | atomic_inc(&state->count); |
| 1727 | return state; |
| 1728 | } |
| 1729 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1730 | static void |
| 1731 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1732 | { |
| 1733 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1734 | struct nfs_delegation *delegation; |
| 1735 | int delegation_flags = 0; |
| 1736 | |
| 1737 | rcu_read_lock(); |
| 1738 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1739 | if (delegation) |
| 1740 | delegation_flags = delegation->flags; |
| 1741 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1742 | switch (data->o_arg.claim) { |
| 1743 | default: |
| 1744 | break; |
| 1745 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1746 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1747 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1748 | "returning a delegation for " |
| 1749 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1750 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1751 | return; |
| 1752 | } |
| 1753 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1754 | nfs_inode_set_delegation(state->inode, |
| 1755 | data->owner->so_cred, |
| 1756 | &data->o_res); |
| 1757 | else |
| 1758 | nfs_inode_reclaim_delegation(state->inode, |
| 1759 | data->owner->so_cred, |
| 1760 | &data->o_res); |
| 1761 | } |
| 1762 | |
| 1763 | /* |
| 1764 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1765 | * and update the nfs4_state. |
| 1766 | */ |
| 1767 | static struct nfs4_state * |
| 1768 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1769 | { |
| 1770 | struct inode *inode = data->state->inode; |
| 1771 | struct nfs4_state *state = data->state; |
| 1772 | int ret; |
| 1773 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1774 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1775 | if (data->rpc_status) |
| 1776 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1777 | /* cached opens have already been processed */ |
| 1778 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1781 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1782 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1783 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1784 | |
| 1785 | if (data->o_res.delegation_type != 0) |
| 1786 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1787 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1788 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1789 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1790 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1791 | |
| 1792 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Trond Myklebust | 4e2fcac | 2017-08-08 09:06:18 -0400 | [diff] [blame] | 1795 | static struct inode * |
| 1796 | nfs4_opendata_get_inode(struct nfs4_opendata *data) |
| 1797 | { |
| 1798 | struct inode *inode; |
| 1799 | |
| 1800 | switch (data->o_arg.claim) { |
| 1801 | case NFS4_OPEN_CLAIM_NULL: |
| 1802 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1803 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1804 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
| 1805 | return ERR_PTR(-EAGAIN); |
| 1806 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, |
| 1807 | &data->f_attr, data->f_label); |
| 1808 | break; |
| 1809 | default: |
| 1810 | inode = d_inode(data->dentry); |
| 1811 | ihold(inode); |
| 1812 | nfs_refresh_inode(inode, &data->f_attr); |
| 1813 | } |
| 1814 | return inode; |
| 1815 | } |
| 1816 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1817 | static struct nfs4_state * |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1818 | nfs4_opendata_find_nfs4_state(struct nfs4_opendata *data) |
| 1819 | { |
| 1820 | struct nfs4_state *state; |
| 1821 | struct inode *inode; |
| 1822 | |
| 1823 | inode = nfs4_opendata_get_inode(data); |
| 1824 | if (IS_ERR(inode)) |
| 1825 | return ERR_CAST(inode); |
| 1826 | if (data->state != NULL && data->state->inode == inode) { |
| 1827 | state = data->state; |
| 1828 | atomic_inc(&state->count); |
| 1829 | } else |
| 1830 | state = nfs4_get_open_state(inode, data->owner); |
| 1831 | iput(inode); |
| 1832 | if (state == NULL) |
| 1833 | state = ERR_PTR(-ENOMEM); |
| 1834 | return state; |
| 1835 | } |
| 1836 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1837 | static struct nfs4_state * |
| 1838 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1839 | { |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1840 | struct nfs4_state *state; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1841 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1842 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1843 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1844 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1845 | goto out; |
| 1846 | } |
| 1847 | |
Trond Myklebust | 75e8c48 | 2017-08-08 10:38:07 -0400 | [diff] [blame] | 1848 | state = nfs4_opendata_find_nfs4_state(data); |
| 1849 | if (IS_ERR(state)) |
| 1850 | goto out; |
| 1851 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1852 | if (data->o_res.delegation_type != 0) |
| 1853 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1854 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1855 | data->o_arg.fmode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1856 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1857 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1858 | return state; |
| 1859 | } |
| 1860 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1861 | static struct nfs4_state * |
| 1862 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1863 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1864 | struct nfs4_state *ret; |
| 1865 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1866 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1867 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1868 | else |
| 1869 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1870 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1871 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1872 | } |
| 1873 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1874 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1875 | { |
| 1876 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1877 | struct nfs_open_context *ctx; |
| 1878 | |
| 1879 | spin_lock(&state->inode->i_lock); |
| 1880 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1881 | if (ctx->state != state) |
| 1882 | continue; |
| 1883 | get_nfs_open_context(ctx); |
| 1884 | spin_unlock(&state->inode->i_lock); |
| 1885 | return ctx; |
| 1886 | } |
| 1887 | spin_unlock(&state->inode->i_lock); |
| 1888 | return ERR_PTR(-ENOENT); |
| 1889 | } |
| 1890 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1891 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1892 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1893 | { |
| 1894 | struct nfs4_opendata *opendata; |
| 1895 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1896 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 1897 | NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1898 | if (opendata == NULL) |
| 1899 | return ERR_PTR(-ENOMEM); |
| 1900 | opendata->state = state; |
| 1901 | atomic_inc(&state->count); |
| 1902 | return opendata; |
| 1903 | } |
| 1904 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1905 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1906 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1907 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1908 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1909 | int ret; |
| 1910 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1911 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1912 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1913 | opendata->o_arg.open_flags = 0; |
| 1914 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1915 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1916 | NFS_SB(opendata->dentry->d_sb), |
| 1917 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1918 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1919 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1920 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1921 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1922 | if (ret != 0) |
| 1923 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1924 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1925 | if (IS_ERR(newstate)) |
| 1926 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1927 | if (newstate != opendata->state) |
| 1928 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1929 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1930 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1934 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1935 | int ret; |
| 1936 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1937 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1938 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1939 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1940 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1941 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1942 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1943 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1944 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1945 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1946 | if (ret != 0) |
| 1947 | return ret; |
| 1948 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1949 | if (ret != 0) |
| 1950 | return ret; |
| 1951 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1952 | if (ret != 0) |
| 1953 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1954 | /* |
| 1955 | * We may have performed cached opens for all three recoveries. |
| 1956 | * Check if we need to update the current stateid. |
| 1957 | */ |
| 1958 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1959 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1960 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1961 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1962 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1963 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1964 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1965 | return 0; |
| 1966 | } |
| 1967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | /* |
| 1969 | * OPEN_RECLAIM: |
| 1970 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1972 | 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] | 1973 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1974 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1975 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1976 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | int status; |
| 1978 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1979 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1980 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1981 | if (IS_ERR(opendata)) |
| 1982 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1983 | rcu_read_lock(); |
| 1984 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1985 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1986 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1987 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1988 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1989 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1990 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | return status; |
| 1992 | } |
| 1993 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1994 | 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] | 1995 | { |
| 1996 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1997 | struct nfs4_exception exception = { }; |
| 1998 | int err; |
| 1999 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2000 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2001 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2002 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2003 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 2004 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | } while (exception.retry); |
| 2008 | return err; |
| 2009 | } |
| 2010 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2011 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2012 | { |
| 2013 | struct nfs_open_context *ctx; |
| 2014 | int ret; |
| 2015 | |
| 2016 | ctx = nfs4_state_find_open_context(state); |
| 2017 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2018 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2019 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2020 | put_nfs_open_context(ctx); |
| 2021 | return ret; |
| 2022 | } |
| 2023 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2024 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2026 | switch (err) { |
| 2027 | default: |
| 2028 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 2029 | "%d.\n", __func__, err); |
| 2030 | case 0: |
| 2031 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 2032 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2033 | case -ESTALE: |
| 2034 | break; |
| 2035 | case -NFS4ERR_BADSESSION: |
| 2036 | case -NFS4ERR_BADSLOT: |
| 2037 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 2038 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 2039 | case -NFS4ERR_DEADSESSION: |
| 2040 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2041 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 2042 | return -EAGAIN; |
| 2043 | case -NFS4ERR_STALE_CLIENTID: |
| 2044 | case -NFS4ERR_STALE_STATEID: |
| 2045 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2046 | /* Don't recall a delegation if it was lost */ |
| 2047 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 2048 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 2049 | case -NFS4ERR_MOVED: |
| 2050 | nfs4_schedule_migration_recovery(server); |
| 2051 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 2052 | case -NFS4ERR_LEASE_MOVED: |
| 2053 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 2054 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2055 | case -NFS4ERR_DELEG_REVOKED: |
| 2056 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 2057 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2058 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2059 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2060 | nfs_inode_find_state_and_recover(state->inode, |
| 2061 | stateid); |
| 2062 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 2063 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2064 | case -NFS4ERR_DELAY: |
| 2065 | case -NFS4ERR_GRACE: |
| 2066 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2067 | ssleep(1); |
| 2068 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2069 | case -ENOMEM: |
| 2070 | case -NFS4ERR_DENIED: |
| 2071 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 2072 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | return err; |
| 2075 | } |
| 2076 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2077 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2078 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2079 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2080 | { |
| 2081 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2082 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2083 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2084 | |
| 2085 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2086 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2087 | if (IS_ERR(opendata)) |
| 2088 | return PTR_ERR(opendata); |
| 2089 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2090 | write_seqlock(&state->seqlock); |
| 2091 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2092 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2093 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2094 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2095 | case FMODE_READ|FMODE_WRITE: |
| 2096 | case FMODE_WRITE: |
| 2097 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2098 | if (err) |
| 2099 | break; |
| 2100 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2101 | if (err) |
| 2102 | break; |
| 2103 | case FMODE_READ: |
| 2104 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2105 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2106 | nfs4_opendata_put(opendata); |
| 2107 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2108 | } |
| 2109 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2110 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2111 | { |
| 2112 | struct nfs4_opendata *data = calldata; |
| 2113 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 2114 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 2115 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2116 | } |
| 2117 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2118 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2119 | { |
| 2120 | struct nfs4_opendata *data = calldata; |
| 2121 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2122 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2123 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2124 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2125 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2126 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2127 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2128 | renew_lease(data->o_res.server, data->timestamp); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2129 | data->rpc_done = true; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2130 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static void nfs4_open_confirm_release(void *calldata) |
| 2134 | { |
| 2135 | struct nfs4_opendata *data = calldata; |
| 2136 | struct nfs4_state *state = NULL; |
| 2137 | |
| 2138 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2139 | if (!data->cancelled) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2140 | goto out_free; |
| 2141 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2142 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2143 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2144 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2145 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2146 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2147 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2148 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2152 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2153 | .rpc_call_done = nfs4_open_confirm_done, |
| 2154 | .rpc_release = nfs4_open_confirm_release, |
| 2155 | }; |
| 2156 | |
| 2157 | /* |
| 2158 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2159 | */ |
| 2160 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2161 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2162 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2163 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2164 | struct rpc_message msg = { |
| 2165 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2166 | .rpc_argp = &data->c_arg, |
| 2167 | .rpc_resp = &data->c_res, |
| 2168 | .rpc_cred = data->owner->so_cred, |
| 2169 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2170 | struct rpc_task_setup task_setup_data = { |
| 2171 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2172 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2173 | .callback_ops = &nfs4_open_confirm_ops, |
| 2174 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2175 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2176 | .flags = RPC_TASK_ASYNC, |
| 2177 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | int status; |
| 2179 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2180 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2181 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2182 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2183 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2184 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2185 | if (data->is_recover) |
| 2186 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2187 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2188 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2189 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2190 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2191 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2192 | data->cancelled = true; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2193 | smp_wmb(); |
| 2194 | } else |
| 2195 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2196 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | return status; |
| 2198 | } |
| 2199 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2200 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2202 | struct nfs4_opendata *data = calldata; |
| 2203 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2204 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2205 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2206 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2207 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2208 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2209 | /* |
| 2210 | * Check if we still need to send an OPEN call, or if we can use |
| 2211 | * a delegation instead. |
| 2212 | */ |
| 2213 | if (data->state != NULL) { |
| 2214 | struct nfs_delegation *delegation; |
| 2215 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2216 | 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] | 2217 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2218 | rcu_read_lock(); |
| 2219 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2220 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2221 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2222 | rcu_read_unlock(); |
| 2223 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2224 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2225 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2226 | switch (claim) { |
| 2227 | default: |
| 2228 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2229 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2230 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2231 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2232 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2233 | case NFS4_OPEN_CLAIM_FH: |
| 2234 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2235 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2236 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2237 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2238 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2239 | &data->o_res.seq_res, |
| 2240 | task) != 0) |
| 2241 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2242 | |
| 2243 | /* Set the create mode (note dependency on the session type) */ |
| 2244 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2245 | if (data->o_arg.open_flags & O_EXCL) { |
| 2246 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2247 | if (nfs4_has_persistent_session(clp)) |
| 2248 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2249 | else if (clp->cl_mvops->minor_version > 0) |
| 2250 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2251 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2252 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2253 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2254 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2255 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2256 | out_no_action: |
| 2257 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2258 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2259 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2260 | } |
| 2261 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2262 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2263 | { |
| 2264 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2266 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2267 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2268 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2269 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2270 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2271 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2272 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2273 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2274 | case S_IFREG: |
| 2275 | break; |
| 2276 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2277 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2278 | break; |
| 2279 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2280 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2281 | break; |
| 2282 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2283 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2284 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2285 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2286 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2287 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2288 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2289 | } |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2290 | data->rpc_done = true; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2291 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2292 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2293 | static void nfs4_open_release(void *calldata) |
| 2294 | { |
| 2295 | struct nfs4_opendata *data = calldata; |
| 2296 | struct nfs4_state *state = NULL; |
| 2297 | |
| 2298 | /* If this request hasn't been cancelled, do nothing */ |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2299 | if (!data->cancelled) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2300 | goto out_free; |
| 2301 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2302 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2303 | goto out_free; |
| 2304 | /* In case we need an open_confirm, no cleanup! */ |
| 2305 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2306 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2307 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2308 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2309 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2310 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2311 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2315 | .rpc_call_prepare = nfs4_open_prepare, |
| 2316 | .rpc_call_done = nfs4_open_done, |
| 2317 | .rpc_release = nfs4_open_release, |
| 2318 | }; |
| 2319 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2320 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2321 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2322 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2323 | struct nfs_server *server = NFS_SERVER(dir); |
| 2324 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2325 | struct nfs_openres *o_res = &data->o_res; |
| 2326 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2327 | struct rpc_message msg = { |
| 2328 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2329 | .rpc_argp = o_arg, |
| 2330 | .rpc_resp = o_res, |
| 2331 | .rpc_cred = data->owner->so_cred, |
| 2332 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2333 | struct rpc_task_setup task_setup_data = { |
| 2334 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2335 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2336 | .callback_ops = &nfs4_open_ops, |
| 2337 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2338 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2339 | .flags = RPC_TASK_ASYNC, |
| 2340 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2341 | int status; |
| 2342 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2343 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2344 | kref_get(&data->kref); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2345 | data->rpc_done = false; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2346 | data->rpc_status = 0; |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2347 | data->cancelled = false; |
| 2348 | data->is_recover = false; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2349 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2350 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2351 | data->is_recover = true; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2352 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2353 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2354 | if (IS_ERR(task)) |
| 2355 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2356 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2357 | if (status != 0) { |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2358 | data->cancelled = true; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2359 | smp_wmb(); |
| 2360 | } else |
| 2361 | status = data->rpc_status; |
| 2362 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2363 | |
| 2364 | return status; |
| 2365 | } |
| 2366 | |
| 2367 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2368 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2369 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2370 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2371 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2372 | |
| 2373 | status = nfs4_run_open_task(data, 1); |
| 2374 | if (status != 0 || !data->rpc_done) |
| 2375 | return status; |
| 2376 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2377 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2378 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2379 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2380 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2381 | |
| 2382 | return status; |
| 2383 | } |
| 2384 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2385 | /* |
| 2386 | * Additional permission checks in order to distinguish between an |
| 2387 | * open for read, and an open for execute. This works around the |
| 2388 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2389 | * the same. |
| 2390 | * Note that in the non-execute case, we want to turn off permission |
| 2391 | * checking if we just created a new file (POSIX open() semantics). |
| 2392 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2393 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2394 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2395 | struct nfs4_state *state, fmode_t fmode, |
| 2396 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2397 | { |
| 2398 | struct nfs_access_entry cache; |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2399 | u32 mask, flags; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2400 | |
| 2401 | /* access call failed or for some reason the server doesn't |
| 2402 | * support any access modes -- defer access call until later */ |
| 2403 | if (opendata->o_res.access_supported == 0) |
| 2404 | return 0; |
| 2405 | |
| 2406 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2407 | /* |
| 2408 | * Use openflags to check for exec, because fmode won't |
| 2409 | * always have FMODE_EXEC set when file open for exec. |
| 2410 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2411 | if (openflags & __FMODE_EXEC) { |
| 2412 | /* ONLY check for exec rights */ |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2413 | if (S_ISDIR(state->inode->i_mode)) |
| 2414 | mask = NFS4_ACCESS_LOOKUP; |
| 2415 | else |
| 2416 | mask = NFS4_ACCESS_EXECUTE; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2417 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2418 | mask = NFS4_ACCESS_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2419 | |
| 2420 | cache.cred = cred; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2421 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2422 | nfs_access_add_cache(state->inode, &cache); |
| 2423 | |
Anna Schumaker | 1e6f209 | 2017-07-25 16:10:47 -0400 | [diff] [blame] | 2424 | flags = NFS4_ACCESS_READ | NFS4_ACCESS_EXECUTE | NFS4_ACCESS_LOOKUP; |
| 2425 | if ((mask & ~cache.mask & flags) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2426 | return 0; |
| 2427 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2428 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2429 | } |
| 2430 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2431 | /* |
| 2432 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2433 | */ |
| 2434 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2435 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2436 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2437 | struct nfs_server *server = NFS_SERVER(dir); |
| 2438 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2439 | struct nfs_openres *o_res = &data->o_res; |
| 2440 | int status; |
| 2441 | |
| 2442 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2443 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2444 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2445 | if (status != 0) { |
| 2446 | if (status == -NFS4ERR_BADNAME && |
| 2447 | !(o_arg->open_flags & O_CREAT)) |
| 2448 | return -ENOENT; |
| 2449 | return status; |
| 2450 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2451 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2452 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2453 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2454 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2455 | if (o_arg->open_flags & O_EXCL) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2456 | data->file_created = true; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2457 | else if (o_res->cinfo.before != o_res->cinfo.after) |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 2458 | data->file_created = true; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2459 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2460 | update_changeattr(dir, &o_res->cinfo, |
| 2461 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2462 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2463 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2464 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2466 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2468 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2470 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2471 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2472 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2473 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2474 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | /* |
| 2478 | * OPEN_EXPIRED: |
| 2479 | * reclaim state on the server after a network partition. |
| 2480 | * Assumes caller holds the appropriate lock |
| 2481 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2482 | 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] | 2483 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2484 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2485 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2487 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2488 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2489 | if (IS_ERR(opendata)) |
| 2490 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2491 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2492 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2493 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2494 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2495 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2498 | 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] | 2499 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2500 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2501 | struct nfs4_exception exception = { }; |
| 2502 | int err; |
| 2503 | |
| 2504 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2505 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2506 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2507 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2508 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2509 | switch (err) { |
| 2510 | default: |
| 2511 | goto out; |
| 2512 | case -NFS4ERR_GRACE: |
| 2513 | case -NFS4ERR_DELAY: |
| 2514 | nfs4_handle_exception(server, err, &exception); |
| 2515 | err = 0; |
| 2516 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2517 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2518 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2519 | return err; |
| 2520 | } |
| 2521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2523 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2525 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2527 | ctx = nfs4_state_find_open_context(state); |
| 2528 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2529 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2530 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2531 | put_nfs_open_context(ctx); |
| 2532 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2535 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2536 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2537 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2538 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2539 | write_seqlock(&state->seqlock); |
| 2540 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2541 | write_sequnlock(&state->seqlock); |
| 2542 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2543 | } |
| 2544 | |
| 2545 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2546 | { |
| 2547 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2548 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2552 | { |
| 2553 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2554 | nfs40_clear_delegation_stateid(state); |
| 2555 | return nfs4_open_expired(sp, state); |
| 2556 | } |
| 2557 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2558 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2559 | nfs4_stateid *stateid, |
| 2560 | struct rpc_cred *cred) |
| 2561 | { |
| 2562 | return -NFS4ERR_BAD_STATEID; |
| 2563 | } |
| 2564 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2565 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2566 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2567 | nfs4_stateid *stateid, |
| 2568 | struct rpc_cred *cred) |
| 2569 | { |
| 2570 | int status; |
| 2571 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2572 | switch (stateid->type) { |
| 2573 | default: |
| 2574 | break; |
| 2575 | case NFS4_INVALID_STATEID_TYPE: |
| 2576 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2577 | return -NFS4ERR_BAD_STATEID; |
| 2578 | case NFS4_REVOKED_STATEID_TYPE: |
| 2579 | goto out_free; |
| 2580 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2581 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2582 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2583 | switch (status) { |
| 2584 | case -NFS4ERR_EXPIRED: |
| 2585 | case -NFS4ERR_ADMIN_REVOKED: |
| 2586 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2587 | break; |
| 2588 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2589 | return status; |
| 2590 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2591 | out_free: |
| 2592 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2593 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2594 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2595 | } |
| 2596 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2597 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2598 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2599 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2600 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2601 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2602 | struct rpc_cred *cred; |
| 2603 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2604 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2605 | /* Get the delegation credential for use by test/free_stateid */ |
| 2606 | rcu_read_lock(); |
| 2607 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2608 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2609 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2610 | return; |
| 2611 | } |
| 2612 | |
| 2613 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2614 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2615 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2616 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2617 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2618 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2619 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2620 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2621 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2622 | cred = get_rpccred(delegation->cred); |
| 2623 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2624 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2625 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2626 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2627 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2628 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2629 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2633 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2634 | * |
| 2635 | * @state: NFSv4 state for an inode |
| 2636 | * |
| 2637 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2638 | * Otherwise a negative NFS4ERR value is returned. |
| 2639 | */ |
| 2640 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2641 | { |
| 2642 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2643 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2644 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2645 | |
| 2646 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2647 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2648 | |
| 2649 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2650 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2651 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2652 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2653 | |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 2654 | refcount_inc(&lsp->ls_count); |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2655 | spin_unlock(&state->state_lock); |
| 2656 | |
| 2657 | nfs4_put_lock_state(prev); |
| 2658 | prev = lsp; |
| 2659 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2660 | status = nfs41_test_and_free_expired_stateid(server, |
| 2661 | &lsp->ls_stateid, |
| 2662 | cred); |
| 2663 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2664 | if (status == -NFS4ERR_EXPIRED || |
| 2665 | status == -NFS4ERR_BAD_STATEID) { |
| 2666 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2667 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2668 | if (!recover_lost_locks) |
| 2669 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2670 | } else if (status != NFS_OK) { |
| 2671 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2672 | nfs4_put_lock_state(prev); |
| 2673 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2674 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2675 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2676 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2677 | } |
| 2678 | spin_unlock(&state->state_lock); |
| 2679 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2680 | out: |
| 2681 | return ret; |
| 2682 | } |
| 2683 | |
| 2684 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2685 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2686 | * |
| 2687 | * @state: NFSv4 state for an inode |
| 2688 | * |
| 2689 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2690 | * Otherwise a negative NFS4ERR value is returned. |
| 2691 | */ |
| 2692 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2693 | { |
| 2694 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2695 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2696 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2697 | int status; |
| 2698 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2699 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2700 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2701 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2702 | return NFS_OK; |
| 2703 | return -NFS4ERR_OPENMODE; |
| 2704 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2705 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2706 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2707 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2708 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2709 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2710 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2711 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2712 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2713 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2714 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2715 | return status; |
Trond Myklebust | c0ca0e5 | 2017-08-08 21:39:28 -0400 | [diff] [blame] | 2716 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2717 | if (nfs_open_stateid_recover_openmode(state)) |
| 2718 | return -NFS4ERR_OPENMODE; |
| 2719 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2723 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2724 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2725 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2726 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2727 | status = nfs41_check_expired_locks(state); |
| 2728 | if (status != NFS_OK) |
| 2729 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2730 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2731 | if (status != NFS_OK) |
| 2732 | status = nfs4_open_expired(sp, state); |
| 2733 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2734 | } |
| 2735 | #endif |
| 2736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2738 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2739 | * fields corresponding to attributes that were used to store the verifier. |
| 2740 | * Make sure we clobber those fields in the later setattr call |
| 2741 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2742 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2743 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2744 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2745 | const u32 *attrset = opendata->o_res.attrset; |
| 2746 | |
| 2747 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2748 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2749 | sattr->ia_valid |= ATTR_ATIME; |
| 2750 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2751 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2752 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2753 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2754 | |
| 2755 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2756 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
Benjamin Coddington | 501e7a4 | 2017-06-02 11:21:34 -0400 | [diff] [blame] | 2757 | (attrset[1] & FATTR4_WORD1_MODE || |
| 2758 | attrset[2] & FATTR4_WORD2_MODE_UMASK)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2759 | sattr->ia_valid &= ~ATTR_MODE; |
| 2760 | |
| 2761 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2762 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2763 | } |
| 2764 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2765 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2766 | fmode_t fmode, |
| 2767 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2768 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2769 | { |
| 2770 | struct nfs4_state_owner *sp = opendata->owner; |
| 2771 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2772 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2773 | struct nfs4_state *state; |
| 2774 | unsigned int seq; |
| 2775 | int ret; |
| 2776 | |
| 2777 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2778 | |
| 2779 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2780 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2781 | goto out; |
| 2782 | |
| 2783 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2784 | ret = PTR_ERR(state); |
| 2785 | if (IS_ERR(state)) |
| 2786 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2787 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2788 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2789 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2790 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2791 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2792 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2793 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2794 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2795 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2796 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2797 | alias = d_exact_alias(dentry, state->inode); |
| 2798 | if (!alias) |
| 2799 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2800 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2801 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2802 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2803 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2804 | } |
| 2805 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2806 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2809 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2810 | if (ret != 0) |
| 2811 | goto out; |
| 2812 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2813 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2814 | nfs_inode_attach_open_context(ctx); |
| 2815 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2816 | nfs4_schedule_stateid_recovery(server, state); |
| 2817 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2818 | out: |
| 2819 | return ret; |
| 2820 | } |
| 2821 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2822 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2823 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2825 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2826 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2827 | int flags, |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2828 | const struct nfs4_open_createattrs *c, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2829 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | { |
| 2831 | struct nfs4_state_owner *sp; |
| 2832 | struct nfs4_state *state = NULL; |
| 2833 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2834 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2835 | struct dentry *dentry = ctx->dentry; |
| 2836 | struct rpc_cred *cred = ctx->cred; |
| 2837 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2838 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2839 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2840 | struct iattr *sattr = c->sattr; |
| 2841 | struct nfs4_label *label = c->label; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2842 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2843 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
| 2845 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2847 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2848 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2850 | goto out_err; |
| 2851 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2852 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2853 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2854 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2855 | if (d_really_is_positive(dentry)) |
| 2856 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2857 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2858 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2859 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2860 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, |
| 2861 | c, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2862 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2863 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2865 | if (label) { |
| 2866 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2867 | if (IS_ERR(olabel)) { |
| 2868 | status = PTR_ERR(olabel); |
| 2869 | goto err_opendata_put; |
| 2870 | } |
| 2871 | } |
| 2872 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2873 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2874 | if (!opendata->f_attr.mdsthreshold) { |
| 2875 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2876 | if (!opendata->f_attr.mdsthreshold) |
| 2877 | goto err_free_label; |
| 2878 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2879 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2880 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2881 | if (d_really_is_positive(dentry)) |
| 2882 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2883 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2884 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2885 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2886 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2887 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2888 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2889 | 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] | 2890 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2891 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2892 | /* |
| 2893 | * send create attributes which was not set by open |
| 2894 | * with an extra setattr. |
| 2895 | */ |
| 2896 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2897 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2898 | status = nfs4_do_setattr(state->inode, cred, |
| 2899 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2900 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2901 | if (status == 0) { |
| 2902 | nfs_setattr_update_inode(state->inode, sattr, |
| 2903 | opendata->o_res.f_attr); |
| 2904 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2905 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2906 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2907 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2908 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2909 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2910 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2911 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2912 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2913 | opendata->f_attr.mdsthreshold = NULL; |
| 2914 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2915 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2916 | nfs4_label_free(olabel); |
| 2917 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2918 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2921 | err_free_label: |
| 2922 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2923 | err_opendata_put: |
| 2924 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2925 | err_put_state_owner: |
| 2926 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | return status; |
| 2929 | } |
| 2930 | |
| 2931 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2932 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2933 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2934 | int flags, |
| 2935 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2936 | struct nfs4_label *label, |
| 2937 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2939 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | struct nfs4_exception exception = { }; |
| 2941 | struct nfs4_state *res; |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2942 | struct nfs4_open_createattrs c = { |
| 2943 | .label = label, |
| 2944 | .sattr = sattr, |
| 2945 | .verf = { |
| 2946 | [0] = (__u32)jiffies, |
| 2947 | [1] = (__u32)current->pid, |
| 2948 | }, |
| 2949 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | int status; |
| 2951 | |
| 2952 | do { |
Trond Myklebust | 8fd1ab7 | 2017-11-06 15:28:03 -0500 | [diff] [blame] | 2953 | status = _nfs4_do_open(dir, ctx, flags, &c, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2954 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2955 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | if (status == 0) |
| 2957 | break; |
| 2958 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2959 | * book-keeping w.r.t. state-changing operations |
| 2960 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2961 | * It is actually a sign of a bug on the client or on the server. |
| 2962 | * |
| 2963 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2964 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | * have unhashed the old state_owner for us, and that we can |
| 2966 | * therefore safely retry using a new one. We should still warn |
| 2967 | * the user though... |
| 2968 | */ |
| 2969 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2970 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2971 | " returned a bad sequence-id error!\n", |
| 2972 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | exception.retry = 1; |
| 2974 | continue; |
| 2975 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2976 | /* |
| 2977 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2978 | * state before it received the OPEN_CONFIRM. |
| 2979 | * Recover by retrying the request as per the discussion |
| 2980 | * on Page 181 of RFC3530. |
| 2981 | */ |
| 2982 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2983 | exception.retry = 1; |
| 2984 | continue; |
| 2985 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2986 | if (status == -EAGAIN) { |
| 2987 | /* We must have found a delegation */ |
| 2988 | exception.retry = 1; |
| 2989 | continue; |
| 2990 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2991 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2992 | continue; |
| 2993 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | status, &exception)); |
| 2995 | } while (exception.retry); |
| 2996 | return res; |
| 2997 | } |
| 2998 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2999 | static int _nfs4_do_setattr(struct inode *inode, |
| 3000 | struct nfs_setattrargs *arg, |
| 3001 | struct nfs_setattrres *res, |
| 3002 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3003 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3004 | { |
| 3005 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3006 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 3008 | .rpc_argp = arg, |
| 3009 | .rpc_resp = res, |
| 3010 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3011 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3012 | struct rpc_cred *delegation_cred = NULL; |
| 3013 | unsigned long timestamp = jiffies; |
| 3014 | fmode_t fmode; |
| 3015 | bool truncate; |
| 3016 | int status; |
| 3017 | |
| 3018 | nfs_fattr_init(res->fattr); |
| 3019 | |
| 3020 | /* Servers should only apply open mode checks for file size changes */ |
| 3021 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 3022 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 3023 | |
| 3024 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 3025 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3026 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3027 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3028 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3029 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3030 | l_ctx = nfs_get_lock_context(ctx); |
| 3031 | if (IS_ERR(l_ctx)) |
| 3032 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 3033 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 3034 | &arg->stateid, &delegation_cred); |
| 3035 | nfs_put_lock_context(l_ctx); |
| 3036 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3037 | return -EBADF; |
| 3038 | } else |
| 3039 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 3040 | if (delegation_cred) |
| 3041 | msg.rpc_cred = delegation_cred; |
| 3042 | |
| 3043 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 3044 | |
| 3045 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3046 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3047 | renew_lease(server, timestamp); |
| 3048 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 3049 | return status; |
| 3050 | } |
| 3051 | |
| 3052 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 3053 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3054 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3055 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 3057 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3058 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3059 | struct nfs_setattrargs arg = { |
| 3060 | .fh = NFS_FH(inode), |
| 3061 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | .server = server, |
| 3063 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3064 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3065 | }; |
| 3066 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3068 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3070 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3071 | struct nfs4_exception exception = { |
| 3072 | .state = state, |
| 3073 | .inode = inode, |
| 3074 | .stateid = &arg.stateid, |
| 3075 | }; |
| 3076 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3078 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3079 | if (ilabel) |
| 3080 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3083 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3084 | switch (err) { |
| 3085 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3086 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3087 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3088 | "applying open mode checks to " |
| 3089 | "a SETATTR that is not " |
| 3090 | "changing file size.\n", |
| 3091 | server->nfs_client->cl_hostname); |
| 3092 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3093 | if (state && !(state->state & FMODE_WRITE)) { |
| 3094 | err = -EBADF; |
| 3095 | if (sattr->ia_valid & ATTR_OPEN) |
| 3096 | err = -EACCES; |
| 3097 | goto out; |
| 3098 | } |
| 3099 | } |
| 3100 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3102 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | return err; |
| 3104 | } |
| 3105 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3106 | static bool |
| 3107 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3108 | { |
| 3109 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3110 | return false; |
| 3111 | |
| 3112 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3113 | } |
| 3114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | struct nfs4_closedata { |
| 3116 | struct inode *inode; |
| 3117 | struct nfs4_state *state; |
| 3118 | struct nfs_closeargs arg; |
| 3119 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3120 | struct { |
| 3121 | struct nfs4_layoutreturn_args arg; |
| 3122 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3123 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3124 | u32 roc_barrier; |
| 3125 | bool roc; |
| 3126 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3127 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3128 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | }; |
| 3130 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3131 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3132 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3133 | struct nfs4_closedata *calldata = data; |
| 3134 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3135 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3136 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3137 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3138 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3139 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3140 | nfs4_put_open_state(calldata->state); |
| 3141 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3142 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3143 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3144 | kfree(calldata); |
| 3145 | } |
| 3146 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3147 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3149 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3152 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3154 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3155 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3156 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3157 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3158 | |
| 3159 | /* Handle Layoutreturn errors */ |
| 3160 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3161 | switch (calldata->res.lr_ret) { |
| 3162 | default: |
| 3163 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3164 | break; |
| 3165 | case 0: |
| 3166 | calldata->arg.lr_args = NULL; |
| 3167 | calldata->res.lr_res = NULL; |
| 3168 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3169 | case -NFS4ERR_OLD_STATEID: |
| 3170 | if (nfs4_refresh_layout_stateid(&calldata->arg.lr_args->stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3171 | calldata->inode)) |
| 3172 | goto lr_restart; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 3173 | /* Fallthrough */ |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3174 | case -NFS4ERR_ADMIN_REVOKED: |
| 3175 | case -NFS4ERR_DELEG_REVOKED: |
| 3176 | case -NFS4ERR_EXPIRED: |
| 3177 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3178 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3179 | case -NFS4ERR_WRONG_CRED: |
| 3180 | calldata->arg.lr_args = NULL; |
| 3181 | calldata->res.lr_res = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3182 | goto lr_restart; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3186 | /* 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] | 3187 | * the state_owner. we keep this around to process errors |
| 3188 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | switch (task->tk_status) { |
| 3190 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3191 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3192 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3193 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3194 | case -NFS4ERR_ACCESS: |
| 3195 | if (calldata->arg.bitmask != NULL) { |
| 3196 | calldata->arg.bitmask = NULL; |
| 3197 | calldata->res.fattr = NULL; |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3198 | goto out_restart; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3199 | |
| 3200 | } |
| 3201 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3202 | case -NFS4ERR_OLD_STATEID: |
| 3203 | /* Did we race with OPEN? */ |
| 3204 | if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3205 | state)) |
| 3206 | goto out_restart; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3207 | goto out_release; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3208 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3210 | case -NFS4ERR_EXPIRED: |
| 3211 | nfs4_free_revoked_stateid(server, |
| 3212 | &calldata->arg.stateid, |
| 3213 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 3214 | /* Fallthrough */ |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3215 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3216 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | default: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3218 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) |
| 3219 | goto out_restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3221 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3222 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3223 | out_release: |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3224 | task->tk_status = 0; |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3225 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3226 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3227 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Trond Myklebust | 91b30d2 | 2017-11-06 15:28:09 -0500 | [diff] [blame^] | 3228 | return; |
| 3229 | lr_restart: |
| 3230 | calldata->res.lr_ret = 0; |
| 3231 | out_restart: |
| 3232 | task->tk_status = 0; |
| 3233 | rpc_restart_call_prepare(task); |
| 3234 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3237 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3239 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3240 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3241 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3242 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3243 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3244 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3245 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3246 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3247 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3248 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3249 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3250 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3251 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3252 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3253 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3254 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3255 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3256 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3257 | if (state->n_rdonly == 0) |
| 3258 | call_close |= is_rdonly; |
| 3259 | else if (is_rdonly) |
| 3260 | calldata->arg.fmode |= FMODE_READ; |
| 3261 | if (state->n_wronly == 0) |
| 3262 | call_close |= is_wronly; |
| 3263 | else if (is_wronly) |
| 3264 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3265 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3266 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3267 | } else if (is_rdwr) |
| 3268 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3269 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3270 | if (!nfs4_valid_open_stateid(state) || |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3271 | !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3272 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3273 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3274 | |
| 3275 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3276 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3277 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3278 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3279 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3280 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3281 | nfs_release_seqid(calldata->arg.seqid); |
| 3282 | goto out_wait; |
| 3283 | } |
| 3284 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3285 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3286 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3287 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3288 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3289 | /* Close-to-open cache consistency revalidation */ |
| 3290 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3291 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3292 | else |
| 3293 | calldata->arg.bitmask = NULL; |
| 3294 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3295 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3296 | calldata->arg.share_access = |
| 3297 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3298 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3299 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3300 | if (calldata->res.fattr == NULL) |
| 3301 | calldata->arg.bitmask = NULL; |
| 3302 | else if (calldata->arg.bitmask == NULL) |
| 3303 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3304 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3305 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3306 | &calldata->arg.seq_args, |
| 3307 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3308 | task) != 0) |
| 3309 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3310 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3311 | return; |
| 3312 | out_no_action: |
| 3313 | task->tk_action = NULL; |
| 3314 | out_wait: |
| 3315 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3318 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3319 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3320 | .rpc_call_done = nfs4_close_done, |
| 3321 | .rpc_release = nfs4_free_closedata, |
| 3322 | }; |
| 3323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | /* |
| 3325 | * It is possible for data to be read/written from a mem-mapped file |
| 3326 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3327 | * This means that we can't safely call nfsv4 close on a file until |
| 3328 | * the inode is cleared. This in turn means that we are not good |
| 3329 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3330 | * share state even when we are done with one of the three share |
| 3331 | * stateid's in the inode. |
| 3332 | * |
| 3333 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3334 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3335 | 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] | 3336 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3337 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3338 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3340 | struct nfs4_state_owner *sp = state->owner; |
| 3341 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3342 | struct rpc_message msg = { |
| 3343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3344 | .rpc_cred = state->owner->so_cred, |
| 3345 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3346 | struct rpc_task_setup task_setup_data = { |
| 3347 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3348 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3349 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3350 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3351 | .flags = RPC_TASK_ASYNC, |
| 3352 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3353 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3355 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3356 | &task_setup_data.rpc_client, &msg); |
| 3357 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3358 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3360 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3361 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3362 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3364 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | c82bac6 | 2017-11-06 15:28:06 -0500 | [diff] [blame] | 3365 | if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) |
| 3366 | goto out_free_calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3368 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3369 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3370 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3371 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3372 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3373 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3374 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3375 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3376 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3377 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3378 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3379 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3380 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3381 | if (calldata->lr.roc) { |
| 3382 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3383 | calldata->res.lr_res = &calldata->lr.res; |
| 3384 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3385 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3386 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3387 | msg.rpc_argp = &calldata->arg; |
| 3388 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3389 | task_setup_data.callback_data = calldata; |
| 3390 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3391 | if (IS_ERR(task)) |
| 3392 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3393 | status = 0; |
| 3394 | if (wait) |
| 3395 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3396 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3397 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3398 | out_free_calldata: |
| 3399 | kfree(calldata); |
| 3400 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3401 | nfs4_put_open_state(state); |
| 3402 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3403 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3406 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3407 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3408 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3411 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3412 | |
| 3413 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3415 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3416 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3417 | |
| 3418 | nfs4_label_release_security(label); |
| 3419 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3420 | if (IS_ERR(state)) |
| 3421 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3422 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3425 | 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] | 3426 | { |
| 3427 | if (ctx->state == NULL) |
| 3428 | return; |
| 3429 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3430 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3431 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3432 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3435 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3436 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3437 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3440 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3441 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3442 | struct nfs4_server_caps_arg args = { |
| 3443 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3444 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3445 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | struct nfs4_server_caps_res res = {}; |
| 3447 | struct rpc_message msg = { |
| 3448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3449 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | .rpc_resp = &res, |
| 3451 | }; |
| 3452 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3453 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3455 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3456 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3457 | FATTR4_WORD0_LINK_SUPPORT | |
| 3458 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3459 | FATTR4_WORD0_ACLSUPPORT; |
| 3460 | if (minorversion) |
| 3461 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3462 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3463 | 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] | 3464 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3465 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3466 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3467 | case 0: |
| 3468 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3469 | res.attr_bitmask[2] = 0; |
| 3470 | break; |
| 3471 | case 1: |
| 3472 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3473 | break; |
| 3474 | case 2: |
| 3475 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3478 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3479 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3480 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3481 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3482 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3483 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3484 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3485 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | server->caps |= NFS_CAP_ACLS; |
| 3487 | if (res.has_links != 0) |
| 3488 | server->caps |= NFS_CAP_HARDLINKS; |
| 3489 | if (res.has_symlinks != 0) |
| 3490 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3491 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3492 | server->caps |= NFS_CAP_FILEID; |
| 3493 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3494 | server->caps |= NFS_CAP_MODE; |
| 3495 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3496 | server->caps |= NFS_CAP_NLINK; |
| 3497 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3498 | server->caps |= NFS_CAP_OWNER; |
| 3499 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3500 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3501 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3502 | server->caps |= NFS_CAP_ATIME; |
| 3503 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3504 | server->caps |= NFS_CAP_CTIME; |
| 3505 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3506 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3507 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3508 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3509 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3510 | #endif |
| 3511 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3512 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3513 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3514 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3515 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3516 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3517 | 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] | 3518 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3519 | |
| 3520 | /* Avoid a regression due to buggy server */ |
| 3521 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3522 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3523 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3524 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3527 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | return status; |
| 3531 | } |
| 3532 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3533 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | { |
| 3535 | struct nfs4_exception exception = { }; |
| 3536 | int err; |
| 3537 | do { |
| 3538 | err = nfs4_handle_exception(server, |
| 3539 | _nfs4_server_capabilities(server, fhandle), |
| 3540 | &exception); |
| 3541 | } while (exception.retry); |
| 3542 | return err; |
| 3543 | } |
| 3544 | |
| 3545 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3546 | struct nfs_fsinfo *info) |
| 3547 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3548 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3550 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | }; |
| 3552 | struct nfs4_lookup_res res = { |
| 3553 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3554 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | .fh = fhandle, |
| 3556 | }; |
| 3557 | struct rpc_message msg = { |
| 3558 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3559 | .rpc_argp = &args, |
| 3560 | .rpc_resp = &res, |
| 3561 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3562 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3563 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3564 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3565 | /* |
| 3566 | * Process the label in the upcoming getfattr |
| 3567 | */ |
| 3568 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3569 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3570 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3571 | 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] | 3572 | } |
| 3573 | |
| 3574 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3575 | struct nfs_fsinfo *info) |
| 3576 | { |
| 3577 | struct nfs4_exception exception = { }; |
| 3578 | int err; |
| 3579 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3580 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3581 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3582 | switch (err) { |
| 3583 | case 0: |
| 3584 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3585 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3586 | default: |
| 3587 | err = nfs4_handle_exception(server, err, &exception); |
| 3588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3590 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | return err; |
| 3592 | } |
| 3593 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3594 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3595 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3596 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3597 | struct rpc_auth_create_args auth_args = { |
| 3598 | .pseudoflavor = flavor, |
| 3599 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3600 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3601 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3602 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3603 | if (IS_ERR(auth)) |
| 3604 | return -EACCES; |
| 3605 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3606 | } |
| 3607 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3608 | /* |
| 3609 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3610 | * |
| 3611 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3612 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3613 | * |
| 3614 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3615 | * negative errno value. |
| 3616 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3617 | 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] | 3618 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3620 | /* Per 3530bis 15.33.5 */ |
| 3621 | static const rpc_authflavor_t flav_array[] = { |
| 3622 | RPC_AUTH_GSS_KRB5P, |
| 3623 | RPC_AUTH_GSS_KRB5I, |
| 3624 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3625 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3626 | RPC_AUTH_NULL, |
| 3627 | }; |
| 3628 | int status = -EPERM; |
| 3629 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3631 | if (server->auth_info.flavor_len > 0) { |
| 3632 | /* try each flavor specified by user */ |
| 3633 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3634 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3635 | server->auth_info.flavors[i]); |
| 3636 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3637 | continue; |
| 3638 | break; |
| 3639 | } |
| 3640 | } else { |
| 3641 | /* no flavors specified by user, try default list */ |
| 3642 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3643 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3644 | flav_array[i]); |
| 3645 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3646 | continue; |
| 3647 | break; |
| 3648 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3649 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3650 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3651 | /* |
| 3652 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3653 | * to access the mount. It could also mean that we tried to mount |
| 3654 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3655 | * existing mount programs don't handle -EACCES very well so it should |
| 3656 | * be mapped to -EPERM instead. |
| 3657 | */ |
| 3658 | if (status == -EACCES) |
| 3659 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3660 | return status; |
| 3661 | } |
| 3662 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3663 | /** |
| 3664 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3665 | * @server: initialized nfs_server handle |
| 3666 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3667 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3668 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3669 | * |
| 3670 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3671 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3672 | 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] | 3673 | struct nfs_fsinfo *info, |
| 3674 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3675 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3676 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3677 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3678 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3679 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3680 | |
| 3681 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3682 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3683 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | if (status == 0) |
| 3686 | status = nfs4_server_capabilities(server, fhandle); |
| 3687 | if (status == 0) |
| 3688 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3689 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3690 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3693 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3694 | struct nfs_fsinfo *info) |
| 3695 | { |
| 3696 | int error; |
| 3697 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3698 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3699 | |
| 3700 | error = nfs4_server_capabilities(server, mntfh); |
| 3701 | if (error < 0) { |
| 3702 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3703 | return error; |
| 3704 | } |
| 3705 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3706 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3707 | if (IS_ERR(label)) |
| 3708 | return PTR_ERR(label); |
| 3709 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3710 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3711 | if (error < 0) { |
| 3712 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3713 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3717 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3718 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3719 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3720 | err_free_label: |
| 3721 | nfs4_label_free(label); |
| 3722 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3723 | return error; |
| 3724 | } |
| 3725 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3726 | /* |
| 3727 | * Get locations and (maybe) other attributes of a referral. |
| 3728 | * Note that we'll actually follow the referral later when |
| 3729 | * we detect fsid mismatch in inode revalidation |
| 3730 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3731 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3732 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3733 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3734 | { |
| 3735 | int status = -ENOMEM; |
| 3736 | struct page *page = NULL; |
| 3737 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3738 | |
| 3739 | page = alloc_page(GFP_KERNEL); |
| 3740 | if (page == NULL) |
| 3741 | goto out; |
| 3742 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3743 | if (locations == NULL) |
| 3744 | goto out; |
| 3745 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3746 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3747 | if (status != 0) |
| 3748 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3749 | |
| 3750 | /* |
| 3751 | * If the fsid didn't change, this is a migration event, not a |
| 3752 | * referral. Cause us to drop into the exception handler, which |
| 3753 | * will kick off migration recovery. |
| 3754 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3755 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3756 | dprintk("%s: server did not return a different fsid for" |
| 3757 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3758 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3759 | goto out; |
| 3760 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3761 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3762 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3763 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3764 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3765 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3766 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3767 | out: |
| 3768 | if (page) |
| 3769 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3770 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3771 | return status; |
| 3772 | } |
| 3773 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3774 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3775 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | { |
| 3777 | struct nfs4_getattr_arg args = { |
| 3778 | .fh = fhandle, |
| 3779 | .bitmask = server->attr_bitmask, |
| 3780 | }; |
| 3781 | struct nfs4_getattr_res res = { |
| 3782 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3783 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | .server = server, |
| 3785 | }; |
| 3786 | struct rpc_message msg = { |
| 3787 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3788 | .rpc_argp = &args, |
| 3789 | .rpc_resp = &res, |
| 3790 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3791 | |
| 3792 | args.bitmask = nfs4_bitmask(server, label); |
| 3793 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3794 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3795 | 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] | 3796 | } |
| 3797 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3798 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3799 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | { |
| 3801 | struct nfs4_exception exception = { }; |
| 3802 | int err; |
| 3803 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3804 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3805 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3806 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | &exception); |
| 3808 | } while (exception.retry); |
| 3809 | return err; |
| 3810 | } |
| 3811 | |
| 3812 | /* |
| 3813 | * The file is not closed if it is opened due to the a request to change |
| 3814 | * the size of the file. The open call will not be needed once the |
| 3815 | * VFS layer lookup-intents are implemented. |
| 3816 | * |
| 3817 | * Close is called when the inode is destroyed. |
| 3818 | * If we haven't opened the file for O_WRONLY, we |
| 3819 | * need to in the size_change case to obtain a stateid. |
| 3820 | * |
| 3821 | * Got race? |
| 3822 | * Because OPEN is always done by name in nfsv4, it is |
| 3823 | * possible that we opened a different file by the same |
| 3824 | * name. We can recognize this race condition, but we |
| 3825 | * can't do anything about it besides returning an error. |
| 3826 | * |
| 3827 | * This will be fixed with VFS changes (lookup-intent). |
| 3828 | */ |
| 3829 | static int |
| 3830 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3831 | struct iattr *sattr) |
| 3832 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3833 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3834 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3835 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3836 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | int status; |
| 3838 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3839 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3840 | sattr->ia_valid & ATTR_SIZE && |
| 3841 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3842 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3843 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3844 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3846 | /* Deal with open(O_TRUNC) */ |
| 3847 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3848 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3849 | |
| 3850 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3851 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3852 | return 0; |
| 3853 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3854 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3855 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3856 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3857 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3858 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3859 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3860 | } |
| 3861 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3862 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3863 | if (IS_ERR(label)) |
| 3864 | return PTR_ERR(label); |
| 3865 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3866 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3867 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3868 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3869 | nfs_setsecurity(inode, fattr, label); |
| 3870 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3871 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | return status; |
| 3873 | } |
| 3874 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3875 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3876 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3877 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3878 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3879 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3880 | int status; |
| 3881 | struct nfs4_lookup_arg args = { |
| 3882 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3883 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3884 | .name = name, |
| 3885 | }; |
| 3886 | struct nfs4_lookup_res res = { |
| 3887 | .server = server, |
| 3888 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3889 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3890 | .fh = fhandle, |
| 3891 | }; |
| 3892 | struct rpc_message msg = { |
| 3893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3894 | .rpc_argp = &args, |
| 3895 | .rpc_resp = &res, |
| 3896 | }; |
| 3897 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3898 | args.bitmask = nfs4_bitmask(server, label); |
| 3899 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3900 | nfs_fattr_init(fattr); |
| 3901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3903 | 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] | 3904 | dprintk("NFS reply lookup: %d\n", status); |
| 3905 | return status; |
| 3906 | } |
| 3907 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3908 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3909 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3910 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3911 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3912 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3913 | fattr->nlink = 2; |
| 3914 | } |
| 3915 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3916 | 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] | 3917 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3918 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3919 | { |
| 3920 | struct nfs4_exception exception = { }; |
| 3921 | struct rpc_clnt *client = *clnt; |
| 3922 | int err; |
| 3923 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3924 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3925 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3926 | switch (err) { |
| 3927 | case -NFS4ERR_BADNAME: |
| 3928 | err = -ENOENT; |
| 3929 | goto out; |
| 3930 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3931 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3932 | if (err == -NFS4ERR_MOVED) |
| 3933 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3934 | goto out; |
| 3935 | case -NFS4ERR_WRONGSEC: |
| 3936 | err = -EPERM; |
| 3937 | if (client != *clnt) |
| 3938 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3939 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3940 | if (IS_ERR(client)) |
| 3941 | return PTR_ERR(client); |
| 3942 | |
| 3943 | exception.retry = 1; |
| 3944 | break; |
| 3945 | default: |
| 3946 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3947 | } |
| 3948 | } while (exception.retry); |
| 3949 | |
| 3950 | out: |
| 3951 | if (err == 0) |
| 3952 | *clnt = client; |
| 3953 | else if (client != *clnt) |
| 3954 | rpc_shutdown_client(client); |
| 3955 | |
| 3956 | return err; |
| 3957 | } |
| 3958 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3959 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3960 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3961 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3963 | int status; |
| 3964 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3965 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3966 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3967 | if (client != NFS_CLIENT(dir)) { |
| 3968 | rpc_shutdown_client(client); |
| 3969 | nfs_fixup_secinfo_attributes(fattr); |
| 3970 | } |
| 3971 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3974 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3975 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3976 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3977 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3978 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3979 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3980 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3981 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3982 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3983 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3984 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3985 | } |
| 3986 | |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 3987 | static int _nfs4_proc_lookupp(struct inode *inode, |
| 3988 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3989 | struct nfs4_label *label) |
| 3990 | { |
| 3991 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
| 3992 | struct nfs_server *server = NFS_SERVER(inode); |
| 3993 | int status; |
| 3994 | struct nfs4_lookupp_arg args = { |
| 3995 | .bitmask = server->attr_bitmask, |
| 3996 | .fh = NFS_FH(inode), |
| 3997 | }; |
| 3998 | struct nfs4_lookupp_res res = { |
| 3999 | .server = server, |
| 4000 | .fattr = fattr, |
| 4001 | .label = label, |
| 4002 | .fh = fhandle, |
| 4003 | }; |
| 4004 | struct rpc_message msg = { |
| 4005 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUPP], |
| 4006 | .rpc_argp = &args, |
| 4007 | .rpc_resp = &res, |
| 4008 | }; |
| 4009 | |
| 4010 | args.bitmask = nfs4_bitmask(server, label); |
| 4011 | |
| 4012 | nfs_fattr_init(fattr); |
| 4013 | |
| 4014 | dprintk("NFS call lookupp ino=0x%lx\n", inode->i_ino); |
| 4015 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 4016 | &res.seq_res, 0); |
| 4017 | dprintk("NFS reply lookupp: %d\n", status); |
| 4018 | return status; |
| 4019 | } |
| 4020 | |
| 4021 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
| 4022 | struct nfs_fattr *fattr, struct nfs4_label *label) |
| 4023 | { |
| 4024 | struct nfs4_exception exception = { }; |
| 4025 | int err; |
| 4026 | do { |
| 4027 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
| 4028 | trace_nfs4_lookupp(inode, err); |
| 4029 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
| 4030 | &exception); |
| 4031 | } while (exception.retry); |
| 4032 | return err; |
| 4033 | } |
| 4034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4036 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4037 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | struct nfs4_accessargs args = { |
| 4039 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 4040 | .bitmask = server->cache_consistency_bitmask, |
Anna Schumaker | 1750d92 | 2017-07-26 12:00:21 -0400 | [diff] [blame] | 4041 | .access = entry->mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4043 | struct nfs4_accessres res = { |
| 4044 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 4045 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | struct rpc_message msg = { |
| 4047 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 4048 | .rpc_argp = &args, |
| 4049 | .rpc_resp = &res, |
| 4050 | .rpc_cred = entry->cred, |
| 4051 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4052 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4054 | res.fattr = nfs_alloc_fattr(); |
| 4055 | if (res.fattr == NULL) |
| 4056 | return -ENOMEM; |
| 4057 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4058 | 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] | 4059 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 4060 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4061 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 4063 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | return status; |
| 4065 | } |
| 4066 | |
| 4067 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 4068 | { |
| 4069 | struct nfs4_exception exception = { }; |
| 4070 | int err; |
| 4071 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4072 | err = _nfs4_proc_access(inode, entry); |
| 4073 | trace_nfs4_access(inode, err); |
| 4074 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | &exception); |
| 4076 | } while (exception.retry); |
| 4077 | return err; |
| 4078 | } |
| 4079 | |
| 4080 | /* |
| 4081 | * TODO: For the time being, we don't try to get any attributes |
| 4082 | * along with any of the zero-copy operations READ, READDIR, |
| 4083 | * READLINK, WRITE. |
| 4084 | * |
| 4085 | * In the case of the first three, we want to put the GETATTR |
| 4086 | * after the read-type operation -- this is because it is hard |
| 4087 | * to predict the length of a GETATTR response in v4, and thus |
| 4088 | * align the READ data correctly. This means that the GETATTR |
| 4089 | * may end up partially falling into the page cache, and we should |
| 4090 | * shift it into the 'tail' of the xdr_buf before processing. |
| 4091 | * To do this efficiently, we need to know the total length |
| 4092 | * of data received, which doesn't seem to be available outside |
| 4093 | * of the RPC layer. |
| 4094 | * |
| 4095 | * In the case of WRITE, we also want to put the GETATTR after |
| 4096 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 4097 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | * |
| 4099 | * Both of these changes to the XDR layer would in fact be quite |
| 4100 | * minor, but I decided to leave them for a subsequent patch. |
| 4101 | */ |
| 4102 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4103 | unsigned int pgbase, unsigned int pglen) |
| 4104 | { |
| 4105 | struct nfs4_readlink args = { |
| 4106 | .fh = NFS_FH(inode), |
| 4107 | .pgbase = pgbase, |
| 4108 | .pglen = pglen, |
| 4109 | .pages = &page, |
| 4110 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4111 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | struct rpc_message msg = { |
| 4113 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 4114 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 4115 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | }; |
| 4117 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4118 | 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] | 4119 | } |
| 4120 | |
| 4121 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4122 | unsigned int pgbase, unsigned int pglen) |
| 4123 | { |
| 4124 | struct nfs4_exception exception = { }; |
| 4125 | int err; |
| 4126 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4127 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4128 | trace_nfs4_readlink(inode, err); |
| 4129 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | &exception); |
| 4131 | } while (exception.retry); |
| 4132 | return err; |
| 4133 | } |
| 4134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4136 | * 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] | 4137 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | static int |
| 4139 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4140 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4142 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4143 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4144 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | int status = 0; |
| 4147 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4148 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4149 | if (IS_ERR(ctx)) |
| 4150 | return PTR_ERR(ctx); |
| 4151 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4152 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4153 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4154 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4155 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4156 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | if (IS_ERR(state)) { |
| 4158 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4159 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4162 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4163 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | return status; |
| 4165 | } |
| 4166 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4167 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4169 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4170 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4172 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4174 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4175 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4176 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4179 | .rpc_argp = &args, |
| 4180 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4182 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4183 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4184 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4185 | 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] | 4186 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4187 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | return status; |
| 4189 | } |
| 4190 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4191 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | { |
| 4193 | struct nfs4_exception exception = { }; |
| 4194 | int err; |
| 4195 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4196 | err = _nfs4_proc_remove(dir, name); |
| 4197 | trace_nfs4_remove(dir, name, err); |
| 4198 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | &exception); |
| 4200 | } while (exception.retry); |
| 4201 | return err; |
| 4202 | } |
| 4203 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4204 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4206 | struct nfs_server *server = NFS_SERVER(dir); |
| 4207 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4208 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4210 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4212 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4213 | |
| 4214 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | } |
| 4216 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4217 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4218 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4219 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4220 | &data->args.seq_args, |
| 4221 | &data->res.seq_res, |
| 4222 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4225 | 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] | 4226 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4227 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4228 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4229 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4230 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4231 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4232 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4233 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4234 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4235 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4236 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4237 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4240 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4241 | { |
| 4242 | struct nfs_server *server = NFS_SERVER(dir); |
| 4243 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4244 | struct nfs_renameres *res = msg->rpc_resp; |
| 4245 | |
| 4246 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4247 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4248 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4249 | } |
| 4250 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4251 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4252 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4253 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4254 | &data->args.seq_args, |
| 4255 | &data->res.seq_res, |
| 4256 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4260 | struct inode *new_dir) |
| 4261 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4262 | struct nfs_renamedata *data = task->tk_calldata; |
| 4263 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4264 | |
| 4265 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4266 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4267 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4268 | return 0; |
| 4269 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4270 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4271 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4272 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4273 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4274 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4275 | return 1; |
| 4276 | } |
| 4277 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4278 | 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] | 4279 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4280 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | struct nfs4_link_arg arg = { |
| 4282 | .fh = NFS_FH(inode), |
| 4283 | .dir_fh = NFS_FH(dir), |
| 4284 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4285 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4287 | struct nfs4_link_res res = { |
| 4288 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4289 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4290 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | struct rpc_message msg = { |
| 4292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4293 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4294 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4296 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4298 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4299 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4300 | goto out; |
| 4301 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4302 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4303 | if (IS_ERR(res.label)) { |
| 4304 | status = PTR_ERR(res.label); |
| 4305 | goto out; |
| 4306 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4307 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4308 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4309 | 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] | 4310 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4311 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4312 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4313 | if (!status) |
| 4314 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4315 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4316 | |
| 4317 | |
| 4318 | nfs4_label_free(res.label); |
| 4319 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4320 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4321 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | return status; |
| 4323 | } |
| 4324 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4325 | 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] | 4326 | { |
| 4327 | struct nfs4_exception exception = { }; |
| 4328 | int err; |
| 4329 | do { |
| 4330 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4331 | _nfs4_proc_link(inode, dir, name), |
| 4332 | &exception); |
| 4333 | } while (exception.retry); |
| 4334 | return err; |
| 4335 | } |
| 4336 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4337 | struct nfs4_createdata { |
| 4338 | struct rpc_message msg; |
| 4339 | struct nfs4_create_arg arg; |
| 4340 | struct nfs4_create_res res; |
| 4341 | struct nfs_fh fh; |
| 4342 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4343 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4344 | }; |
| 4345 | |
| 4346 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4347 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4348 | { |
| 4349 | struct nfs4_createdata *data; |
| 4350 | |
| 4351 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4352 | if (data != NULL) { |
| 4353 | struct nfs_server *server = NFS_SERVER(dir); |
| 4354 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4355 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4356 | if (IS_ERR(data->label)) |
| 4357 | goto out_free; |
| 4358 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4359 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4360 | data->msg.rpc_argp = &data->arg; |
| 4361 | data->msg.rpc_resp = &data->res; |
| 4362 | data->arg.dir_fh = NFS_FH(dir); |
| 4363 | data->arg.server = server; |
| 4364 | data->arg.name = name; |
| 4365 | data->arg.attrs = sattr; |
| 4366 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4367 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4368 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4369 | data->res.server = server; |
| 4370 | data->res.fh = &data->fh; |
| 4371 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4372 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4373 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4374 | } |
| 4375 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4376 | out_free: |
| 4377 | kfree(data); |
| 4378 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4382 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4383 | 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] | 4384 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4385 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4386 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4387 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4388 | 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] | 4389 | } |
| 4390 | return status; |
| 4391 | } |
| 4392 | |
| 4393 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4394 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4395 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4396 | kfree(data); |
| 4397 | } |
| 4398 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4399 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4400 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4401 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4403 | struct nfs4_createdata *data; |
| 4404 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4406 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4407 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4408 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4409 | status = -ENOMEM; |
| 4410 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4411 | if (data == NULL) |
| 4412 | goto out; |
| 4413 | |
| 4414 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4415 | data->arg.u.symlink.pages = &page; |
| 4416 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4417 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4419 | status = nfs4_do_create(dir, dentry, data); |
| 4420 | |
| 4421 | nfs4_free_createdata(data); |
| 4422 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | return status; |
| 4424 | } |
| 4425 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4426 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4427 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | { |
| 4429 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4430 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4432 | |
| 4433 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4436 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4437 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4438 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | &exception); |
| 4440 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4441 | |
| 4442 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | return err; |
| 4444 | } |
| 4445 | |
| 4446 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4447 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4449 | struct nfs4_createdata *data; |
| 4450 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4452 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4453 | if (data == NULL) |
| 4454 | goto out; |
| 4455 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4456 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4457 | status = nfs4_do_create(dir, dentry, data); |
| 4458 | |
| 4459 | nfs4_free_createdata(data); |
| 4460 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | return status; |
| 4462 | } |
| 4463 | |
| 4464 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4465 | struct iattr *sattr) |
| 4466 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4467 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4469 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4471 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4472 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4473 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4474 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4475 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4477 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4478 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4479 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | &exception); |
| 4481 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4482 | nfs4_label_release_security(label); |
| 4483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | return err; |
| 4485 | } |
| 4486 | |
| 4487 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4488 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4490 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | struct nfs4_readdir_arg args = { |
| 4492 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4493 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | .pgbase = 0, |
| 4495 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4496 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4497 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | }; |
| 4499 | struct nfs4_readdir_res res; |
| 4500 | struct rpc_message msg = { |
| 4501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4502 | .rpc_argp = &args, |
| 4503 | .rpc_resp = &res, |
| 4504 | .rpc_cred = cred, |
| 4505 | }; |
| 4506 | int status; |
| 4507 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4508 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4509 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4510 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4511 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4513 | 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] | 4514 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4515 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4516 | status += args.pgbase; |
| 4517 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4518 | |
| 4519 | nfs_invalidate_atime(dir); |
| 4520 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4521 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | return status; |
| 4523 | } |
| 4524 | |
| 4525 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 4526 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | { |
| 4528 | struct nfs4_exception exception = { }; |
| 4529 | int err; |
| 4530 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4531 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4532 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4533 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4534 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | &exception); |
| 4536 | } while (exception.retry); |
| 4537 | return err; |
| 4538 | } |
| 4539 | |
| 4540 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4541 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4543 | struct nfs4_createdata *data; |
| 4544 | int mode = sattr->ia_mode; |
| 4545 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4547 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4548 | if (data == NULL) |
| 4549 | goto out; |
| 4550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4552 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4554 | data->arg.ftype = NF4BLK; |
| 4555 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4556 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } |
| 4558 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4559 | data->arg.ftype = NF4CHR; |
| 4560 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4561 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4562 | } else if (!S_ISSOCK(mode)) { |
| 4563 | status = -EINVAL; |
| 4564 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4566 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4567 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4568 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4569 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4570 | nfs4_free_createdata(data); |
| 4571 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | return status; |
| 4573 | } |
| 4574 | |
| 4575 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4576 | struct iattr *sattr, dev_t rdev) |
| 4577 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4578 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4580 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4582 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4583 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4584 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4585 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4586 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4588 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4589 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4590 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | &exception); |
| 4592 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4593 | |
| 4594 | nfs4_label_release_security(label); |
| 4595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | return err; |
| 4597 | } |
| 4598 | |
| 4599 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4600 | struct nfs_fsstat *fsstat) |
| 4601 | { |
| 4602 | struct nfs4_statfs_arg args = { |
| 4603 | .fh = fhandle, |
| 4604 | .bitmask = server->attr_bitmask, |
| 4605 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4606 | struct nfs4_statfs_res res = { |
| 4607 | .fsstat = fsstat, |
| 4608 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | struct rpc_message msg = { |
| 4610 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4611 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4612 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | }; |
| 4614 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4615 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4616 | 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] | 4617 | } |
| 4618 | |
| 4619 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4620 | { |
| 4621 | struct nfs4_exception exception = { }; |
| 4622 | int err; |
| 4623 | do { |
| 4624 | err = nfs4_handle_exception(server, |
| 4625 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4626 | &exception); |
| 4627 | } while (exception.retry); |
| 4628 | return err; |
| 4629 | } |
| 4630 | |
| 4631 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4632 | struct nfs_fsinfo *fsinfo) |
| 4633 | { |
| 4634 | struct nfs4_fsinfo_arg args = { |
| 4635 | .fh = fhandle, |
| 4636 | .bitmask = server->attr_bitmask, |
| 4637 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4638 | struct nfs4_fsinfo_res res = { |
| 4639 | .fsinfo = fsinfo, |
| 4640 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | struct rpc_message msg = { |
| 4642 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4643 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4644 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | }; |
| 4646 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4647 | 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] | 4648 | } |
| 4649 | |
| 4650 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4651 | { |
| 4652 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4653 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | int err; |
| 4655 | |
| 4656 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4657 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4658 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4659 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4660 | nfs4_set_lease_period(server->nfs_client, |
| 4661 | fsinfo->lease_time * HZ, |
| 4662 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4663 | break; |
| 4664 | } |
| 4665 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | } while (exception.retry); |
| 4667 | return err; |
| 4668 | } |
| 4669 | |
| 4670 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4671 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4672 | int error; |
| 4673 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4674 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4675 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4676 | if (error == 0) { |
| 4677 | /* block layout checks this! */ |
| 4678 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4679 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4680 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4681 | |
| 4682 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4686 | struct nfs_pathconf *pathconf) |
| 4687 | { |
| 4688 | struct nfs4_pathconf_arg args = { |
| 4689 | .fh = fhandle, |
| 4690 | .bitmask = server->attr_bitmask, |
| 4691 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4692 | struct nfs4_pathconf_res res = { |
| 4693 | .pathconf = pathconf, |
| 4694 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | struct rpc_message msg = { |
| 4696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4697 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4698 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | }; |
| 4700 | |
| 4701 | /* None of the pathconf attributes are mandatory to implement */ |
| 4702 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4703 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4704 | return 0; |
| 4705 | } |
| 4706 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4707 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4708 | 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] | 4709 | } |
| 4710 | |
| 4711 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4712 | struct nfs_pathconf *pathconf) |
| 4713 | { |
| 4714 | struct nfs4_exception exception = { }; |
| 4715 | int err; |
| 4716 | |
| 4717 | do { |
| 4718 | err = nfs4_handle_exception(server, |
| 4719 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4720 | &exception); |
| 4721 | } while (exception.retry); |
| 4722 | return err; |
| 4723 | } |
| 4724 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4725 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4726 | const struct nfs_open_context *ctx, |
| 4727 | const struct nfs_lock_context *l_ctx, |
| 4728 | fmode_t fmode) |
| 4729 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4730 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4731 | } |
| 4732 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4733 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4734 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4735 | const struct nfs_open_context *ctx, |
| 4736 | const struct nfs_lock_context *l_ctx, |
| 4737 | fmode_t fmode) |
| 4738 | { |
| 4739 | nfs4_stateid current_stateid; |
| 4740 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4741 | /* If the current stateid represents a lost lock, then exit */ |
| 4742 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4743 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4744 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4745 | } |
| 4746 | |
| 4747 | static bool nfs4_error_stateid_expired(int err) |
| 4748 | { |
| 4749 | switch (err) { |
| 4750 | case -NFS4ERR_DELEG_REVOKED: |
| 4751 | case -NFS4ERR_ADMIN_REVOKED: |
| 4752 | case -NFS4ERR_BAD_STATEID: |
| 4753 | case -NFS4ERR_STALE_STATEID: |
| 4754 | case -NFS4ERR_OLD_STATEID: |
| 4755 | case -NFS4ERR_OPENMODE: |
| 4756 | case -NFS4ERR_EXPIRED: |
| 4757 | return true; |
| 4758 | } |
| 4759 | return false; |
| 4760 | } |
| 4761 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4762 | 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] | 4763 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4764 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4766 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4767 | if (task->tk_status < 0) { |
| 4768 | struct nfs4_exception exception = { |
| 4769 | .inode = hdr->inode, |
| 4770 | .state = hdr->args.context->state, |
| 4771 | .stateid = &hdr->args.stateid, |
| 4772 | }; |
| 4773 | task->tk_status = nfs4_async_handle_exception(task, |
| 4774 | server, task->tk_status, &exception); |
| 4775 | if (exception.retry) { |
| 4776 | rpc_restart_call_prepare(task); |
| 4777 | return -EAGAIN; |
| 4778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4782 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4783 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } |
| 4785 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4786 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4787 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4788 | { |
| 4789 | |
| 4790 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4791 | nfs4_stateid_is_current(&args->stateid, |
| 4792 | args->context, |
| 4793 | args->lock_context, |
| 4794 | FMODE_READ)) |
| 4795 | return false; |
| 4796 | rpc_restart_call_prepare(task); |
| 4797 | return true; |
| 4798 | } |
| 4799 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4800 | 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] | 4801 | { |
| 4802 | |
| 4803 | dprintk("--> %s\n", __func__); |
| 4804 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4805 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4806 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4807 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4808 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4809 | if (task->tk_status > 0) |
| 4810 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4811 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4812 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4815 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4816 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4818 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4819 | if (!hdr->pgio_done_cb) |
| 4820 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4821 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4822 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4825 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4826 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4827 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4828 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4829 | &hdr->args.seq_args, |
| 4830 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4831 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4832 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4833 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4834 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4835 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4836 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4837 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4838 | return -EIO; |
| 4839 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4842 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4843 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4845 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4846 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4847 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4848 | if (task->tk_status < 0) { |
| 4849 | struct nfs4_exception exception = { |
| 4850 | .inode = hdr->inode, |
| 4851 | .state = hdr->args.context->state, |
| 4852 | .stateid = &hdr->args.stateid, |
| 4853 | }; |
| 4854 | task->tk_status = nfs4_async_handle_exception(task, |
| 4855 | NFS_SERVER(inode), task->tk_status, |
| 4856 | &exception); |
| 4857 | if (exception.retry) { |
| 4858 | rpc_restart_call_prepare(task); |
| 4859 | return -EAGAIN; |
| 4860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4862 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4863 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4864 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4865 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4866 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | } |
| 4868 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4869 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4870 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4871 | { |
| 4872 | |
| 4873 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4874 | nfs4_stateid_is_current(&args->stateid, |
| 4875 | args->context, |
| 4876 | args->lock_context, |
| 4877 | FMODE_WRITE)) |
| 4878 | return false; |
| 4879 | rpc_restart_call_prepare(task); |
| 4880 | return true; |
| 4881 | } |
| 4882 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4883 | 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] | 4884 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4885 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4886 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4887 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4888 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4889 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4890 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4893 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4894 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4895 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4896 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4897 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4898 | return false; |
| 4899 | /* Otherwise, request attributes if and only if we don't hold |
| 4900 | * a delegation |
| 4901 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4902 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4903 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4904 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4905 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4906 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4908 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4909 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4910 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4911 | hdr->args.bitmask = NULL; |
| 4912 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4913 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4914 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4915 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4916 | if (!hdr->pgio_done_cb) |
| 4917 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4918 | hdr->res.server = server; |
| 4919 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4921 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4922 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4925 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4926 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4927 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4928 | &data->args.seq_args, |
| 4929 | &data->res.seq_res, |
| 4930 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4933 | 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] | 4934 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4936 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4937 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4938 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4939 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4940 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4941 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4943 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4946 | 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] | 4947 | { |
| 4948 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4949 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4950 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4953 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4955 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4956 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4957 | if (data->commit_done_cb == NULL) |
| 4958 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4959 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4960 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4961 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4964 | struct nfs4_renewdata { |
| 4965 | struct nfs_client *client; |
| 4966 | unsigned long timestamp; |
| 4967 | }; |
| 4968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | /* |
| 4970 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4971 | * standalone procedure for queueing an asynchronous RENEW. |
| 4972 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4973 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4974 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4975 | struct nfs4_renewdata *data = calldata; |
| 4976 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4977 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 4978 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4979 | nfs4_schedule_state_renewal(clp); |
| 4980 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4981 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4984 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4986 | struct nfs4_renewdata *data = calldata; |
| 4987 | struct nfs_client *clp = data->client; |
| 4988 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4990 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4991 | switch (task->tk_status) { |
| 4992 | case 0: |
| 4993 | break; |
| 4994 | case -NFS4ERR_LEASE_MOVED: |
| 4995 | nfs4_schedule_lease_moved_recovery(clp); |
| 4996 | break; |
| 4997 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4998 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4999 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 5000 | return; |
| 5001 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5002 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5003 | return; |
| 5004 | } |
| 5005 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5007 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5010 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 5011 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5012 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5013 | }; |
| 5014 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5015 | 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] | 5016 | { |
| 5017 | struct rpc_message msg = { |
| 5018 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5019 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5020 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5022 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5024 | if (renew_flags == 0) |
| 5025 | return 0; |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 5026 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 5027 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 5028 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5029 | if (data == NULL) { |
| 5030 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5031 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 5032 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5033 | data->client = clp; |
| 5034 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5035 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 5036 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5039 | 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] | 5040 | { |
| 5041 | struct rpc_message msg = { |
| 5042 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 5043 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 5044 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | }; |
| 5046 | unsigned long now = jiffies; |
| 5047 | int status; |
| 5048 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 5049 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | if (status < 0) |
| 5051 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5052 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | return 0; |
| 5054 | } |
| 5055 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5056 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 5057 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 5058 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5061 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 5062 | * 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] | 5063 | * the stack. |
| 5064 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5065 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5066 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5067 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5068 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5069 | { |
| 5070 | struct page *newpage, **spages; |
| 5071 | int rc = 0; |
| 5072 | size_t len; |
| 5073 | spages = pages; |
| 5074 | |
| 5075 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5076 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5077 | newpage = alloc_page(GFP_KERNEL); |
| 5078 | |
| 5079 | if (newpage == NULL) |
| 5080 | goto unwind; |
| 5081 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5082 | buf += len; |
| 5083 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5084 | *pages++ = newpage; |
| 5085 | rc++; |
| 5086 | } while (buflen != 0); |
| 5087 | |
| 5088 | return rc; |
| 5089 | |
| 5090 | unwind: |
| 5091 | for(; rc > 0; rc--) |
| 5092 | __free_page(spages[rc-1]); |
| 5093 | return -ENOMEM; |
| 5094 | } |
| 5095 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5096 | struct nfs4_cached_acl { |
| 5097 | int cached; |
| 5098 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 5099 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5100 | }; |
| 5101 | |
| 5102 | 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] | 5103 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5104 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5105 | |
| 5106 | spin_lock(&inode->i_lock); |
| 5107 | kfree(nfsi->nfs4_acl); |
| 5108 | nfsi->nfs4_acl = acl; |
| 5109 | spin_unlock(&inode->i_lock); |
| 5110 | } |
| 5111 | |
| 5112 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 5113 | { |
| 5114 | nfs4_set_cached_acl(inode, NULL); |
| 5115 | } |
| 5116 | |
| 5117 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 5118 | { |
| 5119 | struct nfs_inode *nfsi = NFS_I(inode); |
| 5120 | struct nfs4_cached_acl *acl; |
| 5121 | int ret = -ENOENT; |
| 5122 | |
| 5123 | spin_lock(&inode->i_lock); |
| 5124 | acl = nfsi->nfs4_acl; |
| 5125 | if (acl == NULL) |
| 5126 | goto out; |
| 5127 | if (buf == NULL) /* user is just asking for length */ |
| 5128 | goto out_len; |
| 5129 | if (acl->cached == 0) |
| 5130 | goto out; |
| 5131 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5132 | if (acl->len > buflen) |
| 5133 | goto out; |
| 5134 | memcpy(buf, acl->data, acl->len); |
| 5135 | out_len: |
| 5136 | ret = acl->len; |
| 5137 | out: |
| 5138 | spin_unlock(&inode->i_lock); |
| 5139 | return ret; |
| 5140 | } |
| 5141 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5142 | 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] | 5143 | { |
| 5144 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5145 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5146 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5147 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5148 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5149 | if (acl == NULL) |
| 5150 | goto out; |
| 5151 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5152 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5153 | } else { |
| 5154 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5155 | if (acl == NULL) |
| 5156 | goto out; |
| 5157 | acl->cached = 0; |
| 5158 | } |
| 5159 | acl->len = acl_len; |
| 5160 | out: |
| 5161 | nfs4_set_cached_acl(inode, acl); |
| 5162 | } |
| 5163 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5164 | /* |
| 5165 | * The getxattr API returns the required buffer length when called with a |
| 5166 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5167 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5168 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5169 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5170 | * the cache. If not so, we throw away the page, and cache the required |
| 5171 | * length. The next getxattr call will then produce another round trip to |
| 5172 | * the server, this time with the input buf of the required size. |
| 5173 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5174 | 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] | 5175 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5176 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5177 | struct nfs_getaclargs args = { |
| 5178 | .fh = NFS_FH(inode), |
| 5179 | .acl_pages = pages, |
| 5180 | .acl_len = buflen, |
| 5181 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5182 | struct nfs_getaclres res = { |
| 5183 | .acl_len = buflen, |
| 5184 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5185 | struct rpc_message msg = { |
| 5186 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5187 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5188 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5189 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 5190 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5191 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5192 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5193 | if (npages > ARRAY_SIZE(pages)) |
| 5194 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5195 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5196 | for (i = 0; i < npages; i++) { |
| 5197 | pages[i] = alloc_page(GFP_KERNEL); |
| 5198 | if (!pages[i]) |
| 5199 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5200 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5201 | |
| 5202 | /* for decoding across pages */ |
| 5203 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5204 | if (!res.acl_scratch) |
| 5205 | goto out_free; |
| 5206 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5207 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5208 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5209 | 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] | 5210 | __func__, buf, buflen, npages, args.acl_len); |
| 5211 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5212 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5213 | if (ret) |
| 5214 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5215 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5216 | /* Handle the case where the passed-in buffer is too short */ |
| 5217 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5218 | /* Did the user only issue a request for the acl length? */ |
| 5219 | if (buf == NULL) |
| 5220 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5221 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5222 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5223 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5224 | 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] | 5225 | if (buf) { |
| 5226 | if (res.acl_len > buflen) { |
| 5227 | ret = -ERANGE; |
| 5228 | goto out_free; |
| 5229 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5230 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5231 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5232 | out_ok: |
| 5233 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5234 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5235 | for (i = 0; i < npages; i++) |
| 5236 | if (pages[i]) |
| 5237 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5238 | if (res.acl_scratch) |
| 5239 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5240 | return ret; |
| 5241 | } |
| 5242 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5243 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5244 | { |
| 5245 | struct nfs4_exception exception = { }; |
| 5246 | ssize_t ret; |
| 5247 | do { |
| 5248 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5249 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5250 | if (ret >= 0) |
| 5251 | break; |
| 5252 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5253 | } while (exception.retry); |
| 5254 | return ret; |
| 5255 | } |
| 5256 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5257 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5258 | { |
| 5259 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5260 | int ret; |
| 5261 | |
| 5262 | if (!nfs4_server_supports_acls(server)) |
| 5263 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5264 | ret = nfs_revalidate_inode(server, inode); |
| 5265 | if (ret < 0) |
| 5266 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5267 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5268 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5269 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5270 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5271 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5272 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5273 | return ret; |
| 5274 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5275 | } |
| 5276 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5277 | 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] | 5278 | { |
| 5279 | struct nfs_server *server = NFS_SERVER(inode); |
| 5280 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5281 | struct nfs_setaclargs arg = { |
| 5282 | .fh = NFS_FH(inode), |
| 5283 | .acl_pages = pages, |
| 5284 | .acl_len = buflen, |
| 5285 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5286 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5287 | struct rpc_message msg = { |
| 5288 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5289 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5290 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5291 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5292 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5293 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5294 | |
| 5295 | if (!nfs4_server_supports_acls(server)) |
| 5296 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5297 | if (npages > ARRAY_SIZE(pages)) |
| 5298 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5299 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5300 | if (i < 0) |
| 5301 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5302 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5303 | 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] | 5304 | |
| 5305 | /* |
| 5306 | * Free each page after tx, so the only ref left is |
| 5307 | * held by the network stack |
| 5308 | */ |
| 5309 | for (; i > 0; i--) |
| 5310 | put_page(pages[i-1]); |
| 5311 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5312 | /* |
| 5313 | * Acl update can result in inode attribute update. |
| 5314 | * so mark the attribute cache invalid. |
| 5315 | */ |
| 5316 | spin_lock(&inode->i_lock); |
| 5317 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5318 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5319 | nfs_access_zap_cache(inode); |
| 5320 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5321 | return ret; |
| 5322 | } |
| 5323 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5324 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5325 | { |
| 5326 | struct nfs4_exception exception = { }; |
| 5327 | int err; |
| 5328 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5329 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5330 | trace_nfs4_set_acl(inode, err); |
| 5331 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5332 | &exception); |
| 5333 | } while (exception.retry); |
| 5334 | return err; |
| 5335 | } |
| 5336 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5337 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5338 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5339 | size_t buflen) |
| 5340 | { |
| 5341 | struct nfs_server *server = NFS_SERVER(inode); |
| 5342 | struct nfs_fattr fattr; |
| 5343 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5344 | |
| 5345 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5346 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5347 | .fh = NFS_FH(inode), |
| 5348 | .bitmask = bitmask, |
| 5349 | }; |
| 5350 | struct nfs4_getattr_res res = { |
| 5351 | .fattr = &fattr, |
| 5352 | .label = &label, |
| 5353 | .server = server, |
| 5354 | }; |
| 5355 | struct rpc_message msg = { |
| 5356 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5357 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5358 | .rpc_resp = &res, |
| 5359 | }; |
| 5360 | int ret; |
| 5361 | |
| 5362 | nfs_fattr_init(&fattr); |
| 5363 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5364 | 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] | 5365 | if (ret) |
| 5366 | return ret; |
| 5367 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5368 | return -ENOENT; |
| 5369 | if (buflen < label.len) |
| 5370 | return -ERANGE; |
| 5371 | return 0; |
| 5372 | } |
| 5373 | |
| 5374 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5375 | size_t buflen) |
| 5376 | { |
| 5377 | struct nfs4_exception exception = { }; |
| 5378 | int err; |
| 5379 | |
| 5380 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5381 | return -EOPNOTSUPP; |
| 5382 | |
| 5383 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5384 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5385 | trace_nfs4_get_security_label(inode, err); |
| 5386 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5387 | &exception); |
| 5388 | } while (exception.retry); |
| 5389 | return err; |
| 5390 | } |
| 5391 | |
| 5392 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5393 | struct nfs4_label *ilabel, |
| 5394 | struct nfs_fattr *fattr, |
| 5395 | struct nfs4_label *olabel) |
| 5396 | { |
| 5397 | |
| 5398 | struct iattr sattr = {0}; |
| 5399 | struct nfs_server *server = NFS_SERVER(inode); |
| 5400 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5401 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5402 | .fh = NFS_FH(inode), |
| 5403 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5404 | .server = server, |
| 5405 | .bitmask = bitmask, |
| 5406 | .label = ilabel, |
| 5407 | }; |
| 5408 | struct nfs_setattrres res = { |
| 5409 | .fattr = fattr, |
| 5410 | .label = olabel, |
| 5411 | .server = server, |
| 5412 | }; |
| 5413 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5414 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5415 | .rpc_argp = &arg, |
| 5416 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5417 | }; |
| 5418 | int status; |
| 5419 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5420 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5421 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5422 | 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] | 5423 | if (status) |
| 5424 | dprintk("%s failed: %d\n", __func__, status); |
| 5425 | |
| 5426 | return status; |
| 5427 | } |
| 5428 | |
| 5429 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5430 | struct nfs4_label *ilabel, |
| 5431 | struct nfs_fattr *fattr, |
| 5432 | struct nfs4_label *olabel) |
| 5433 | { |
| 5434 | struct nfs4_exception exception = { }; |
| 5435 | int err; |
| 5436 | |
| 5437 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5438 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5439 | fattr, olabel); |
| 5440 | trace_nfs4_set_security_label(inode, err); |
| 5441 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5442 | &exception); |
| 5443 | } while (exception.retry); |
| 5444 | return err; |
| 5445 | } |
| 5446 | |
| 5447 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5448 | 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] | 5449 | { |
| 5450 | struct nfs4_label ilabel, *olabel = NULL; |
| 5451 | struct nfs_fattr fattr; |
| 5452 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5453 | int status; |
| 5454 | |
| 5455 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5456 | return -EOPNOTSUPP; |
| 5457 | |
| 5458 | nfs_fattr_init(&fattr); |
| 5459 | |
| 5460 | ilabel.pi = 0; |
| 5461 | ilabel.lfs = 0; |
| 5462 | ilabel.label = (char *)buf; |
| 5463 | ilabel.len = buflen; |
| 5464 | |
| 5465 | cred = rpc_lookup_cred(); |
| 5466 | if (IS_ERR(cred)) |
| 5467 | return PTR_ERR(cred); |
| 5468 | |
| 5469 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5470 | if (IS_ERR(olabel)) { |
| 5471 | status = -PTR_ERR(olabel); |
| 5472 | goto out; |
| 5473 | } |
| 5474 | |
| 5475 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5476 | if (status == 0) |
| 5477 | nfs_setsecurity(inode, &fattr, olabel); |
| 5478 | |
| 5479 | nfs4_label_free(olabel); |
| 5480 | out: |
| 5481 | put_rpccred(cred); |
| 5482 | return status; |
| 5483 | } |
| 5484 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5485 | |
| 5486 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5487 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5488 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5489 | { |
| 5490 | __be32 verf[2]; |
| 5491 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5492 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5493 | /* An impossible timestamp guarantees this value |
| 5494 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5495 | verf[0] = cpu_to_be32(U32_MAX); |
| 5496 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5497 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5498 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5499 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5500 | |
| 5501 | verf[0] = cpu_to_be32(ns >> 32); |
| 5502 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5503 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5504 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5505 | } |
| 5506 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5507 | static int |
| 5508 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5509 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5510 | size_t len; |
| 5511 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5512 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5513 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5514 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5515 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5516 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5517 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5518 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5519 | 1 + |
| 5520 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5521 | 1; |
| 5522 | rcu_read_unlock(); |
| 5523 | |
| 5524 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5525 | return -EINVAL; |
| 5526 | |
| 5527 | /* |
| 5528 | * Since this string is allocated at mount time, and held until the |
| 5529 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5530 | * about a memory-reclaim deadlock. |
| 5531 | */ |
| 5532 | str = kmalloc(len, GFP_KERNEL); |
| 5533 | if (!str) |
| 5534 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5535 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5536 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5537 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5538 | clp->cl_ipaddr, |
| 5539 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5540 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5541 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5542 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5543 | clp->cl_owner_id = str; |
| 5544 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5545 | } |
| 5546 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5547 | static int |
| 5548 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5549 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5550 | size_t len; |
| 5551 | char *str; |
| 5552 | |
| 5553 | len = 10 + 10 + 1 + 10 + 1 + |
| 5554 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5555 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5556 | |
| 5557 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5558 | return -EINVAL; |
| 5559 | |
| 5560 | /* |
| 5561 | * Since this string is allocated at mount time, and held until the |
| 5562 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5563 | * about a memory-reclaim deadlock. |
| 5564 | */ |
| 5565 | str = kmalloc(len, GFP_KERNEL); |
| 5566 | if (!str) |
| 5567 | return -ENOMEM; |
| 5568 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5569 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5570 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5571 | nfs4_client_id_uniquifier, |
| 5572 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5573 | clp->cl_owner_id = str; |
| 5574 | return 0; |
| 5575 | } |
| 5576 | |
| 5577 | static int |
| 5578 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5579 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5580 | size_t len; |
| 5581 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5582 | |
| 5583 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5584 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5585 | |
| 5586 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5587 | return nfs4_init_uniquifier_client_string(clp); |
| 5588 | |
| 5589 | len = 10 + 10 + 1 + 10 + 1 + |
| 5590 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5591 | |
| 5592 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5593 | return -EINVAL; |
| 5594 | |
| 5595 | /* |
| 5596 | * Since this string is allocated at mount time, and held until the |
| 5597 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5598 | * about a memory-reclaim deadlock. |
| 5599 | */ |
| 5600 | str = kmalloc(len, GFP_KERNEL); |
| 5601 | if (!str) |
| 5602 | return -ENOMEM; |
| 5603 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5604 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5605 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5606 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5607 | clp->cl_owner_id = str; |
| 5608 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5609 | } |
| 5610 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5611 | /* |
| 5612 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5613 | * services. Advertise one based on the address family of the |
| 5614 | * clientaddr. |
| 5615 | */ |
| 5616 | static unsigned int |
| 5617 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5618 | { |
| 5619 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5620 | return scnprintf(buf, len, "tcp6"); |
| 5621 | else |
| 5622 | return scnprintf(buf, len, "tcp"); |
| 5623 | } |
| 5624 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5625 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5626 | { |
| 5627 | struct nfs4_setclientid *sc = calldata; |
| 5628 | |
| 5629 | if (task->tk_status == 0) |
| 5630 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5631 | } |
| 5632 | |
| 5633 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5634 | .rpc_call_done = nfs4_setclientid_done, |
| 5635 | }; |
| 5636 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5637 | /** |
| 5638 | * nfs4_proc_setclientid - Negotiate client ID |
| 5639 | * @clp: state data structure |
| 5640 | * @program: RPC program for NFSv4 callback service |
| 5641 | * @port: IP port number for NFS4 callback service |
| 5642 | * @cred: RPC credential to use for this call |
| 5643 | * @res: where to place the result |
| 5644 | * |
| 5645 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5646 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5647 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5648 | unsigned short port, struct rpc_cred *cred, |
| 5649 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | { |
| 5651 | nfs4_verifier sc_verifier; |
| 5652 | struct nfs4_setclientid setclientid = { |
| 5653 | .sc_verifier = &sc_verifier, |
| 5654 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5655 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | }; |
| 5657 | struct rpc_message msg = { |
| 5658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5659 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5660 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5661 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5663 | struct rpc_task *task; |
| 5664 | struct rpc_task_setup task_setup_data = { |
| 5665 | .rpc_client = clp->cl_rpcclient, |
| 5666 | .rpc_message = &msg, |
| 5667 | .callback_ops = &nfs4_setclientid_ops, |
| 5668 | .callback_data = &setclientid, |
| 5669 | .flags = RPC_TASK_TIMEOUT, |
| 5670 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5671 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5673 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5674 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5675 | |
| 5676 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5677 | status = nfs4_init_uniform_client_string(clp); |
| 5678 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5679 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5680 | |
| 5681 | if (status) |
| 5682 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5683 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5684 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5685 | setclientid.sc_netid_len = |
| 5686 | nfs4_init_callback_netid(clp, |
| 5687 | setclientid.sc_netid, |
| 5688 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5689 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5690 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5692 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5693 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5694 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5695 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5696 | task = rpc_run_task(&task_setup_data); |
| 5697 | if (IS_ERR(task)) { |
| 5698 | status = PTR_ERR(task); |
| 5699 | goto out; |
| 5700 | } |
| 5701 | status = task->tk_status; |
| 5702 | if (setclientid.sc_cred) { |
| 5703 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5704 | put_rpccred(setclientid.sc_cred); |
| 5705 | } |
| 5706 | rpc_put_task(task); |
| 5707 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5708 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5709 | dprintk("NFS reply setclientid: %d\n", status); |
| 5710 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5713 | /** |
| 5714 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5715 | * @clp: state data structure |
| 5716 | * @res: result of a previous SETCLIENTID |
| 5717 | * @cred: RPC credential to use for this call |
| 5718 | * |
| 5719 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5720 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5721 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5722 | struct nfs4_setclientid_res *arg, |
| 5723 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | struct rpc_message msg = { |
| 5726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5727 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5728 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | int status; |
| 5731 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5732 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5733 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5734 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5735 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5736 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5737 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | return status; |
| 5739 | } |
| 5740 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5741 | struct nfs4_delegreturndata { |
| 5742 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5743 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5744 | struct nfs_fh fh; |
| 5745 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5746 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5747 | struct { |
| 5748 | struct nfs4_layoutreturn_args arg; |
| 5749 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5750 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5751 | u32 roc_barrier; |
| 5752 | bool roc; |
| 5753 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5754 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5755 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5756 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5757 | }; |
| 5758 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5759 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5760 | { |
| 5761 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5762 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5763 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5764 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5765 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5766 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5767 | |
| 5768 | /* Handle Layoutreturn errors */ |
| 5769 | if (data->args.lr_args && task->tk_status != 0) { |
| 5770 | switch(data->res.lr_ret) { |
| 5771 | default: |
| 5772 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5773 | break; |
| 5774 | case 0: |
| 5775 | data->args.lr_args = NULL; |
| 5776 | data->res.lr_res = NULL; |
| 5777 | break; |
Trond Myklebust | 7380020 | 2017-11-06 15:28:07 -0500 | [diff] [blame] | 5778 | case -NFS4ERR_OLD_STATEID: |
| 5779 | if (nfs4_refresh_layout_stateid(&data->args.lr_args->stateid, |
| 5780 | data->inode)) { |
| 5781 | data->res.lr_ret = 0; |
| 5782 | rpc_restart_call_prepare(task); |
| 5783 | return; |
| 5784 | } |
| 5785 | /* Fallthrough */ |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5786 | case -NFS4ERR_ADMIN_REVOKED: |
| 5787 | case -NFS4ERR_DELEG_REVOKED: |
| 5788 | case -NFS4ERR_EXPIRED: |
| 5789 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5790 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5791 | case -NFS4ERR_WRONG_CRED: |
| 5792 | data->args.lr_args = NULL; |
| 5793 | data->res.lr_res = NULL; |
| 5794 | data->res.lr_ret = 0; |
| 5795 | rpc_restart_call_prepare(task); |
| 5796 | return; |
| 5797 | } |
| 5798 | } |
| 5799 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5800 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5801 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5802 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5803 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5804 | case -NFS4ERR_ADMIN_REVOKED: |
| 5805 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5806 | case -NFS4ERR_EXPIRED: |
| 5807 | nfs4_free_revoked_stateid(data->res.server, |
| 5808 | data->args.stateid, |
| 5809 | task->tk_msg.rpc_cred); |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5810 | /* Fallthrough */ |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5811 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5812 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5813 | task->tk_status = 0; |
| 5814 | break; |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 5815 | case -NFS4ERR_OLD_STATEID: |
| 5816 | if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) { |
| 5817 | task->tk_status = 0; |
| 5818 | rpc_restart_call_prepare(task); |
| 5819 | return; |
| 5820 | } |
| 5821 | task->tk_status = 0; |
| 5822 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5823 | case -NFS4ERR_ACCESS: |
| 5824 | if (data->args.bitmask) { |
| 5825 | data->args.bitmask = NULL; |
| 5826 | data->res.fattr = NULL; |
| 5827 | task->tk_status = 0; |
| 5828 | rpc_restart_call_prepare(task); |
| 5829 | return; |
| 5830 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5831 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5832 | if (nfs4_async_handle_error(task, data->res.server, |
| 5833 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5834 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5835 | return; |
| 5836 | } |
| 5837 | } |
| 5838 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | static void nfs4_delegreturn_release(void *calldata) |
| 5842 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5843 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5844 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5845 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5846 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5847 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5848 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5849 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5850 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5851 | nfs_iput_and_deactive(inode); |
| 5852 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5853 | kfree(calldata); |
| 5854 | } |
| 5855 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5856 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5857 | { |
| 5858 | struct nfs4_delegreturndata *d_data; |
| 5859 | |
| 5860 | d_data = (struct nfs4_delegreturndata *)data; |
| 5861 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5862 | 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] | 5863 | return; |
| 5864 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5865 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5866 | &d_data->args.seq_args, |
| 5867 | &d_data->res.seq_res, |
| 5868 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5869 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5870 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5871 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5872 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5873 | .rpc_call_done = nfs4_delegreturn_done, |
| 5874 | .rpc_release = nfs4_delegreturn_release, |
| 5875 | }; |
| 5876 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5877 | 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] | 5878 | { |
| 5879 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5880 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5881 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5882 | struct rpc_message msg = { |
| 5883 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5884 | .rpc_cred = cred, |
| 5885 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5886 | struct rpc_task_setup task_setup_data = { |
| 5887 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5888 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5889 | .callback_ops = &nfs4_delegreturn_ops, |
| 5890 | .flags = RPC_TASK_ASYNC, |
| 5891 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5892 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5893 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5894 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5895 | if (data == NULL) |
| 5896 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5897 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5898 | |
| 5899 | nfs4_state_protect(server->nfs_client, |
| 5900 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5901 | &task_setup_data.rpc_client, &msg); |
| 5902 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5903 | data->args.fhandle = &data->fh; |
| 5904 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5905 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5906 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5907 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5908 | data->res.fattr = &data->fattr; |
| 5909 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5910 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5911 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5912 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5913 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5914 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5915 | 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] | 5916 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5917 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5918 | if (data->lr.roc) { |
| 5919 | data->args.lr_args = &data->lr.arg; |
| 5920 | data->res.lr_res = &data->lr.res; |
| 5921 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5922 | } else if (data->lr.roc) { |
| 5923 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5924 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5925 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5926 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5927 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5928 | msg.rpc_argp = &data->args; |
| 5929 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5930 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5931 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5932 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5933 | if (!issync) |
| 5934 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5935 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5936 | if (status != 0) |
| 5937 | goto out; |
| 5938 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5939 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5940 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5941 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5942 | } |
| 5943 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5944 | 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] | 5945 | { |
| 5946 | struct nfs_server *server = NFS_SERVER(inode); |
| 5947 | struct nfs4_exception exception = { }; |
| 5948 | int err; |
| 5949 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5950 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5951 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | switch (err) { |
| 5953 | case -NFS4ERR_STALE_STATEID: |
| 5954 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | case 0: |
| 5956 | return 0; |
| 5957 | } |
| 5958 | err = nfs4_handle_exception(server, err, &exception); |
| 5959 | } while (exception.retry); |
| 5960 | return err; |
| 5961 | } |
| 5962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5964 | { |
| 5965 | struct inode *inode = state->inode; |
| 5966 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5967 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5968 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5970 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5971 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5972 | struct nfs_lockt_res res = { |
| 5973 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5974 | }; |
| 5975 | struct rpc_message msg = { |
| 5976 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5977 | .rpc_argp = &arg, |
| 5978 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | .rpc_cred = state->owner->so_cred, |
| 5980 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | struct nfs4_lock_state *lsp; |
| 5982 | int status; |
| 5983 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5984 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5985 | status = nfs4_set_lock_state(state, request); |
| 5986 | if (status != 0) |
| 5987 | goto out; |
| 5988 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5989 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5990 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5991 | 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] | 5992 | switch (status) { |
| 5993 | case 0: |
| 5994 | request->fl_type = F_UNLCK; |
| 5995 | break; |
| 5996 | case -NFS4ERR_DENIED: |
| 5997 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5999 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 6000 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 6001 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6002 | return status; |
| 6003 | } |
| 6004 | |
| 6005 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6006 | { |
| 6007 | struct nfs4_exception exception = { }; |
| 6008 | int err; |
| 6009 | |
| 6010 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6011 | err = _nfs4_proc_getlk(state, cmd, request); |
| 6012 | trace_nfs4_get_lock(request, state, cmd, err); |
| 6013 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | &exception); |
| 6015 | } while (exception.retry); |
| 6016 | return err; |
| 6017 | } |
| 6018 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6019 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6020 | struct nfs_locku_args arg; |
| 6021 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6022 | struct nfs4_lock_state *lsp; |
| 6023 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6024 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6025 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 6026 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6027 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6028 | }; |
| 6029 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6030 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 6031 | struct nfs_open_context *ctx, |
| 6032 | struct nfs4_lock_state *lsp, |
| 6033 | struct nfs_seqid *seqid) |
| 6034 | { |
| 6035 | struct nfs4_unlockdata *p; |
| 6036 | struct inode *inode = lsp->ls_state->inode; |
| 6037 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6038 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6039 | if (p == NULL) |
| 6040 | return NULL; |
| 6041 | p->arg.fh = NFS_FH(inode); |
| 6042 | p->arg.fl = &p->fl; |
| 6043 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6044 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6045 | p->lsp = lsp; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6046 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6047 | /* Ensure we don't close file until we're done freeing locks! */ |
| 6048 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6049 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6050 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6051 | p->server = NFS_SERVER(inode); |
| 6052 | return p; |
| 6053 | } |
| 6054 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6055 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6056 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6057 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6058 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6059 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6060 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6061 | put_nfs_open_context(calldata->ctx); |
| 6062 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6065 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6066 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6067 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6068 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6069 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 6070 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6071 | switch (task->tk_status) { |
| 6072 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6073 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6074 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6075 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 6076 | &calldata->res.stateid)) |
| 6077 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 6078 | case -NFS4ERR_ADMIN_REVOKED: |
| 6079 | case -NFS4ERR_EXPIRED: |
| 6080 | nfs4_free_revoked_stateid(calldata->server, |
| 6081 | &calldata->arg.stateid, |
| 6082 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 6083 | case -NFS4ERR_BAD_STATEID: |
| 6084 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6085 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6086 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 6087 | &calldata->lsp->ls_stateid)) |
| 6088 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6089 | break; |
| 6090 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6091 | if (nfs4_async_handle_error(task, calldata->server, |
| 6092 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6093 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6094 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 6095 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6098 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6099 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6100 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6102 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 6103 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 6104 | return; |
| 6105 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6106 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6107 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6108 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6109 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6110 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6111 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6112 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6113 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6114 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 6115 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6116 | &calldata->res.seq_res, |
| 6117 | task) != 0) |
| 6118 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6119 | return; |
| 6120 | out_no_action: |
| 6121 | task->tk_action = NULL; |
| 6122 | out_wait: |
| 6123 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6126 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 6127 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6128 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6129 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 6130 | }; |
| 6131 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6132 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 6133 | struct nfs_open_context *ctx, |
| 6134 | struct nfs4_lock_state *lsp, |
| 6135 | struct nfs_seqid *seqid) |
| 6136 | { |
| 6137 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6138 | struct rpc_message msg = { |
| 6139 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 6140 | .rpc_cred = ctx->cred, |
| 6141 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6142 | struct rpc_task_setup task_setup_data = { |
| 6143 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6144 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6145 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6146 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6147 | .flags = RPC_TASK_ASYNC, |
| 6148 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6149 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 6150 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 6151 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 6152 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6153 | /* Ensure this is an unlock - when canceling a lock, the |
| 6154 | * canceled lock is passed in, and it won't be an unlock. |
| 6155 | */ |
| 6156 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 6157 | if (fl->fl_flags & FL_CLOSE) |
| 6158 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 6159 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6160 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6161 | if (data == NULL) { |
| 6162 | nfs_free_seqid(seqid); |
| 6163 | return ERR_PTR(-ENOMEM); |
| 6164 | } |
| 6165 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6166 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6167 | msg.rpc_argp = &data->arg; |
| 6168 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6169 | task_setup_data.callback_data = data; |
| 6170 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6171 | } |
| 6172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6174 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6175 | struct inode *inode = state->inode; |
| 6176 | struct nfs4_state_owner *sp = state->owner; |
| 6177 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6178 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6179 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6180 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6181 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6182 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6183 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6185 | status = nfs4_set_lock_state(state, request); |
| 6186 | /* Unlock _before_ we do the RPC call */ |
| 6187 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6188 | /* Exclude nfs_delegation_claim_locks() */ |
| 6189 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6190 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6191 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6192 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6193 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6194 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6195 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6196 | } |
| 6197 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6198 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6199 | if (status != 0) |
| 6200 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6201 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6202 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6203 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6204 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6205 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6206 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6207 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6208 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6209 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6210 | 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] | 6211 | status = PTR_ERR(task); |
| 6212 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6213 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6214 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6215 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6216 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6217 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6218 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6219 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | } |
| 6221 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6222 | struct nfs4_lockdata { |
| 6223 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6224 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6225 | struct nfs4_lock_state *lsp; |
| 6226 | struct nfs_open_context *ctx; |
| 6227 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6228 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6229 | int rpc_status; |
| 6230 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6231 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6232 | }; |
| 6233 | |
| 6234 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6235 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6236 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6237 | { |
| 6238 | struct nfs4_lockdata *p; |
| 6239 | struct inode *inode = lsp->ls_state->inode; |
| 6240 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6241 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6242 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6243 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6244 | if (p == NULL) |
| 6245 | return NULL; |
| 6246 | |
| 6247 | p->arg.fh = NFS_FH(inode); |
| 6248 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6249 | 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] | 6250 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6251 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6252 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6253 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6254 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6255 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6256 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6257 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6258 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6259 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6260 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6261 | p->server = server; |
Elena Reshetova | 194bc1f | 2017-10-20 12:53:36 +0300 | [diff] [blame] | 6262 | refcount_inc(&lsp->ls_count); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6263 | p->ctx = get_nfs_open_context(ctx); |
| 6264 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6265 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6266 | out_free_seqid: |
| 6267 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6268 | out_free: |
| 6269 | kfree(p); |
| 6270 | return NULL; |
| 6271 | } |
| 6272 | |
| 6273 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6274 | { |
| 6275 | struct nfs4_lockdata *data = calldata; |
| 6276 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6278 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6279 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6280 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6281 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6282 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6283 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6284 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6285 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6286 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6287 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6288 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6289 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6290 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6291 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6292 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6293 | &data->lsp->ls_stateid); |
| 6294 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6295 | if (!nfs4_valid_open_stateid(state)) { |
| 6296 | data->rpc_status = -EBADF; |
| 6297 | task->tk_action = NULL; |
| 6298 | goto out_release_open_seqid; |
| 6299 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6300 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6301 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6302 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6303 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6304 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6305 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6306 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6307 | nfs_release_seqid(data->arg.open_seqid); |
| 6308 | out_release_lock_seqid: |
| 6309 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6310 | out_wait: |
| 6311 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6312 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6313 | } |
| 6314 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6315 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6316 | { |
| 6317 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6318 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6319 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6320 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6321 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6322 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6323 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6324 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6325 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6326 | switch (task->tk_status) { |
| 6327 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6328 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6329 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6330 | if (data->arg.new_lock) { |
| 6331 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6332 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6333 | rpc_restart_call_prepare(task); |
| 6334 | break; |
| 6335 | } |
| 6336 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6337 | if (data->arg.new_lock_owner != 0) { |
| 6338 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6339 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6340 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6341 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6342 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6343 | break; |
| 6344 | case -NFS4ERR_BAD_STATEID: |
| 6345 | case -NFS4ERR_OLD_STATEID: |
| 6346 | case -NFS4ERR_STALE_STATEID: |
| 6347 | case -NFS4ERR_EXPIRED: |
| 6348 | if (data->arg.new_lock_owner != 0) { |
| 6349 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6350 | &lsp->ls_state->open_stateid)) |
| 6351 | rpc_restart_call_prepare(task); |
| 6352 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6353 | &lsp->ls_stateid)) |
| 6354 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6355 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6356 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | static void nfs4_lock_release(void *calldata) |
| 6360 | { |
| 6361 | struct nfs4_lockdata *data = calldata; |
| 6362 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6363 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6364 | nfs_free_seqid(data->arg.open_seqid); |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6365 | if (data->cancelled) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6366 | struct rpc_task *task; |
| 6367 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6368 | data->arg.lock_seqid); |
| 6369 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6370 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6371 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6372 | } else |
| 6373 | nfs_free_seqid(data->arg.lock_seqid); |
| 6374 | nfs4_put_lock_state(data->lsp); |
| 6375 | put_nfs_open_context(data->ctx); |
| 6376 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6377 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6381 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6382 | .rpc_call_done = nfs4_lock_done, |
| 6383 | .rpc_release = nfs4_lock_release, |
| 6384 | }; |
| 6385 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6386 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6387 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6388 | switch (error) { |
| 6389 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6390 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6391 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6392 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6393 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6394 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6395 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6396 | break; |
| 6397 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6398 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6399 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6400 | }; |
| 6401 | } |
| 6402 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6403 | 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] | 6404 | { |
| 6405 | struct nfs4_lockdata *data; |
| 6406 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6407 | struct rpc_message msg = { |
| 6408 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6409 | .rpc_cred = state->owner->so_cred, |
| 6410 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6411 | struct rpc_task_setup task_setup_data = { |
| 6412 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6413 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6414 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6415 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6416 | .flags = RPC_TASK_ASYNC, |
| 6417 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6418 | int ret; |
| 6419 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6420 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6421 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6422 | fl->fl_u.nfs4_fl.owner, |
| 6423 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6424 | if (data == NULL) |
| 6425 | return -ENOMEM; |
| 6426 | if (IS_SETLKW(cmd)) |
| 6427 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6428 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6429 | msg.rpc_argp = &data->arg; |
| 6430 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6431 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6432 | if (recovery_type > NFS_LOCK_NEW) { |
| 6433 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6434 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6435 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6436 | } else |
| 6437 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6438 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6439 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6440 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6441 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6442 | if (ret == 0) { |
| 6443 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6444 | if (ret) |
| 6445 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6446 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6447 | } else |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 6448 | data->cancelled = true; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6449 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6450 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6451 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6452 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6456 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6457 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6458 | struct nfs4_exception exception = { |
| 6459 | .inode = state->inode, |
| 6460 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6461 | int err; |
| 6462 | |
| 6463 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6464 | /* Cache the lock if possible... */ |
| 6465 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6466 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6467 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6468 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6469 | break; |
| 6470 | nfs4_handle_exception(server, err, &exception); |
| 6471 | } while (exception.retry); |
| 6472 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6476 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6477 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6478 | struct nfs4_exception exception = { |
| 6479 | .inode = state->inode, |
| 6480 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6481 | int err; |
| 6482 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6483 | err = nfs4_set_lock_state(state, request); |
| 6484 | if (err != 0) |
| 6485 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6486 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6487 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6488 | return 0; |
| 6489 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6490 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6491 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6492 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6493 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6494 | switch (err) { |
| 6495 | default: |
| 6496 | goto out; |
| 6497 | case -NFS4ERR_GRACE: |
| 6498 | case -NFS4ERR_DELAY: |
| 6499 | nfs4_handle_exception(server, err, &exception); |
| 6500 | err = 0; |
| 6501 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6502 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6503 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6504 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6507 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6508 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6509 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6510 | struct nfs4_lock_state *lsp; |
| 6511 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6512 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6513 | status = nfs4_set_lock_state(state, request); |
| 6514 | if (status != 0) |
| 6515 | return status; |
| 6516 | lsp = request->fl_u.nfs4_fl.owner; |
| 6517 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6518 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6519 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6520 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6521 | } |
| 6522 | #endif |
| 6523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6524 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6525 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6526 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6527 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6528 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6529 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6531 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6532 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6533 | if (status < 0) |
| 6534 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6535 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6536 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6537 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6538 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6539 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6540 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6541 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6542 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6543 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6544 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6545 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6546 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6547 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6548 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6549 | out: |
| 6550 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6551 | return status; |
| 6552 | } |
| 6553 | |
| 6554 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6555 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6556 | struct nfs4_exception exception = { |
| 6557 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6558 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6559 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | int err; |
| 6561 | |
| 6562 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6563 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6564 | if (err == -NFS4ERR_DENIED) |
| 6565 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6567 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6568 | } while (exception.retry); |
| 6569 | return err; |
| 6570 | } |
| 6571 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6572 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6573 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6574 | |
| 6575 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6576 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6577 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6578 | { |
| 6579 | int status = -ERESTARTSYS; |
| 6580 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6581 | |
| 6582 | while(!signalled()) { |
| 6583 | status = nfs4_proc_setlk(state, cmd, request); |
| 6584 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6585 | break; |
| 6586 | freezable_schedule_timeout_interruptible(timeout); |
| 6587 | timeout *= 2; |
| 6588 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6589 | status = -ERESTARTSYS; |
| 6590 | } |
| 6591 | return status; |
| 6592 | } |
| 6593 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6594 | #ifdef CONFIG_NFS_V4_1 |
| 6595 | struct nfs4_lock_waiter { |
| 6596 | struct task_struct *task; |
| 6597 | struct inode *inode; |
| 6598 | struct nfs_lowner *owner; |
| 6599 | bool notified; |
| 6600 | }; |
| 6601 | |
| 6602 | static int |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6603 | 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] | 6604 | { |
| 6605 | int ret; |
| 6606 | struct cb_notify_lock_args *cbnl = key; |
| 6607 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6608 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6609 | *wowner = waiter->owner; |
| 6610 | |
| 6611 | /* Only wake if the callback was for the same owner */ |
| 6612 | if (lowner->clientid != wowner->clientid || |
| 6613 | lowner->id != wowner->id || |
| 6614 | lowner->s_dev != wowner->s_dev) |
| 6615 | return 0; |
| 6616 | |
| 6617 | /* Make sure it's for the right inode */ |
| 6618 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6619 | return 0; |
| 6620 | |
| 6621 | waiter->notified = true; |
| 6622 | |
| 6623 | /* override "private" so we can use default_wake_function */ |
| 6624 | wait->private = waiter->task; |
| 6625 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6626 | wait->private = waiter; |
| 6627 | return ret; |
| 6628 | } |
| 6629 | |
| 6630 | static int |
| 6631 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6632 | { |
| 6633 | int status = -ERESTARTSYS; |
| 6634 | unsigned long flags; |
| 6635 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6636 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6637 | struct nfs_client *clp = server->nfs_client; |
| 6638 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6639 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6640 | .id = lsp->ls_seqid.owner_id, |
| 6641 | .s_dev = server->s_dev }; |
| 6642 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6643 | .inode = state->inode, |
| 6644 | .owner = &owner, |
| 6645 | .notified = false }; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 6646 | wait_queue_entry_t wait; |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6647 | |
| 6648 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6649 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6650 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6651 | |
| 6652 | init_wait(&wait); |
| 6653 | wait.private = &waiter; |
| 6654 | wait.func = nfs4_wake_lock_waiter; |
| 6655 | add_wait_queue(q, &wait); |
| 6656 | |
| 6657 | while(!signalled()) { |
| 6658 | status = nfs4_proc_setlk(state, cmd, request); |
| 6659 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6660 | break; |
| 6661 | |
| 6662 | status = -ERESTARTSYS; |
| 6663 | spin_lock_irqsave(&q->lock, flags); |
| 6664 | if (waiter.notified) { |
| 6665 | spin_unlock_irqrestore(&q->lock, flags); |
| 6666 | continue; |
| 6667 | } |
| 6668 | set_current_state(TASK_INTERRUPTIBLE); |
| 6669 | spin_unlock_irqrestore(&q->lock, flags); |
| 6670 | |
Benjamin Coddington | b7dbcc0 | 2017-07-28 12:33:54 -0400 | [diff] [blame] | 6671 | freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT); |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | finish_wait(q, &wait); |
| 6675 | return status; |
| 6676 | } |
| 6677 | #else /* !CONFIG_NFS_V4_1 */ |
| 6678 | static inline int |
| 6679 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6680 | { |
| 6681 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6682 | } |
| 6683 | #endif |
| 6684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6685 | static int |
| 6686 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6687 | { |
| 6688 | struct nfs_open_context *ctx; |
| 6689 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6690 | int status; |
| 6691 | |
| 6692 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6693 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6694 | state = ctx->state; |
| 6695 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6696 | if (IS_GETLK(cmd)) { |
| 6697 | if (state != NULL) |
| 6698 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6699 | return 0; |
| 6700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6701 | |
| 6702 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6703 | return -EINVAL; |
| 6704 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6705 | if (request->fl_type == F_UNLCK) { |
| 6706 | if (state != NULL) |
| 6707 | return nfs4_proc_unlck(state, cmd, request); |
| 6708 | return 0; |
| 6709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6710 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6711 | if (state == NULL) |
| 6712 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6713 | |
| 6714 | if ((request->fl_flags & FL_POSIX) && |
| 6715 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6716 | return -ENOLCK; |
| 6717 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6718 | status = nfs4_set_lock_state(state, request); |
| 6719 | if (status != 0) |
| 6720 | return status; |
| 6721 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6722 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | } |
| 6724 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6725 | 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] | 6726 | { |
| 6727 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6728 | int err; |
| 6729 | |
| 6730 | err = nfs4_set_lock_state(state, fl); |
| 6731 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6732 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6733 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6734 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6735 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6736 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6737 | struct nfs_release_lockowner_data { |
| 6738 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6739 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6740 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6741 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6742 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6743 | }; |
| 6744 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6745 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6746 | { |
| 6747 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6748 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6749 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6750 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6751 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6752 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6753 | } |
| 6754 | |
| 6755 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6756 | { |
| 6757 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6758 | struct nfs_server *server = data->server; |
| 6759 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6760 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6761 | |
| 6762 | switch (task->tk_status) { |
| 6763 | case 0: |
| 6764 | renew_lease(server, data->timestamp); |
| 6765 | break; |
| 6766 | case -NFS4ERR_STALE_CLIENTID: |
| 6767 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6768 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6769 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6770 | case -NFS4ERR_LEASE_MOVED: |
| 6771 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6772 | if (nfs4_async_handle_error(task, server, |
| 6773 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6774 | rpc_restart_call_prepare(task); |
| 6775 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6776 | } |
| 6777 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6778 | static void nfs4_release_lockowner_release(void *calldata) |
| 6779 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6780 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6781 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6782 | kfree(calldata); |
| 6783 | } |
| 6784 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6785 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6786 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6787 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6788 | .rpc_release = nfs4_release_lockowner_release, |
| 6789 | }; |
| 6790 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6791 | static void |
| 6792 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6793 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6794 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6795 | struct rpc_message msg = { |
| 6796 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6797 | }; |
| 6798 | |
| 6799 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6800 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6801 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6802 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6803 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6804 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6805 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6806 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6807 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6808 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6809 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6810 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6811 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6812 | msg.rpc_resp = &data->res; |
| 6813 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6814 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6815 | } |
| 6816 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6817 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6818 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6819 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6820 | struct dentry *unused, struct inode *inode, |
| 6821 | const char *key, const void *buf, |
| 6822 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6823 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6824 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6825 | } |
| 6826 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6827 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6828 | struct dentry *unused, struct inode *inode, |
| 6829 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6830 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6831 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6832 | } |
| 6833 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6834 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6835 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6836 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6839 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6840 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6841 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6842 | struct dentry *unused, struct inode *inode, |
| 6843 | const char *key, const void *buf, |
| 6844 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6845 | { |
| 6846 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6847 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6848 | |
| 6849 | return -EOPNOTSUPP; |
| 6850 | } |
| 6851 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6852 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6853 | struct dentry *unused, struct inode *inode, |
| 6854 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6855 | { |
| 6856 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6857 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6858 | return -EOPNOTSUPP; |
| 6859 | } |
| 6860 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6861 | static ssize_t |
| 6862 | 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] | 6863 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6864 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6865 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6866 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6867 | len = security_inode_listsecurity(inode, list, list_len); |
| 6868 | if (list_len && len > list_len) |
| 6869 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6870 | } |
| 6871 | return len; |
| 6872 | } |
| 6873 | |
| 6874 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6875 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6876 | .get = nfs4_xattr_get_nfs4_label, |
| 6877 | .set = nfs4_xattr_set_nfs4_label, |
| 6878 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6879 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6880 | #else |
| 6881 | |
| 6882 | static ssize_t |
| 6883 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6884 | { |
| 6885 | return 0; |
| 6886 | } |
| 6887 | |
| 6888 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6889 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6890 | /* |
| 6891 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6892 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6893 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6894 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6895 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6896 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6897 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6898 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6899 | return; |
| 6900 | |
| 6901 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6902 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6903 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6904 | fattr->nlink = 2; |
| 6905 | } |
| 6906 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6907 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6908 | const struct qstr *name, |
| 6909 | struct nfs4_fs_locations *fs_locations, |
| 6910 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6911 | { |
| 6912 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6913 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6914 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6915 | }; |
| 6916 | struct nfs4_fs_locations_arg args = { |
| 6917 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6918 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6919 | .page = page, |
| 6920 | .bitmask = bitmask, |
| 6921 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6922 | struct nfs4_fs_locations_res res = { |
| 6923 | .fs_locations = fs_locations, |
| 6924 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6925 | struct rpc_message msg = { |
| 6926 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6927 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6928 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6929 | }; |
| 6930 | int status; |
| 6931 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6932 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6933 | |
| 6934 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6935 | * is not supported */ |
| 6936 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6937 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6938 | else |
| 6939 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6940 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6941 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6942 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6943 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6944 | 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] | 6945 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6946 | return status; |
| 6947 | } |
| 6948 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6949 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6950 | const struct qstr *name, |
| 6951 | struct nfs4_fs_locations *fs_locations, |
| 6952 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6953 | { |
| 6954 | struct nfs4_exception exception = { }; |
| 6955 | int err; |
| 6956 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6957 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6958 | fs_locations, page); |
| 6959 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6960 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6961 | &exception); |
| 6962 | } while (exception.retry); |
| 6963 | return err; |
| 6964 | } |
| 6965 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6966 | /* |
| 6967 | * This operation also signals the server that this client is |
| 6968 | * performing migration recovery. The server can stop returning |
| 6969 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6970 | * appended to this compound to identify the client ID which is |
| 6971 | * performing recovery. |
| 6972 | */ |
| 6973 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6974 | struct nfs4_fs_locations *locations, |
| 6975 | struct page *page, struct rpc_cred *cred) |
| 6976 | { |
| 6977 | struct nfs_server *server = NFS_SERVER(inode); |
| 6978 | struct rpc_clnt *clnt = server->client; |
| 6979 | u32 bitmask[2] = { |
| 6980 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6981 | }; |
| 6982 | struct nfs4_fs_locations_arg args = { |
| 6983 | .clientid = server->nfs_client->cl_clientid, |
| 6984 | .fh = NFS_FH(inode), |
| 6985 | .page = page, |
| 6986 | .bitmask = bitmask, |
| 6987 | .migration = 1, /* skip LOOKUP */ |
| 6988 | .renew = 1, /* append RENEW */ |
| 6989 | }; |
| 6990 | struct nfs4_fs_locations_res res = { |
| 6991 | .fs_locations = locations, |
| 6992 | .migration = 1, |
| 6993 | .renew = 1, |
| 6994 | }; |
| 6995 | struct rpc_message msg = { |
| 6996 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6997 | .rpc_argp = &args, |
| 6998 | .rpc_resp = &res, |
| 6999 | .rpc_cred = cred, |
| 7000 | }; |
| 7001 | unsigned long now = jiffies; |
| 7002 | int status; |
| 7003 | |
| 7004 | nfs_fattr_init(&locations->fattr); |
| 7005 | locations->server = server; |
| 7006 | locations->nlocations = 0; |
| 7007 | |
| 7008 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7009 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7010 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7011 | &args.seq_args, &res.seq_res); |
| 7012 | if (status) |
| 7013 | return status; |
| 7014 | |
| 7015 | renew_lease(server, now); |
| 7016 | return 0; |
| 7017 | } |
| 7018 | |
| 7019 | #ifdef CONFIG_NFS_V4_1 |
| 7020 | |
| 7021 | /* |
| 7022 | * This operation also signals the server that this client is |
| 7023 | * performing migration recovery. The server can stop asserting |
| 7024 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 7025 | * performing this operation is identified in the SEQUENCE |
| 7026 | * operation in this compound. |
| 7027 | * |
| 7028 | * When the client supports GETATTR(fs_locations_info), it can |
| 7029 | * be plumbed in here. |
| 7030 | */ |
| 7031 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 7032 | struct nfs4_fs_locations *locations, |
| 7033 | struct page *page, struct rpc_cred *cred) |
| 7034 | { |
| 7035 | struct nfs_server *server = NFS_SERVER(inode); |
| 7036 | struct rpc_clnt *clnt = server->client; |
| 7037 | u32 bitmask[2] = { |
| 7038 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 7039 | }; |
| 7040 | struct nfs4_fs_locations_arg args = { |
| 7041 | .fh = NFS_FH(inode), |
| 7042 | .page = page, |
| 7043 | .bitmask = bitmask, |
| 7044 | .migration = 1, /* skip LOOKUP */ |
| 7045 | }; |
| 7046 | struct nfs4_fs_locations_res res = { |
| 7047 | .fs_locations = locations, |
| 7048 | .migration = 1, |
| 7049 | }; |
| 7050 | struct rpc_message msg = { |
| 7051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 7052 | .rpc_argp = &args, |
| 7053 | .rpc_resp = &res, |
| 7054 | .rpc_cred = cred, |
| 7055 | }; |
| 7056 | int status; |
| 7057 | |
| 7058 | nfs_fattr_init(&locations->fattr); |
| 7059 | locations->server = server; |
| 7060 | locations->nlocations = 0; |
| 7061 | |
| 7062 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7063 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7064 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7065 | &args.seq_args, &res.seq_res); |
| 7066 | if (status == NFS4_OK && |
| 7067 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7068 | status = -NFS4ERR_LEASE_MOVED; |
| 7069 | return status; |
| 7070 | } |
| 7071 | |
| 7072 | #endif /* CONFIG_NFS_V4_1 */ |
| 7073 | |
| 7074 | /** |
| 7075 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 7076 | * @inode: inode on FSID that is migrating |
| 7077 | * @locations: result of query |
| 7078 | * @page: buffer |
| 7079 | * @cred: credential to use for this operation |
| 7080 | * |
| 7081 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 7082 | * operation failed, or a negative errno if a local error occurred. |
| 7083 | * |
| 7084 | * On success, "locations" is filled in, but if the server has |
| 7085 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 7086 | * asserted. |
| 7087 | * |
| 7088 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 7089 | * from this client that require migration recovery. |
| 7090 | */ |
| 7091 | int nfs4_proc_get_locations(struct inode *inode, |
| 7092 | struct nfs4_fs_locations *locations, |
| 7093 | struct page *page, struct rpc_cred *cred) |
| 7094 | { |
| 7095 | struct nfs_server *server = NFS_SERVER(inode); |
| 7096 | struct nfs_client *clp = server->nfs_client; |
| 7097 | const struct nfs4_mig_recovery_ops *ops = |
| 7098 | clp->cl_mvops->mig_recovery_ops; |
| 7099 | struct nfs4_exception exception = { }; |
| 7100 | int status; |
| 7101 | |
| 7102 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7103 | (unsigned long long)server->fsid.major, |
| 7104 | (unsigned long long)server->fsid.minor, |
| 7105 | clp->cl_hostname); |
| 7106 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7107 | |
| 7108 | do { |
| 7109 | status = ops->get_locations(inode, locations, page, cred); |
| 7110 | if (status != -NFS4ERR_DELAY) |
| 7111 | break; |
| 7112 | nfs4_handle_exception(server, status, &exception); |
| 7113 | } while (exception.retry); |
| 7114 | return status; |
| 7115 | } |
| 7116 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 7117 | /* |
| 7118 | * This operation also signals the server that this client is |
| 7119 | * performing "lease moved" recovery. The server can stop |
| 7120 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 7121 | * is appended to this compound to identify the client ID which is |
| 7122 | * performing recovery. |
| 7123 | */ |
| 7124 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7125 | { |
| 7126 | struct nfs_server *server = NFS_SERVER(inode); |
| 7127 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 7128 | struct rpc_clnt *clnt = server->client; |
| 7129 | struct nfs4_fsid_present_arg args = { |
| 7130 | .fh = NFS_FH(inode), |
| 7131 | .clientid = clp->cl_clientid, |
| 7132 | .renew = 1, /* append RENEW */ |
| 7133 | }; |
| 7134 | struct nfs4_fsid_present_res res = { |
| 7135 | .renew = 1, |
| 7136 | }; |
| 7137 | struct rpc_message msg = { |
| 7138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7139 | .rpc_argp = &args, |
| 7140 | .rpc_resp = &res, |
| 7141 | .rpc_cred = cred, |
| 7142 | }; |
| 7143 | unsigned long now = jiffies; |
| 7144 | int status; |
| 7145 | |
| 7146 | res.fh = nfs_alloc_fhandle(); |
| 7147 | if (res.fh == NULL) |
| 7148 | return -ENOMEM; |
| 7149 | |
| 7150 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7151 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7152 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7153 | &args.seq_args, &res.seq_res); |
| 7154 | nfs_free_fhandle(res.fh); |
| 7155 | if (status) |
| 7156 | return status; |
| 7157 | |
| 7158 | do_renew_lease(clp, 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 "lease moved" recovery. The server can stop asserting |
| 7167 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7168 | * this operation is identified in the SEQUENCE operation in this |
| 7169 | * compound. |
| 7170 | */ |
| 7171 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7172 | { |
| 7173 | struct nfs_server *server = NFS_SERVER(inode); |
| 7174 | struct rpc_clnt *clnt = server->client; |
| 7175 | struct nfs4_fsid_present_arg args = { |
| 7176 | .fh = NFS_FH(inode), |
| 7177 | }; |
| 7178 | struct nfs4_fsid_present_res res = { |
| 7179 | }; |
| 7180 | struct rpc_message msg = { |
| 7181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7182 | .rpc_argp = &args, |
| 7183 | .rpc_resp = &res, |
| 7184 | .rpc_cred = cred, |
| 7185 | }; |
| 7186 | int status; |
| 7187 | |
| 7188 | res.fh = nfs_alloc_fhandle(); |
| 7189 | if (res.fh == NULL) |
| 7190 | return -ENOMEM; |
| 7191 | |
| 7192 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7193 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7194 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7195 | &args.seq_args, &res.seq_res); |
| 7196 | nfs_free_fhandle(res.fh); |
| 7197 | if (status == NFS4_OK && |
| 7198 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7199 | status = -NFS4ERR_LEASE_MOVED; |
| 7200 | return status; |
| 7201 | } |
| 7202 | |
| 7203 | #endif /* CONFIG_NFS_V4_1 */ |
| 7204 | |
| 7205 | /** |
| 7206 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7207 | * @inode: inode on FSID to check |
| 7208 | * @cred: credential to use for this operation |
| 7209 | * |
| 7210 | * Server indicates whether the FSID is present, moved, or not |
| 7211 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7212 | * condition for this client ID. |
| 7213 | * |
| 7214 | * Returns NFS4_OK if the FSID is present on this server, |
| 7215 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7216 | * NFS4ERR code if some error occurred on the server, or a |
| 7217 | * negative errno if a local failure occurred. |
| 7218 | */ |
| 7219 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7220 | { |
| 7221 | struct nfs_server *server = NFS_SERVER(inode); |
| 7222 | struct nfs_client *clp = server->nfs_client; |
| 7223 | const struct nfs4_mig_recovery_ops *ops = |
| 7224 | clp->cl_mvops->mig_recovery_ops; |
| 7225 | struct nfs4_exception exception = { }; |
| 7226 | int status; |
| 7227 | |
| 7228 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7229 | (unsigned long long)server->fsid.major, |
| 7230 | (unsigned long long)server->fsid.minor, |
| 7231 | clp->cl_hostname); |
| 7232 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7233 | |
| 7234 | do { |
| 7235 | status = ops->fsid_present(inode, cred); |
| 7236 | if (status != -NFS4ERR_DELAY) |
| 7237 | break; |
| 7238 | nfs4_handle_exception(server, status, &exception); |
| 7239 | } while (exception.retry); |
| 7240 | return status; |
| 7241 | } |
| 7242 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7243 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7244 | * If 'use_integrity' is true and the state managment nfs_client |
| 7245 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7246 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7247 | * Considerations sections. Otherwise, just use the user cred with the |
| 7248 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7249 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7250 | 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] | 7251 | { |
| 7252 | int status; |
| 7253 | struct nfs4_secinfo_arg args = { |
| 7254 | .dir_fh = NFS_FH(dir), |
| 7255 | .name = name, |
| 7256 | }; |
| 7257 | struct nfs4_secinfo_res res = { |
| 7258 | .flavors = flavors, |
| 7259 | }; |
| 7260 | struct rpc_message msg = { |
| 7261 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7262 | .rpc_argp = &args, |
| 7263 | .rpc_resp = &res, |
| 7264 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7265 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7266 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7267 | |
| 7268 | if (use_integrity) { |
| 7269 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7270 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7271 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7272 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7273 | |
| 7274 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7275 | |
| 7276 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7277 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7278 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7279 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7280 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7281 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7282 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7283 | if (cred) |
| 7284 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7285 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7286 | return status; |
| 7287 | } |
| 7288 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7289 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7290 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7291 | { |
| 7292 | struct nfs4_exception exception = { }; |
| 7293 | int err; |
| 7294 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7295 | err = -NFS4ERR_WRONGSEC; |
| 7296 | |
| 7297 | /* try to use integrity protection with machine cred */ |
| 7298 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7299 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7300 | |
| 7301 | /* |
| 7302 | * if unable to use integrity protection, or SECINFO with |
| 7303 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7304 | * disallowed by spec, but exists in deployed servers) use |
| 7305 | * the current filesystem's rpc_client and the user cred. |
| 7306 | */ |
| 7307 | if (err == -NFS4ERR_WRONGSEC) |
| 7308 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7309 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7310 | trace_nfs4_secinfo(dir, name, err); |
| 7311 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7312 | &exception); |
| 7313 | } while (exception.retry); |
| 7314 | return err; |
| 7315 | } |
| 7316 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7317 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7318 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7319 | * Check the exchange flags returned by the server for invalid flags, having |
| 7320 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7321 | * DS flags set. |
| 7322 | */ |
| 7323 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7324 | { |
| 7325 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7326 | goto out_inval; |
| 7327 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7328 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7329 | goto out_inval; |
| 7330 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7331 | goto out_inval; |
| 7332 | return NFS_OK; |
| 7333 | out_inval: |
| 7334 | return -NFS4ERR_INVAL; |
| 7335 | } |
| 7336 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7337 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7338 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7339 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7340 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7341 | if (a->server_scope_sz != b->server_scope_sz) |
| 7342 | return false; |
| 7343 | 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] | 7344 | } |
| 7345 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7346 | static void |
| 7347 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7348 | { |
| 7349 | } |
| 7350 | |
| 7351 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7352 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7353 | }; |
| 7354 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7355 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7356 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7357 | * |
| 7358 | * The 4.1 client currently uses the same TCP connection for the |
| 7359 | * fore and backchannel. |
| 7360 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7361 | static |
| 7362 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7363 | struct rpc_xprt *xprt, |
| 7364 | struct nfs_client *clp, |
| 7365 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7366 | { |
| 7367 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7368 | struct nfs41_bind_conn_to_session_args args = { |
| 7369 | .client = clp, |
| 7370 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7371 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7372 | struct nfs41_bind_conn_to_session_res res; |
| 7373 | struct rpc_message msg = { |
| 7374 | .rpc_proc = |
| 7375 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7376 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7377 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7378 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7379 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7380 | struct rpc_task_setup task_setup_data = { |
| 7381 | .rpc_client = clnt, |
| 7382 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7383 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7384 | .rpc_message = &msg, |
| 7385 | .flags = RPC_TASK_TIMEOUT, |
| 7386 | }; |
| 7387 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7388 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7389 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7390 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7391 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7392 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7393 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7394 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7395 | args.dir = NFS4_CDFC4_FORE; |
| 7396 | |
| 7397 | task = rpc_run_task(&task_setup_data); |
| 7398 | if (!IS_ERR(task)) { |
| 7399 | status = task->tk_status; |
| 7400 | rpc_put_task(task); |
| 7401 | } else |
| 7402 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7403 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7404 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7405 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7406 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7407 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7408 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7409 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7410 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7411 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7412 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7413 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7414 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7415 | 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] | 7416 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7417 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7418 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7419 | } |
| 7420 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7421 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7422 | return status; |
| 7423 | } |
| 7424 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7425 | struct rpc_bind_conn_calldata { |
| 7426 | struct nfs_client *clp; |
| 7427 | struct rpc_cred *cred; |
| 7428 | }; |
| 7429 | |
| 7430 | static int |
| 7431 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7432 | struct rpc_xprt *xprt, |
| 7433 | void *calldata) |
| 7434 | { |
| 7435 | struct rpc_bind_conn_calldata *p = calldata; |
| 7436 | |
| 7437 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7438 | } |
| 7439 | |
| 7440 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7441 | { |
| 7442 | struct rpc_bind_conn_calldata data = { |
| 7443 | .clp = clp, |
| 7444 | .cred = cred, |
| 7445 | }; |
| 7446 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7447 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7448 | } |
| 7449 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7450 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7451 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7452 | * 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] | 7453 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7454 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7455 | .how = SP4_MACH_CRED, |
| 7456 | .enforce.u.words = { |
| 7457 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7458 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7459 | 1 << (OP_CREATE_SESSION - 32) | |
| 7460 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7461 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7462 | }, |
| 7463 | .allow.u.words = { |
| 7464 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7465 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7466 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7467 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7468 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7469 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7470 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7471 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7472 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7473 | 1 << (OP_FREE_STATEID - 32) | |
| 7474 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7475 | } |
| 7476 | }; |
| 7477 | |
| 7478 | /* |
| 7479 | * Select the state protection mode for client `clp' given the server results |
| 7480 | * from exchange_id in `sp'. |
| 7481 | * |
| 7482 | * Returns 0 on success, negative errno otherwise. |
| 7483 | */ |
| 7484 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7485 | struct nfs41_state_protection *sp) |
| 7486 | { |
| 7487 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7488 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7489 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7490 | 1 << (OP_CREATE_SESSION - 32) | |
| 7491 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7492 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7493 | }; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7494 | unsigned long flags = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7495 | unsigned int i; |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7496 | int ret = 0; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7497 | |
| 7498 | if (sp->how == SP4_MACH_CRED) { |
| 7499 | /* Print state protect result */ |
| 7500 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7501 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7502 | if (test_bit(i, sp->enforce.u.longs)) |
| 7503 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7504 | if (test_bit(i, sp->allow.u.longs)) |
| 7505 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7506 | } |
| 7507 | |
| 7508 | /* make sure nothing is on enforce list that isn't supported */ |
| 7509 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7510 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7511 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7512 | ret = -EINVAL; |
| 7513 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | /* |
| 7518 | * Minimal mode - state operations are allowed to use machine |
| 7519 | * credential. Note this already happens by default, so the |
| 7520 | * client doesn't have to do anything more than the negotiation. |
| 7521 | * |
| 7522 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7523 | * we're already using the machine cred for exchange_id |
| 7524 | * and will never use a different cred. |
| 7525 | */ |
| 7526 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7527 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7528 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7529 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7530 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7531 | dfprintk(MOUNT, " minimal mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7532 | __set_bit(NFS_SP4_MACH_CRED_MINIMAL, &flags); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7533 | } else { |
| 7534 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7535 | ret = -EINVAL; |
| 7536 | goto out; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7537 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7538 | |
| 7539 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7540 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7541 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7542 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7543 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7544 | __set_bit(NFS_SP4_MACH_CRED_CLEANUP, &flags); |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7545 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7546 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7547 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7548 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7549 | __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, &flags); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7550 | } |
| 7551 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7552 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7553 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7554 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7555 | __set_bit(NFS_SP4_MACH_CRED_SECINFO, &flags); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7556 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7557 | |
| 7558 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7559 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7560 | dfprintk(MOUNT, " stateid mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7561 | __set_bit(NFS_SP4_MACH_CRED_STATEID, &flags); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7562 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7563 | |
| 7564 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7565 | dfprintk(MOUNT, " write mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7566 | __set_bit(NFS_SP4_MACH_CRED_WRITE, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7570 | dfprintk(MOUNT, " commit mode enabled\n"); |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7571 | __set_bit(NFS_SP4_MACH_CRED_COMMIT, &flags); |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7572 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7573 | } |
Trond Myklebust | 937e313 | 2017-08-01 07:32:50 -0400 | [diff] [blame] | 7574 | out: |
| 7575 | clp->cl_sp4_flags = flags; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7576 | return 0; |
| 7577 | } |
| 7578 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7579 | struct nfs41_exchange_id_data { |
| 7580 | struct nfs41_exchange_id_res res; |
| 7581 | struct nfs41_exchange_id_args args; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7582 | }; |
| 7583 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7584 | static void nfs4_exchange_id_release(void *data) |
| 7585 | { |
| 7586 | struct nfs41_exchange_id_data *cdata = |
| 7587 | (struct nfs41_exchange_id_data *)data; |
| 7588 | |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7589 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7590 | kfree(cdata->res.impl_id); |
| 7591 | kfree(cdata->res.server_scope); |
| 7592 | kfree(cdata->res.server_owner); |
| 7593 | kfree(cdata); |
| 7594 | } |
| 7595 | |
| 7596 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7597 | .rpc_release = nfs4_exchange_id_release, |
| 7598 | }; |
| 7599 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7600 | /* |
| 7601 | * _nfs4_proc_exchange_id() |
| 7602 | * |
| 7603 | * Wrapper for EXCHANGE_ID operation. |
| 7604 | */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7605 | static struct rpc_task * |
| 7606 | nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7607 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7608 | { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7609 | struct rpc_message msg = { |
| 7610 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7611 | .rpc_cred = cred, |
| 7612 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7613 | struct rpc_task_setup task_setup_data = { |
| 7614 | .rpc_client = clp->cl_rpcclient, |
| 7615 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7616 | .rpc_message = &msg, |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7617 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7618 | }; |
| 7619 | struct nfs41_exchange_id_data *calldata; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7620 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7621 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 7622 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7623 | return ERR_PTR(-EIO); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7624 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7625 | status = -ENOMEM; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7626 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7627 | if (!calldata) |
| 7628 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7629 | |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7630 | nfs4_init_boot_verifier(clp, &calldata->args.verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7631 | |
| 7632 | status = nfs4_init_uniform_client_string(clp); |
| 7633 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7634 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7635 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7636 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7637 | GFP_NOFS); |
| 7638 | status = -ENOMEM; |
| 7639 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7640 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7641 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7642 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7643 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7644 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7645 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7646 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7647 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7648 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7649 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7650 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7651 | switch (sp4_how) { |
| 7652 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7653 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7654 | break; |
| 7655 | |
| 7656 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7657 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7658 | break; |
| 7659 | |
| 7660 | default: |
| 7661 | /* unsupported! */ |
| 7662 | WARN_ON_ONCE(1); |
| 7663 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7664 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7665 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7666 | if (xprt) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7667 | task_setup_data.rpc_xprt = xprt; |
Trond Myklebust | d9cb733 | 2017-08-01 16:02:48 -0400 | [diff] [blame] | 7668 | task_setup_data.flags |= RPC_TASK_SOFTCONN; |
Trond Myklebust | fd40559 | 2017-08-01 16:02:47 -0400 | [diff] [blame] | 7669 | memcpy(calldata->args.verifier.data, clp->cl_confirm.data, |
| 7670 | sizeof(calldata->args.verifier.data)); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7671 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7672 | calldata->args.client = clp; |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7673 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7674 | EXCHGID4_FLAG_BIND_PRINC_STATEID; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7675 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
Trond Myklebust | bfab281 | 2017-08-01 08:17:34 -0400 | [diff] [blame] | 7676 | calldata->args.flags |= EXCHGID4_FLAG_SUPP_MOVED_MIGR; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7677 | #endif |
| 7678 | msg.rpc_argp = &calldata->args; |
| 7679 | msg.rpc_resp = &calldata->res; |
| 7680 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7681 | |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7682 | return rpc_run_task(&task_setup_data); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7683 | |
| 7684 | out_impl_id: |
| 7685 | kfree(calldata->res.impl_id); |
| 7686 | out_server_scope: |
| 7687 | kfree(calldata->res.server_scope); |
| 7688 | out_server_owner: |
| 7689 | kfree(calldata->res.server_owner); |
| 7690 | out_calldata: |
| 7691 | kfree(calldata); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7692 | out: |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7693 | nfs_put_client(clp); |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7694 | return ERR_PTR(status); |
| 7695 | } |
| 7696 | |
| 7697 | /* |
| 7698 | * _nfs4_proc_exchange_id() |
| 7699 | * |
| 7700 | * Wrapper for EXCHANGE_ID operation. |
| 7701 | */ |
| 7702 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
| 7703 | u32 sp4_how) |
| 7704 | { |
| 7705 | struct rpc_task *task; |
| 7706 | struct nfs41_exchange_id_args *argp; |
| 7707 | struct nfs41_exchange_id_res *resp; |
| 7708 | int status; |
| 7709 | |
| 7710 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
| 7711 | if (IS_ERR(task)) |
| 7712 | return PTR_ERR(task); |
| 7713 | |
| 7714 | argp = task->tk_msg.rpc_argp; |
| 7715 | resp = task->tk_msg.rpc_resp; |
| 7716 | status = task->tk_status; |
| 7717 | if (status != 0) |
| 7718 | goto out; |
| 7719 | |
| 7720 | status = nfs4_check_cl_exchange_flags(resp->flags); |
| 7721 | if (status != 0) |
| 7722 | goto out; |
| 7723 | |
| 7724 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
| 7725 | if (status != 0) |
| 7726 | goto out; |
| 7727 | |
| 7728 | clp->cl_clientid = resp->clientid; |
| 7729 | clp->cl_exchange_flags = resp->flags; |
| 7730 | clp->cl_seqid = resp->seqid; |
| 7731 | /* Client ID is not confirmed */ |
| 7732 | if (!(resp->flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 7733 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7734 | &clp->cl_session->session_state); |
| 7735 | |
| 7736 | if (clp->cl_serverscope != NULL && |
| 7737 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7738 | resp->server_scope)) { |
| 7739 | dprintk("%s: server_scope mismatch detected\n", |
| 7740 | __func__); |
| 7741 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7742 | } |
| 7743 | |
| 7744 | swap(clp->cl_serverowner, resp->server_owner); |
| 7745 | swap(clp->cl_serverscope, resp->server_scope); |
| 7746 | swap(clp->cl_implid, resp->impl_id); |
| 7747 | |
| 7748 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7749 | memcpy(clp->cl_confirm.data, argp->verifier.data, |
| 7750 | sizeof(clp->cl_confirm.data)); |
| 7751 | out: |
| 7752 | trace_nfs4_exchange_id(clp, status); |
| 7753 | rpc_put_task(task); |
| 7754 | return status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7755 | } |
| 7756 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7757 | /* |
| 7758 | * nfs4_proc_exchange_id() |
| 7759 | * |
| 7760 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7761 | * |
| 7762 | * Since the clientid has expired, all compounds using sessions |
| 7763 | * associated with the stale clientid will be returning |
| 7764 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7765 | * be in some phase of session reset. |
| 7766 | * |
| 7767 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7768 | */ |
| 7769 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7770 | { |
| 7771 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7772 | int status; |
| 7773 | |
| 7774 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7775 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7776 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7777 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7778 | if (!status) |
| 7779 | return 0; |
| 7780 | } |
| 7781 | |
| 7782 | /* try SP4_NONE */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7783 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7784 | } |
| 7785 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7786 | /** |
| 7787 | * nfs4_test_session_trunk |
| 7788 | * |
| 7789 | * This is an add_xprt_test() test function called from |
| 7790 | * rpc_clnt_setup_test_and_add_xprt. |
| 7791 | * |
| 7792 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7793 | * and is dereferrenced in nfs4_exchange_id_release |
| 7794 | * |
| 7795 | * Upon success, add the new transport to the rpc_clnt |
| 7796 | * |
| 7797 | * @clnt: struct rpc_clnt to get new transport |
| 7798 | * @xprt: the rpc_xprt to test |
| 7799 | * @data: call data for _nfs4_proc_exchange_id. |
| 7800 | */ |
| 7801 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7802 | void *data) |
| 7803 | { |
| 7804 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7805 | struct rpc_task *task; |
| 7806 | int status; |
| 7807 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7808 | u32 sp4_how; |
| 7809 | |
| 7810 | dprintk("--> %s try %s\n", __func__, |
| 7811 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7812 | |
| 7813 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7814 | |
| 7815 | /* Test connection for session trunking. Async exchange_id call */ |
Trond Myklebust | 9c760d1 | 2017-07-31 18:38:50 -0400 | [diff] [blame] | 7816 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7817 | if (IS_ERR(task)) |
| 7818 | return PTR_ERR(task); |
| 7819 | |
| 7820 | status = task->tk_status; |
| 7821 | if (status == 0) |
| 7822 | status = nfs4_detect_session_trunking(adata->clp, |
| 7823 | task->tk_msg.rpc_resp, xprt); |
| 7824 | |
| 7825 | rpc_put_task(task); |
| 7826 | return status; |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7827 | } |
| 7828 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7829 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7830 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7831 | struct rpc_cred *cred) |
| 7832 | { |
| 7833 | struct rpc_message msg = { |
| 7834 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7835 | .rpc_argp = clp, |
| 7836 | .rpc_cred = cred, |
| 7837 | }; |
| 7838 | int status; |
| 7839 | |
| 7840 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7841 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7842 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7843 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7844 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7845 | return status; |
| 7846 | } |
| 7847 | |
| 7848 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7849 | struct rpc_cred *cred) |
| 7850 | { |
| 7851 | unsigned int loop; |
| 7852 | int ret; |
| 7853 | |
| 7854 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7855 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7856 | switch (ret) { |
| 7857 | case -NFS4ERR_DELAY: |
| 7858 | case -NFS4ERR_CLIENTID_BUSY: |
| 7859 | ssleep(1); |
| 7860 | break; |
| 7861 | default: |
| 7862 | return ret; |
| 7863 | } |
| 7864 | } |
| 7865 | return 0; |
| 7866 | } |
| 7867 | |
| 7868 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7869 | { |
| 7870 | struct rpc_cred *cred; |
| 7871 | int ret = 0; |
| 7872 | |
| 7873 | if (clp->cl_mvops->minor_version < 1) |
| 7874 | goto out; |
| 7875 | if (clp->cl_exchange_flags == 0) |
| 7876 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7877 | if (clp->cl_preserve_clid) |
| 7878 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7879 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7880 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7881 | if (cred) |
| 7882 | put_rpccred(cred); |
| 7883 | switch (ret) { |
| 7884 | case 0: |
| 7885 | case -NFS4ERR_STALE_CLIENTID: |
| 7886 | clp->cl_exchange_flags = 0; |
| 7887 | } |
| 7888 | out: |
| 7889 | return ret; |
| 7890 | } |
| 7891 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7892 | struct nfs4_get_lease_time_data { |
| 7893 | struct nfs4_get_lease_time_args *args; |
| 7894 | struct nfs4_get_lease_time_res *res; |
| 7895 | struct nfs_client *clp; |
| 7896 | }; |
| 7897 | |
| 7898 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7899 | void *calldata) |
| 7900 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7901 | struct nfs4_get_lease_time_data *data = |
| 7902 | (struct nfs4_get_lease_time_data *)calldata; |
| 7903 | |
| 7904 | dprintk("--> %s\n", __func__); |
| 7905 | /* just setup sequence, do not trigger session recovery |
| 7906 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7907 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7908 | &data->args->la_seq_args, |
| 7909 | &data->res->lr_seq_res, |
| 7910 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7911 | dprintk("<-- %s\n", __func__); |
| 7912 | } |
| 7913 | |
| 7914 | /* |
| 7915 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7916 | * from sequence operation or clientid errors. |
| 7917 | */ |
| 7918 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7919 | { |
| 7920 | struct nfs4_get_lease_time_data *data = |
| 7921 | (struct nfs4_get_lease_time_data *)calldata; |
| 7922 | |
| 7923 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7924 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7925 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7926 | switch (task->tk_status) { |
| 7927 | case -NFS4ERR_DELAY: |
| 7928 | case -NFS4ERR_GRACE: |
| 7929 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7930 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7931 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7932 | /* fall through */ |
| 7933 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7934 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7935 | return; |
| 7936 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7937 | dprintk("<-- %s\n", __func__); |
| 7938 | } |
| 7939 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7940 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7941 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7942 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7943 | }; |
| 7944 | |
| 7945 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7946 | { |
| 7947 | struct rpc_task *task; |
| 7948 | struct nfs4_get_lease_time_args args; |
| 7949 | struct nfs4_get_lease_time_res res = { |
| 7950 | .lr_fsinfo = fsinfo, |
| 7951 | }; |
| 7952 | struct nfs4_get_lease_time_data data = { |
| 7953 | .args = &args, |
| 7954 | .res = &res, |
| 7955 | .clp = clp, |
| 7956 | }; |
| 7957 | struct rpc_message msg = { |
| 7958 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7959 | .rpc_argp = &args, |
| 7960 | .rpc_resp = &res, |
| 7961 | }; |
| 7962 | struct rpc_task_setup task_setup = { |
| 7963 | .rpc_client = clp->cl_rpcclient, |
| 7964 | .rpc_message = &msg, |
| 7965 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7966 | .callback_data = &data, |
| 7967 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7968 | }; |
| 7969 | int status; |
| 7970 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7971 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7972 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7973 | task = rpc_run_task(&task_setup); |
| 7974 | |
| 7975 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7976 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7977 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7978 | status = task->tk_status; |
| 7979 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7980 | return status; |
| 7981 | } |
| 7982 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7983 | /* |
| 7984 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7985 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7986 | * use them. |
| 7987 | * |
| 7988 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7989 | * always set csa_cachethis to FALSE because the current implementation |
| 7990 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7991 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7992 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7993 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7994 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7995 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7996 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7997 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7998 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7999 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 8000 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8001 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 8002 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 8003 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8004 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 8005 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8006 | |
| 8007 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8008 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8009 | __func__, |
| 8010 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 8011 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8012 | |
| 8013 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8014 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 8015 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8016 | args->bc_attrs.max_resp_sz_cached = 0; |
| 8017 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8018 | 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] | 8019 | |
| 8020 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 8021 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 8022 | __func__, |
| 8023 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 8024 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 8025 | args->bc_attrs.max_reqs); |
| 8026 | } |
| 8027 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8028 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 8029 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8030 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8031 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8032 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8033 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8034 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 8035 | return -EINVAL; |
| 8036 | /* |
| 8037 | * Our requested max_ops is the minimum we need; we're not |
| 8038 | * prepared to break up compounds into smaller pieces than that. |
| 8039 | * So, no point even trying to continue if the server won't |
| 8040 | * cooperate: |
| 8041 | */ |
| 8042 | if (rcvd->max_ops < sent->max_ops) |
| 8043 | return -EINVAL; |
| 8044 | if (rcvd->max_reqs == 0) |
| 8045 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 8046 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 8047 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8048 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8049 | } |
| 8050 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8051 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 8052 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8053 | { |
| 8054 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8055 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8056 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8057 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 8058 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8059 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 8060 | return -EINVAL; |
| 8061 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 8062 | return -EINVAL; |
| 8063 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 8064 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8065 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8066 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 8067 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8068 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8069 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8070 | return 0; |
| 8071 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8072 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8073 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8074 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8075 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8076 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8077 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8078 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 8079 | if (ret) |
| 8080 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8081 | return nfs4_verify_back_channel_attrs(args, res); |
| 8082 | } |
| 8083 | |
| 8084 | static void nfs4_update_session(struct nfs4_session *session, |
| 8085 | struct nfs41_create_session_res *res) |
| 8086 | { |
| 8087 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8088 | /* Mark client id and session as being confirmed */ |
| 8089 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 8090 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8091 | session->flags = res->flags; |
| 8092 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 8093 | if (res->flags & SESSION4_BACK_CHAN) |
| 8094 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 8095 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8096 | } |
| 8097 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8098 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 8099 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8100 | { |
| 8101 | struct nfs4_session *session = clp->cl_session; |
| 8102 | struct nfs41_create_session_args args = { |
| 8103 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8104 | .clientid = clp->cl_clientid, |
| 8105 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8106 | .cb_program = NFS4_CALLBACK, |
| 8107 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8108 | struct nfs41_create_session_res res; |
| 8109 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8110 | struct rpc_message msg = { |
| 8111 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8112 | .rpc_argp = &args, |
| 8113 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8114 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8115 | }; |
| 8116 | int status; |
| 8117 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8118 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8119 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8120 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8121 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8122 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8123 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8124 | switch (status) { |
| 8125 | case -NFS4ERR_STALE_CLIENTID: |
| 8126 | case -NFS4ERR_DELAY: |
| 8127 | case -ETIMEDOUT: |
| 8128 | case -EACCES: |
| 8129 | case -EAGAIN: |
| 8130 | goto out; |
| 8131 | }; |
| 8132 | |
| 8133 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8134 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8135 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8136 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8137 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8138 | if (status) |
| 8139 | goto out; |
| 8140 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8141 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8142 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8143 | return status; |
| 8144 | } |
| 8145 | |
| 8146 | /* |
| 8147 | * Issues a CREATE_SESSION operation to the server. |
| 8148 | * It is the responsibility of the caller to verify the session is |
| 8149 | * expired before calling this routine. |
| 8150 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8151 | 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] | 8152 | { |
| 8153 | int status; |
| 8154 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8155 | struct nfs4_session *session = clp->cl_session; |
| 8156 | |
| 8157 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8158 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8159 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8160 | if (status) |
| 8161 | goto out; |
| 8162 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8163 | /* Init or reset the session slot tables */ |
| 8164 | status = nfs4_setup_session_slot_tables(session); |
| 8165 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8166 | if (status) |
| 8167 | goto out; |
| 8168 | |
| 8169 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8170 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8171 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8172 | out: |
| 8173 | dprintk("<-- %s\n", __func__); |
| 8174 | return status; |
| 8175 | } |
| 8176 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8177 | /* |
| 8178 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8179 | * The caller must serialize access to this routine. |
| 8180 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8181 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8182 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8183 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8184 | struct rpc_message msg = { |
| 8185 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8186 | .rpc_argp = session, |
| 8187 | .rpc_cred = cred, |
| 8188 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8189 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8190 | |
| 8191 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8192 | |
| 8193 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8194 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8195 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8196 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8197 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8198 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8199 | |
| 8200 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8201 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8202 | "Session has been destroyed regardless...\n", status); |
| 8203 | |
| 8204 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8205 | return status; |
| 8206 | } |
| 8207 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8208 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8209 | * Renew the cl_session lease. |
| 8210 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8211 | struct nfs4_sequence_data { |
| 8212 | struct nfs_client *clp; |
| 8213 | struct nfs4_sequence_args args; |
| 8214 | struct nfs4_sequence_res res; |
| 8215 | }; |
| 8216 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8217 | static void nfs41_sequence_release(void *data) |
| 8218 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8219 | struct nfs4_sequence_data *calldata = data; |
| 8220 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8221 | |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8222 | if (refcount_read(&clp->cl_count) > 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8223 | nfs4_schedule_state_renewal(clp); |
| 8224 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8225 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8226 | } |
| 8227 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8228 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8229 | { |
| 8230 | switch(task->tk_status) { |
| 8231 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8232 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8233 | return -EAGAIN; |
| 8234 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8235 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8236 | } |
| 8237 | return 0; |
| 8238 | } |
| 8239 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8240 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8241 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8242 | struct nfs4_sequence_data *calldata = data; |
| 8243 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8244 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8245 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8246 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8247 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8248 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8249 | if (task->tk_status < 0) { |
| 8250 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8251 | if (refcount_read(&clp->cl_count) == 1) |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8252 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8253 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8254 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8255 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8256 | return; |
| 8257 | } |
| 8258 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8259 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8260 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8261 | dprintk("<-- %s\n", __func__); |
| 8262 | } |
| 8263 | |
| 8264 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8265 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8266 | struct nfs4_sequence_data *calldata = data; |
| 8267 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8268 | struct nfs4_sequence_args *args; |
| 8269 | struct nfs4_sequence_res *res; |
| 8270 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8271 | args = task->tk_msg.rpc_argp; |
| 8272 | res = task->tk_msg.rpc_resp; |
| 8273 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8274 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8275 | } |
| 8276 | |
| 8277 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8278 | .rpc_call_done = nfs41_sequence_call_done, |
| 8279 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8280 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8281 | }; |
| 8282 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8283 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8284 | struct rpc_cred *cred, |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8285 | struct nfs4_slot *slot, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8286 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8287 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8288 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8289 | struct rpc_message msg = { |
| 8290 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8291 | .rpc_cred = cred, |
| 8292 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8293 | struct rpc_task_setup task_setup_data = { |
| 8294 | .rpc_client = clp->cl_rpcclient, |
| 8295 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8296 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8297 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8298 | }; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8299 | struct rpc_task *ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8300 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8301 | ret = ERR_PTR(-EIO); |
Elena Reshetova | 212bf41 | 2017-10-20 12:53:38 +0300 | [diff] [blame] | 8302 | if (!refcount_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8303 | goto out_err; |
| 8304 | |
| 8305 | ret = ERR_PTR(-ENOMEM); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8306 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8307 | if (calldata == NULL) |
| 8308 | goto out_put_clp; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8309 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8310 | nfs4_sequence_attach_slot(&calldata->args, &calldata->res, slot); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8311 | if (is_privileged) |
| 8312 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8313 | msg.rpc_argp = &calldata->args; |
| 8314 | msg.rpc_resp = &calldata->res; |
| 8315 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8316 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8317 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8318 | ret = rpc_run_task(&task_setup_data); |
| 8319 | if (IS_ERR(ret)) |
| 8320 | goto out_err; |
| 8321 | return ret; |
| 8322 | out_put_clp: |
| 8323 | nfs_put_client(clp); |
| 8324 | out_err: |
| 8325 | nfs41_release_slot(slot); |
| 8326 | return ret; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8327 | } |
| 8328 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8329 | 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] | 8330 | { |
| 8331 | struct rpc_task *task; |
| 8332 | int ret = 0; |
| 8333 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8334 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8335 | return -EAGAIN; |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8336 | task = _nfs41_proc_sequence(clp, cred, NULL, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8337 | if (IS_ERR(task)) |
| 8338 | ret = PTR_ERR(task); |
| 8339 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8340 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8341 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8342 | return ret; |
| 8343 | } |
| 8344 | |
| 8345 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8346 | { |
| 8347 | struct rpc_task *task; |
| 8348 | int ret; |
| 8349 | |
Trond Myklebust | 3be0f80b | 2017-10-19 15:46:45 -0400 | [diff] [blame] | 8350 | task = _nfs41_proc_sequence(clp, cred, NULL, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8351 | if (IS_ERR(task)) { |
| 8352 | ret = PTR_ERR(task); |
| 8353 | goto out; |
| 8354 | } |
| 8355 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8356 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8357 | ret = task->tk_status; |
| 8358 | rpc_put_task(task); |
| 8359 | out: |
| 8360 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8361 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8362 | } |
| 8363 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8364 | struct nfs4_reclaim_complete_data { |
| 8365 | struct nfs_client *clp; |
| 8366 | struct nfs41_reclaim_complete_args arg; |
| 8367 | struct nfs41_reclaim_complete_res res; |
| 8368 | }; |
| 8369 | |
| 8370 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8371 | { |
| 8372 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8373 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8374 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8375 | &calldata->arg.seq_args, |
| 8376 | &calldata->res.seq_res, |
| 8377 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8378 | } |
| 8379 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8380 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8381 | { |
| 8382 | switch(task->tk_status) { |
| 8383 | case 0: |
| 8384 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8385 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8386 | break; |
| 8387 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8388 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8389 | /* fall through */ |
| 8390 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8391 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8392 | case -NFS4ERR_BADSESSION: |
| 8393 | case -NFS4ERR_DEADSESSION: |
| 8394 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8395 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8396 | task->tk_status); |
| 8397 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8398 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8399 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8400 | } |
| 8401 | return 0; |
| 8402 | } |
| 8403 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8404 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8405 | { |
| 8406 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8407 | struct nfs_client *clp = calldata->clp; |
| 8408 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8409 | |
| 8410 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8411 | if (!nfs41_sequence_done(task, res)) |
| 8412 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8413 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8414 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8415 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8416 | rpc_restart_call_prepare(task); |
| 8417 | return; |
| 8418 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8419 | dprintk("<-- %s\n", __func__); |
| 8420 | } |
| 8421 | |
| 8422 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8423 | { |
| 8424 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8425 | |
| 8426 | kfree(calldata); |
| 8427 | } |
| 8428 | |
| 8429 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8430 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8431 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8432 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8433 | }; |
| 8434 | |
| 8435 | /* |
| 8436 | * Issue a global reclaim complete. |
| 8437 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8438 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8439 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8440 | { |
| 8441 | struct nfs4_reclaim_complete_data *calldata; |
| 8442 | struct rpc_task *task; |
| 8443 | struct rpc_message msg = { |
| 8444 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8445 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8446 | }; |
| 8447 | struct rpc_task_setup task_setup_data = { |
| 8448 | .rpc_client = clp->cl_rpcclient, |
| 8449 | .rpc_message = &msg, |
| 8450 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8451 | .flags = RPC_TASK_ASYNC, |
| 8452 | }; |
| 8453 | int status = -ENOMEM; |
| 8454 | |
| 8455 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8456 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8457 | if (calldata == NULL) |
| 8458 | goto out; |
| 8459 | calldata->clp = clp; |
| 8460 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8461 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8462 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8463 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8464 | msg.rpc_argp = &calldata->arg; |
| 8465 | msg.rpc_resp = &calldata->res; |
| 8466 | task_setup_data.callback_data = calldata; |
| 8467 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8468 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8469 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8470 | goto out; |
| 8471 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8472 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8473 | if (status == 0) |
| 8474 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8475 | rpc_put_task(task); |
| 8476 | out: |
| 8477 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8478 | return status; |
| 8479 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8480 | |
| 8481 | static void |
| 8482 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8483 | { |
| 8484 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8485 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8486 | |
| 8487 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8488 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8489 | &lgp->res.seq_res, task); |
| 8490 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8491 | } |
| 8492 | |
| 8493 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8494 | { |
| 8495 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8496 | |
| 8497 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8498 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8499 | dprintk("<-- %s\n", __func__); |
| 8500 | } |
| 8501 | |
| 8502 | static int |
| 8503 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8504 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8505 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8506 | struct inode *inode = lgp->args.inode; |
| 8507 | struct nfs_server *server = NFS_SERVER(inode); |
| 8508 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8509 | int nfs4err = task->tk_status; |
| 8510 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8511 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8512 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8513 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8514 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8515 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8516 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8517 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8518 | |
| 8519 | /* |
| 8520 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8521 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8522 | * retry go inband. |
| 8523 | */ |
| 8524 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8525 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8526 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8527 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8528 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8529 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8530 | */ |
| 8531 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8532 | status = -EOVERFLOW; |
| 8533 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8534 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8535 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8536 | * (or clients) writing to the same RAID stripe except when |
| 8537 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8538 | * |
| 8539 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8540 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8541 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8542 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8543 | if (lgp->args.minlength == 0) { |
| 8544 | status = -EOVERFLOW; |
| 8545 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8546 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8547 | status = -EBUSY; |
| 8548 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8549 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8550 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8551 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8552 | case -NFS4ERR_DELEG_REVOKED: |
| 8553 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8554 | case -NFS4ERR_EXPIRED: |
| 8555 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8556 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8557 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8558 | lo = NFS_I(inode)->layout; |
| 8559 | /* If the open stateid was bad, then recover it. */ |
| 8560 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
Trond Myklebust | e8fa33a | 2017-10-04 13:49:12 -0400 | [diff] [blame] | 8561 | !nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8562 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8563 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8564 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8565 | break; |
| 8566 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8567 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8568 | /* |
| 8569 | * Mark the bad layout state as invalid, then retry |
| 8570 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8571 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8572 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8573 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8574 | pnfs_free_lseg_list(&head); |
| 8575 | status = -EAGAIN; |
| 8576 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8577 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8578 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8579 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8580 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8581 | if (!status) { |
| 8582 | if (exception->retry) |
| 8583 | status = -EAGAIN; |
| 8584 | else |
| 8585 | status = err; |
| 8586 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8587 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8588 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8589 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8590 | } |
| 8591 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8592 | static size_t max_response_pages(struct nfs_server *server) |
| 8593 | { |
| 8594 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8595 | return nfs_page_array_len(0, max_resp_sz); |
| 8596 | } |
| 8597 | |
| 8598 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8599 | { |
| 8600 | int i; |
| 8601 | |
| 8602 | if (!pages) |
| 8603 | return; |
| 8604 | |
| 8605 | for (i = 0; i < size; i++) { |
| 8606 | if (!pages[i]) |
| 8607 | break; |
| 8608 | __free_page(pages[i]); |
| 8609 | } |
| 8610 | kfree(pages); |
| 8611 | } |
| 8612 | |
| 8613 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8614 | { |
| 8615 | struct page **pages; |
| 8616 | int i; |
| 8617 | |
| 8618 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8619 | if (!pages) { |
| 8620 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8621 | return NULL; |
| 8622 | } |
| 8623 | |
| 8624 | for (i = 0; i < size; i++) { |
| 8625 | pages[i] = alloc_page(gfp_flags); |
| 8626 | if (!pages[i]) { |
| 8627 | dprintk("%s: failed to allocate page\n", __func__); |
| 8628 | nfs4_free_pages(pages, size); |
| 8629 | return NULL; |
| 8630 | } |
| 8631 | } |
| 8632 | |
| 8633 | return pages; |
| 8634 | } |
| 8635 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8636 | static void nfs4_layoutget_release(void *calldata) |
| 8637 | { |
| 8638 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8639 | struct inode *inode = lgp->args.inode; |
| 8640 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8641 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8642 | |
| 8643 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame] | 8644 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8645 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8646 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8647 | put_nfs_open_context(lgp->args.ctx); |
| 8648 | kfree(calldata); |
| 8649 | dprintk("<-- %s\n", __func__); |
| 8650 | } |
| 8651 | |
| 8652 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8653 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8654 | .rpc_call_done = nfs4_layoutget_done, |
| 8655 | .rpc_release = nfs4_layoutget_release, |
| 8656 | }; |
| 8657 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8658 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8659 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8660 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8661 | struct inode *inode = lgp->args.inode; |
| 8662 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8663 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8664 | struct rpc_task *task; |
| 8665 | struct rpc_message msg = { |
| 8666 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8667 | .rpc_argp = &lgp->args, |
| 8668 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8669 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8670 | }; |
| 8671 | struct rpc_task_setup task_setup_data = { |
| 8672 | .rpc_client = server->client, |
| 8673 | .rpc_message = &msg, |
| 8674 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8675 | .callback_data = lgp, |
| 8676 | .flags = RPC_TASK_ASYNC, |
| 8677 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8678 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8679 | struct nfs4_exception exception = { |
| 8680 | .inode = inode, |
| 8681 | .timeout = *timeout, |
| 8682 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8683 | int status = 0; |
| 8684 | |
| 8685 | dprintk("--> %s\n", __func__); |
| 8686 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8687 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8688 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8689 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8690 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8691 | if (!lgp->args.layout.pages) { |
| 8692 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8693 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8694 | } |
| 8695 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8696 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8697 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8698 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8699 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8700 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8701 | task = rpc_run_task(&task_setup_data); |
| 8702 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8703 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8704 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8705 | if (status == 0) { |
| 8706 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8707 | *timeout = exception.timeout; |
| 8708 | } |
| 8709 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8710 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8711 | &lgp->args.range, |
| 8712 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8713 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8714 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8715 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8716 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8717 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8718 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8719 | rpc_put_task(task); |
| 8720 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8721 | if (status) |
| 8722 | return ERR_PTR(status); |
| 8723 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8724 | } |
| 8725 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8726 | static void |
| 8727 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8728 | { |
| 8729 | struct nfs4_layoutreturn *lrp = calldata; |
| 8730 | |
| 8731 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8732 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8733 | &lrp->args.seq_args, |
| 8734 | &lrp->res.seq_res, |
| 8735 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8736 | } |
| 8737 | |
| 8738 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8739 | { |
| 8740 | struct nfs4_layoutreturn *lrp = calldata; |
| 8741 | struct nfs_server *server; |
| 8742 | |
| 8743 | dprintk("--> %s\n", __func__); |
| 8744 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8745 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8746 | return; |
| 8747 | |
| 8748 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8749 | switch (task->tk_status) { |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8750 | case -NFS4ERR_OLD_STATEID: |
| 8751 | if (nfs4_refresh_layout_stateid(&lrp->args.stateid, |
| 8752 | lrp->args.inode)) |
| 8753 | goto out_restart; |
| 8754 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8755 | default: |
| 8756 | task->tk_status = 0; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8757 | /* Fallthrough */ |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8758 | case 0: |
| 8759 | break; |
| 8760 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8761 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8762 | break; |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8763 | goto out_restart; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8764 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8765 | dprintk("<-- %s\n", __func__); |
Trond Myklebust | ff90514 | 2017-11-06 15:28:08 -0500 | [diff] [blame] | 8766 | return; |
| 8767 | out_restart: |
| 8768 | task->tk_status = 0; |
| 8769 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
| 8770 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8771 | } |
| 8772 | |
| 8773 | static void nfs4_layoutreturn_release(void *calldata) |
| 8774 | { |
| 8775 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8776 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8777 | |
| 8778 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8779 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8780 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8781 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8782 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8783 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8784 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8785 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8786 | kfree(calldata); |
| 8787 | dprintk("<-- %s\n", __func__); |
| 8788 | } |
| 8789 | |
| 8790 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8791 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8792 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8793 | .rpc_release = nfs4_layoutreturn_release, |
| 8794 | }; |
| 8795 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8796 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8797 | { |
| 8798 | struct rpc_task *task; |
| 8799 | struct rpc_message msg = { |
| 8800 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8801 | .rpc_argp = &lrp->args, |
| 8802 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8803 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8804 | }; |
| 8805 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8806 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8807 | .rpc_message = &msg, |
| 8808 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8809 | .callback_data = lrp, |
| 8810 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8811 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8812 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8813 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8814 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8815 | &task_setup_data.rpc_client, &msg); |
| 8816 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8817 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8818 | if (!sync) { |
| 8819 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8820 | if (!lrp->inode) { |
| 8821 | nfs4_layoutreturn_release(lrp); |
| 8822 | return -EAGAIN; |
| 8823 | } |
| 8824 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8825 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8826 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8827 | task = rpc_run_task(&task_setup_data); |
| 8828 | if (IS_ERR(task)) |
| 8829 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8830 | if (sync) |
| 8831 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8832 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8833 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8834 | rpc_put_task(task); |
| 8835 | return status; |
| 8836 | } |
| 8837 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8838 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8839 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8840 | struct pnfs_device *pdev, |
| 8841 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8842 | { |
| 8843 | struct nfs4_getdeviceinfo_args args = { |
| 8844 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8845 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8846 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8847 | }; |
| 8848 | struct nfs4_getdeviceinfo_res res = { |
| 8849 | .pdev = pdev, |
| 8850 | }; |
| 8851 | struct rpc_message msg = { |
| 8852 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8853 | .rpc_argp = &args, |
| 8854 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8855 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8856 | }; |
| 8857 | int status; |
| 8858 | |
| 8859 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8860 | 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] | 8861 | if (res.notification & ~args.notify_types) |
| 8862 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8863 | if (res.notification != args.notify_types) |
| 8864 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8865 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8866 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8867 | |
| 8868 | return status; |
| 8869 | } |
| 8870 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8871 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8872 | struct pnfs_device *pdev, |
| 8873 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8874 | { |
| 8875 | struct nfs4_exception exception = { }; |
| 8876 | int err; |
| 8877 | |
| 8878 | do { |
| 8879 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8880 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8881 | &exception); |
| 8882 | } while (exception.retry); |
| 8883 | return err; |
| 8884 | } |
| 8885 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8886 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8887 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8888 | { |
| 8889 | struct nfs4_layoutcommit_data *data = calldata; |
| 8890 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8891 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8892 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8893 | &data->args.seq_args, |
| 8894 | &data->res.seq_res, |
| 8895 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8896 | } |
| 8897 | |
| 8898 | static void |
| 8899 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8900 | { |
| 8901 | struct nfs4_layoutcommit_data *data = calldata; |
| 8902 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8903 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8904 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8905 | return; |
| 8906 | |
| 8907 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8908 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8909 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8910 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8911 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8912 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8913 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8914 | break; |
| 8915 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8916 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8917 | rpc_restart_call_prepare(task); |
| 8918 | return; |
| 8919 | } |
| 8920 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8921 | } |
| 8922 | |
| 8923 | static void nfs4_layoutcommit_release(void *calldata) |
| 8924 | { |
| 8925 | struct nfs4_layoutcommit_data *data = calldata; |
| 8926 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8927 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8928 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8929 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8930 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8931 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8932 | kfree(data); |
| 8933 | } |
| 8934 | |
| 8935 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8936 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8937 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8938 | .rpc_release = nfs4_layoutcommit_release, |
| 8939 | }; |
| 8940 | |
| 8941 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8942 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8943 | { |
| 8944 | struct rpc_message msg = { |
| 8945 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8946 | .rpc_argp = &data->args, |
| 8947 | .rpc_resp = &data->res, |
| 8948 | .rpc_cred = data->cred, |
| 8949 | }; |
| 8950 | struct rpc_task_setup task_setup_data = { |
| 8951 | .task = &data->task, |
| 8952 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8953 | .rpc_message = &msg, |
| 8954 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8955 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8956 | }; |
| 8957 | struct rpc_task *task; |
| 8958 | int status = 0; |
| 8959 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8960 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8961 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8962 | data->args.lastbytewritten, |
| 8963 | data->args.inode->i_ino); |
| 8964 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8965 | if (!sync) { |
| 8966 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8967 | if (data->inode == NULL) { |
| 8968 | nfs4_layoutcommit_release(data); |
| 8969 | return -EAGAIN; |
| 8970 | } |
| 8971 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8972 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8973 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8974 | task = rpc_run_task(&task_setup_data); |
| 8975 | if (IS_ERR(task)) |
| 8976 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8977 | if (sync) |
| 8978 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8979 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8980 | dprintk("%s: status %d\n", __func__, status); |
| 8981 | rpc_put_task(task); |
| 8982 | return status; |
| 8983 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8984 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8985 | /** |
| 8986 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8987 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8988 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8989 | static int |
| 8990 | _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] | 8991 | struct nfs_fsinfo *info, |
| 8992 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8993 | { |
| 8994 | struct nfs41_secinfo_no_name_args args = { |
| 8995 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8996 | }; |
| 8997 | struct nfs4_secinfo_res res = { |
| 8998 | .flavors = flavors, |
| 8999 | }; |
| 9000 | struct rpc_message msg = { |
| 9001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 9002 | .rpc_argp = &args, |
| 9003 | .rpc_resp = &res, |
| 9004 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9005 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9006 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9007 | int status; |
| 9008 | |
| 9009 | if (use_integrity) { |
| 9010 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9011 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 9012 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9013 | } |
| 9014 | |
| 9015 | dprintk("--> %s\n", __func__); |
| 9016 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 9017 | &res.seq_res, 0); |
| 9018 | dprintk("<-- %s status=%d\n", __func__, status); |
| 9019 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 9020 | if (cred) |
| 9021 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9022 | |
| 9023 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | static int |
| 9027 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9028 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 9029 | { |
| 9030 | struct nfs4_exception exception = { }; |
| 9031 | int err; |
| 9032 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 9033 | /* first try using integrity protection */ |
| 9034 | err = -NFS4ERR_WRONGSEC; |
| 9035 | |
| 9036 | /* try to use integrity protection with machine cred */ |
| 9037 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 9038 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9039 | flavors, true); |
| 9040 | |
| 9041 | /* |
| 9042 | * if unable to use integrity protection, or SECINFO with |
| 9043 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 9044 | * disallowed by spec, but exists in deployed servers) use |
| 9045 | * the current filesystem's rpc_client and the user cred. |
| 9046 | */ |
| 9047 | if (err == -NFS4ERR_WRONGSEC) |
| 9048 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 9049 | flavors, false); |
| 9050 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9051 | switch (err) { |
| 9052 | case 0: |
| 9053 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9054 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9055 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9056 | default: |
| 9057 | err = nfs4_handle_exception(server, err, &exception); |
| 9058 | } |
| 9059 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 9060 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9061 | return err; |
| 9062 | } |
| 9063 | |
| 9064 | static int |
| 9065 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 9066 | struct nfs_fsinfo *info) |
| 9067 | { |
| 9068 | int err; |
| 9069 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 9070 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9071 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9072 | struct nfs4_secinfo4 *secinfo; |
| 9073 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9074 | |
| 9075 | page = alloc_page(GFP_KERNEL); |
| 9076 | if (!page) { |
| 9077 | err = -ENOMEM; |
| 9078 | goto out; |
| 9079 | } |
| 9080 | |
| 9081 | flavors = page_address(page); |
| 9082 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 9083 | |
| 9084 | /* |
| 9085 | * Fall back on "guess and check" method if |
| 9086 | * the server doesn't support SECINFO_NO_NAME |
| 9087 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 9088 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9089 | err = nfs4_find_root_sec(server, fhandle, info); |
| 9090 | goto out_freepage; |
| 9091 | } |
| 9092 | if (err) |
| 9093 | goto out_freepage; |
| 9094 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9095 | for (i = 0; i < flavors->num_flavors; i++) { |
| 9096 | secinfo = &flavors->flavors[i]; |
| 9097 | |
| 9098 | switch (secinfo->flavor) { |
| 9099 | case RPC_AUTH_NULL: |
| 9100 | case RPC_AUTH_UNIX: |
| 9101 | case RPC_AUTH_GSS: |
| 9102 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 9103 | &secinfo->flavor_info); |
| 9104 | break; |
| 9105 | default: |
| 9106 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9107 | break; |
| 9108 | } |
| 9109 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 9110 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 9111 | flavor = RPC_AUTH_MAXFLAVOR; |
| 9112 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 9113 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 9114 | err = nfs4_lookup_root_sec(server, fhandle, |
| 9115 | info, flavor); |
| 9116 | if (!err) |
| 9117 | break; |
| 9118 | } |
| 9119 | } |
| 9120 | |
| 9121 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 9122 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9123 | |
| 9124 | out_freepage: |
| 9125 | put_page(page); |
| 9126 | if (err == -EACCES) |
| 9127 | return -EPERM; |
| 9128 | out: |
| 9129 | return err; |
| 9130 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9131 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9132 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9133 | nfs4_stateid *stateid, |
| 9134 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9135 | { |
| 9136 | int status; |
| 9137 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9138 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9139 | }; |
| 9140 | struct nfs41_test_stateid_res res; |
| 9141 | struct rpc_message msg = { |
| 9142 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9143 | .rpc_argp = &args, |
| 9144 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9145 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9146 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9147 | struct rpc_clnt *rpc_client = server->client; |
| 9148 | |
| 9149 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9150 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9151 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9152 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9153 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9154 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9155 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9156 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9157 | if (status != NFS_OK) { |
| 9158 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9159 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9160 | } |
| 9161 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9162 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9163 | } |
| 9164 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9165 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9166 | int err, struct nfs4_exception *exception) |
| 9167 | { |
| 9168 | exception->retry = 0; |
| 9169 | switch(err) { |
| 9170 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9171 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9172 | nfs4_handle_exception(server, err, exception); |
| 9173 | break; |
| 9174 | case -NFS4ERR_BADSESSION: |
| 9175 | case -NFS4ERR_BADSLOT: |
| 9176 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9177 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9178 | case -NFS4ERR_DEADSESSION: |
| 9179 | nfs4_do_handle_exception(server, err, exception); |
| 9180 | } |
| 9181 | } |
| 9182 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9183 | /** |
| 9184 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9185 | * |
| 9186 | * @server: server / transport on which to perform the operation |
| 9187 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9188 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9189 | * |
| 9190 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9191 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9192 | * failed or the state ID is not currently valid. |
| 9193 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9194 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9195 | nfs4_stateid *stateid, |
| 9196 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9197 | { |
| 9198 | struct nfs4_exception exception = { }; |
| 9199 | int err; |
| 9200 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9201 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9202 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9203 | } while (exception.retry); |
| 9204 | return err; |
| 9205 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9206 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9207 | struct nfs_free_stateid_data { |
| 9208 | struct nfs_server *server; |
| 9209 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9210 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9211 | }; |
| 9212 | |
| 9213 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9214 | { |
| 9215 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9216 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9217 | &data->args.seq_args, |
| 9218 | &data->res.seq_res, |
| 9219 | task); |
| 9220 | } |
| 9221 | |
| 9222 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9223 | { |
| 9224 | struct nfs_free_stateid_data *data = calldata; |
| 9225 | |
| 9226 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9227 | |
| 9228 | switch (task->tk_status) { |
| 9229 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9230 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9231 | rpc_restart_call_prepare(task); |
| 9232 | } |
| 9233 | } |
| 9234 | |
| 9235 | static void nfs41_free_stateid_release(void *calldata) |
| 9236 | { |
| 9237 | kfree(calldata); |
| 9238 | } |
| 9239 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9240 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9241 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9242 | .rpc_call_done = nfs41_free_stateid_done, |
| 9243 | .rpc_release = nfs41_free_stateid_release, |
| 9244 | }; |
| 9245 | |
| 9246 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9247 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9248 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9249 | bool privileged) |
| 9250 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9251 | struct rpc_message msg = { |
| 9252 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9253 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9254 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9255 | struct rpc_task_setup task_setup = { |
| 9256 | .rpc_client = server->client, |
| 9257 | .rpc_message = &msg, |
| 9258 | .callback_ops = &nfs41_free_stateid_ops, |
| 9259 | .flags = RPC_TASK_ASYNC, |
| 9260 | }; |
| 9261 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9262 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9263 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9264 | &task_setup.rpc_client, &msg); |
| 9265 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9266 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9267 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9268 | if (!data) |
| 9269 | return ERR_PTR(-ENOMEM); |
| 9270 | data->server = server; |
| 9271 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9272 | |
| 9273 | task_setup.callback_data = data; |
| 9274 | |
| 9275 | msg.rpc_argp = &data->args; |
| 9276 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9277 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9278 | if (privileged) |
| 9279 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9280 | |
| 9281 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9282 | } |
| 9283 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9284 | /** |
| 9285 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9286 | * |
| 9287 | * @server: server / transport on which to perform the operation |
| 9288 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9289 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9290 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9291 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9292 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9293 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9294 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9295 | const nfs4_stateid *stateid, |
| 9296 | struct rpc_cred *cred, |
| 9297 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9298 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9299 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9300 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9301 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9302 | if (IS_ERR(task)) |
| 9303 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9304 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9305 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9306 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9307 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9308 | static void |
| 9309 | 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] | 9310 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9311 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9312 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9313 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9314 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9315 | } |
| 9316 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9317 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9318 | const nfs4_stateid *s2) |
| 9319 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9320 | if (s1->type != s2->type) |
| 9321 | return false; |
| 9322 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9323 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9324 | return false; |
| 9325 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9326 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9327 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9328 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9329 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9330 | } |
| 9331 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9332 | #endif /* CONFIG_NFS_V4_1 */ |
| 9333 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9334 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9335 | const nfs4_stateid *s2) |
| 9336 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9337 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9338 | } |
| 9339 | |
| 9340 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9341 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9342 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9343 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9344 | .recover_open = nfs4_open_reclaim, |
| 9345 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9346 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9347 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9348 | }; |
| 9349 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9350 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9351 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9352 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9353 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9354 | .recover_open = nfs4_open_reclaim, |
| 9355 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9356 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9357 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9358 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9359 | }; |
| 9360 | #endif /* CONFIG_NFS_V4_1 */ |
| 9361 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9362 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9363 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9364 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9365 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9366 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9367 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9368 | }; |
| 9369 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9370 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9371 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9372 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9373 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9374 | .recover_open = nfs41_open_expired, |
| 9375 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9376 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9377 | }; |
| 9378 | #endif /* CONFIG_NFS_V4_1 */ |
| 9379 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9380 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9381 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9382 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9383 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9384 | }; |
| 9385 | |
| 9386 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9387 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9388 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9389 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9390 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9391 | }; |
| 9392 | #endif |
| 9393 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9394 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9395 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9396 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9397 | }; |
| 9398 | |
| 9399 | #if defined(CONFIG_NFS_V4_1) |
| 9400 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9401 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9402 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9403 | }; |
| 9404 | #endif /* CONFIG_NFS_V4_1 */ |
| 9405 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9406 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9407 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9408 | .init_caps = NFS_CAP_READDIRPLUS |
| 9409 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9410 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9411 | .init_client = nfs40_init_client, |
| 9412 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9413 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9414 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9415 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9416 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9417 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9418 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9419 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9420 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9421 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9422 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9423 | }; |
| 9424 | |
| 9425 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9426 | static struct nfs_seqid * |
| 9427 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9428 | { |
| 9429 | return NULL; |
| 9430 | } |
| 9431 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9432 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9433 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9434 | .init_caps = NFS_CAP_READDIRPLUS |
| 9435 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9436 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9437 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9438 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9439 | .init_client = nfs41_init_client, |
| 9440 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9441 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9442 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9443 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9444 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9445 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9446 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9447 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9448 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9449 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9450 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9451 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9452 | }; |
| 9453 | #endif |
| 9454 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9455 | #if defined(CONFIG_NFS_V4_2) |
| 9456 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9457 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9458 | .init_caps = NFS_CAP_READDIRPLUS |
| 9459 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9460 | | NFS_CAP_POSIX_LOCK |
| 9461 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9462 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9463 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9464 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9465 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9466 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9467 | | NFS_CAP_LAYOUTSTATS |
| 9468 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9469 | .init_client = nfs41_init_client, |
| 9470 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9471 | .match_stateid = nfs41_match_stateid, |
| 9472 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9473 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9474 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9475 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9476 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9477 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9478 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9479 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9480 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9481 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9482 | }; |
| 9483 | #endif |
| 9484 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9485 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9486 | [0] = &nfs_v4_0_minor_ops, |
| 9487 | #if defined(CONFIG_NFS_V4_1) |
| 9488 | [1] = &nfs_v4_1_minor_ops, |
| 9489 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9490 | #if defined(CONFIG_NFS_V4_2) |
| 9491 | [2] = &nfs_v4_2_minor_ops, |
| 9492 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9493 | }; |
| 9494 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9495 | 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] | 9496 | { |
| 9497 | ssize_t error, error2; |
| 9498 | |
| 9499 | error = generic_listxattr(dentry, list, size); |
| 9500 | if (error < 0) |
| 9501 | return error; |
| 9502 | if (list) { |
| 9503 | list += error; |
| 9504 | size -= error; |
| 9505 | } |
| 9506 | |
| 9507 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9508 | if (error2 < 0) |
| 9509 | return error2; |
| 9510 | return error + error2; |
| 9511 | } |
| 9512 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9513 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9514 | .create = nfs_create, |
| 9515 | .lookup = nfs_lookup, |
| 9516 | .atomic_open = nfs_atomic_open, |
| 9517 | .link = nfs_link, |
| 9518 | .unlink = nfs_unlink, |
| 9519 | .symlink = nfs_symlink, |
| 9520 | .mkdir = nfs_mkdir, |
| 9521 | .rmdir = nfs_rmdir, |
| 9522 | .mknod = nfs_mknod, |
| 9523 | .rename = nfs_rename, |
| 9524 | .permission = nfs_permission, |
| 9525 | .getattr = nfs_getattr, |
| 9526 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9527 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9528 | }; |
| 9529 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9530 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9531 | .permission = nfs_permission, |
| 9532 | .getattr = nfs_getattr, |
| 9533 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9534 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9535 | }; |
| 9536 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9537 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9538 | .version = 4, /* protocol version */ |
| 9539 | .dentry_ops = &nfs4_dentry_operations, |
| 9540 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9541 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9542 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9543 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9544 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9545 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9546 | .getattr = nfs4_proc_getattr, |
| 9547 | .setattr = nfs4_proc_setattr, |
| 9548 | .lookup = nfs4_proc_lookup, |
Jeff Layton | 5b5faaf | 2017-06-29 06:34:52 -0700 | [diff] [blame] | 9549 | .lookupp = nfs4_proc_lookupp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9550 | .access = nfs4_proc_access, |
| 9551 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9552 | .create = nfs4_proc_create, |
| 9553 | .remove = nfs4_proc_remove, |
| 9554 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9555 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9556 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9557 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9558 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9559 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9560 | .link = nfs4_proc_link, |
| 9561 | .symlink = nfs4_proc_symlink, |
| 9562 | .mkdir = nfs4_proc_mkdir, |
| 9563 | .rmdir = nfs4_proc_remove, |
| 9564 | .readdir = nfs4_proc_readdir, |
| 9565 | .mknod = nfs4_proc_mknod, |
| 9566 | .statfs = nfs4_proc_statfs, |
| 9567 | .fsinfo = nfs4_proc_fsinfo, |
| 9568 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9569 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9570 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9571 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9572 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9573 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9574 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9575 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9576 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9577 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9578 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9579 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9580 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9581 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9582 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9583 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9584 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9585 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9586 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7eced | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9587 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9588 | .create_server = nfs4_create_server, |
| 9589 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9590 | }; |
| 9591 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9592 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9593 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9594 | .list = nfs4_xattr_list_nfs4_acl, |
| 9595 | .get = nfs4_xattr_get_nfs4_acl, |
| 9596 | .set = nfs4_xattr_set_nfs4_acl, |
| 9597 | }; |
| 9598 | |
| 9599 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9600 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9601 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9602 | &nfs4_xattr_nfs4_label_handler, |
| 9603 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9604 | NULL |
| 9605 | }; |
| 9606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9607 | /* |
| 9608 | * Local variables: |
| 9609 | * c-basic-offset: 8 |
| 9610 | * End: |
| 9611 | */ |