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 | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 99 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 100 | struct rpc_cred *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 101 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 102 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 103 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 106 | static inline struct nfs4_label * |
| 107 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 108 | struct iattr *sattr, struct nfs4_label *label) |
| 109 | { |
| 110 | int err; |
| 111 | |
| 112 | if (label == NULL) |
| 113 | return NULL; |
| 114 | |
| 115 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 116 | return NULL; |
| 117 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 118 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 119 | &dentry->d_name, (void **)&label->label, &label->len); |
| 120 | if (err == 0) |
| 121 | return label; |
| 122 | |
| 123 | return NULL; |
| 124 | } |
| 125 | static inline void |
| 126 | nfs4_label_release_security(struct nfs4_label *label) |
| 127 | { |
| 128 | if (label) |
| 129 | security_release_secctx(label->label, label->len); |
| 130 | } |
| 131 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 132 | { |
| 133 | if (label) |
| 134 | return server->attr_bitmask; |
| 135 | |
| 136 | return server->attr_bitmask_nl; |
| 137 | } |
| 138 | #else |
| 139 | static inline struct nfs4_label * |
| 140 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 141 | struct iattr *sattr, struct nfs4_label *l) |
| 142 | { return NULL; } |
| 143 | static inline void |
| 144 | nfs4_label_release_security(struct nfs4_label *label) |
| 145 | { return; } |
| 146 | static inline u32 * |
| 147 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 148 | { return server->attr_bitmask; } |
| 149 | #endif |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 152 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 154 | if (err >= -1000) |
| 155 | return err; |
| 156 | switch (err) { |
| 157 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 158 | case -NFS4ERR_LAYOUTTRYLATER: |
| 159 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 160 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 161 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 162 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 163 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 164 | case -NFS4ERR_BADOWNER: |
| 165 | case -NFS4ERR_BADNAME: |
| 166 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 167 | case -NFS4ERR_SHARE_DENIED: |
| 168 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 169 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 170 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 171 | case -NFS4ERR_FILE_OPEN: |
| 172 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 173 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 175 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 176 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 178 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This is our standard bitmap for GETATTR requests. |
| 183 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 184 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | FATTR4_WORD0_TYPE |
| 186 | | FATTR4_WORD0_CHANGE |
| 187 | | FATTR4_WORD0_SIZE |
| 188 | | FATTR4_WORD0_FSID |
| 189 | | FATTR4_WORD0_FILEID, |
| 190 | FATTR4_WORD1_MODE |
| 191 | | FATTR4_WORD1_NUMLINKS |
| 192 | | FATTR4_WORD1_OWNER |
| 193 | | FATTR4_WORD1_OWNER_GROUP |
| 194 | | FATTR4_WORD1_RAWDEV |
| 195 | | FATTR4_WORD1_SPACE_USED |
| 196 | | FATTR4_WORD1_TIME_ACCESS |
| 197 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 198 | | FATTR4_WORD1_TIME_MODIFY |
| 199 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 200 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 201 | FATTR4_WORD2_SECURITY_LABEL |
| 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 205 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 206 | FATTR4_WORD0_TYPE |
| 207 | | FATTR4_WORD0_CHANGE |
| 208 | | FATTR4_WORD0_SIZE |
| 209 | | FATTR4_WORD0_FSID |
| 210 | | FATTR4_WORD0_FILEID, |
| 211 | FATTR4_WORD1_MODE |
| 212 | | FATTR4_WORD1_NUMLINKS |
| 213 | | FATTR4_WORD1_OWNER |
| 214 | | FATTR4_WORD1_OWNER_GROUP |
| 215 | | FATTR4_WORD1_RAWDEV |
| 216 | | FATTR4_WORD1_SPACE_USED |
| 217 | | FATTR4_WORD1_TIME_ACCESS |
| 218 | | FATTR4_WORD1_TIME_METADATA |
| 219 | | FATTR4_WORD1_TIME_MODIFY, |
| 220 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 221 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 222 | | FATTR4_WORD2_SECURITY_LABEL |
| 223 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 226 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 227 | FATTR4_WORD0_TYPE |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 228 | | FATTR4_WORD0_FILEID, |
| 229 | }; |
| 230 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 231 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | FATTR4_WORD0_FILES_AVAIL |
| 233 | | FATTR4_WORD0_FILES_FREE |
| 234 | | FATTR4_WORD0_FILES_TOTAL, |
| 235 | FATTR4_WORD1_SPACE_AVAIL |
| 236 | | FATTR4_WORD1_SPACE_FREE |
| 237 | | FATTR4_WORD1_SPACE_TOTAL |
| 238 | }; |
| 239 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 240 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | FATTR4_WORD0_MAXLINK |
| 242 | | FATTR4_WORD0_MAXNAME, |
| 243 | 0 |
| 244 | }; |
| 245 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 246 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | | FATTR4_WORD0_MAXREAD |
| 248 | | FATTR4_WORD0_MAXWRITE |
| 249 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 250 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 251 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 252 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 253 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 256 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 257 | FATTR4_WORD0_TYPE |
| 258 | | FATTR4_WORD0_CHANGE |
| 259 | | FATTR4_WORD0_SIZE |
| 260 | | FATTR4_WORD0_FSID |
| 261 | | FATTR4_WORD0_FILEID |
| 262 | | FATTR4_WORD0_FS_LOCATIONS, |
| 263 | FATTR4_WORD1_MODE |
| 264 | | FATTR4_WORD1_NUMLINKS |
| 265 | | FATTR4_WORD1_OWNER |
| 266 | | FATTR4_WORD1_OWNER_GROUP |
| 267 | | FATTR4_WORD1_RAWDEV |
| 268 | | FATTR4_WORD1_SPACE_USED |
| 269 | | FATTR4_WORD1_TIME_ACCESS |
| 270 | | FATTR4_WORD1_TIME_METADATA |
| 271 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 272 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 273 | }; |
| 274 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 275 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct nfs4_readdir_arg *readdir) |
| 277 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 278 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 281 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | readdir->cookie = 0; |
| 287 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 288 | if (cookie == 2) |
| 289 | return; |
| 290 | |
| 291 | /* |
| 292 | * NFSv4 servers do not return entries for '.' and '..' |
| 293 | * Therefore, we fake these entries here. We let '.' |
| 294 | * have cookie 0 and '..' have cookie 1. Note that |
| 295 | * when talking to the server, we always send cookie 0 |
| 296 | * instead of 1 or 2. |
| 297 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 298 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | if (cookie == 0) { |
| 301 | *p++ = xdr_one; /* next */ |
| 302 | *p++ = xdr_zero; /* cookie, first word */ |
| 303 | *p++ = xdr_one; /* cookie, second word */ |
| 304 | *p++ = xdr_one; /* entry len */ |
| 305 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 306 | p++; |
| 307 | *p++ = xdr_one; /* bitmap length */ |
| 308 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 309 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 310 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | *p++ = xdr_one; /* next */ |
| 314 | *p++ = xdr_zero; /* cookie, first word */ |
| 315 | *p++ = xdr_two; /* cookie, second word */ |
| 316 | *p++ = xdr_two; /* entry len */ |
| 317 | memcpy(p, "..\0\0", 4); /* entry */ |
| 318 | p++; |
| 319 | *p++ = xdr_one; /* bitmap length */ |
| 320 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 321 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 322 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | readdir->pgbase = (char *)p - (char *)start; |
| 325 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 326 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 329 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 330 | nfs4_stateid *stateid, |
| 331 | struct rpc_cred *cred) |
| 332 | { |
| 333 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 334 | |
| 335 | ops->test_and_free_expired(server, stateid, cred); |
| 336 | } |
| 337 | |
| 338 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 339 | nfs4_stateid *stateid, |
| 340 | struct rpc_cred *cred) |
| 341 | { |
| 342 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 343 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 344 | } |
| 345 | |
| 346 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 347 | const nfs4_stateid *stateid, |
| 348 | struct rpc_cred *cred) |
| 349 | { |
| 350 | nfs4_stateid tmp; |
| 351 | |
| 352 | nfs4_stateid_copy(&tmp, stateid); |
| 353 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 354 | } |
| 355 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 356 | static long nfs4_update_delay(long *timeout) |
| 357 | { |
| 358 | long ret; |
| 359 | if (!timeout) |
| 360 | return NFS4_POLL_RETRY_MAX; |
| 361 | if (*timeout <= 0) |
| 362 | *timeout = NFS4_POLL_RETRY_MIN; |
| 363 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 364 | *timeout = NFS4_POLL_RETRY_MAX; |
| 365 | ret = *timeout; |
| 366 | *timeout <<= 1; |
| 367 | return ret; |
| 368 | } |
| 369 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 370 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 371 | { |
| 372 | int res = 0; |
| 373 | |
| 374 | might_sleep(); |
| 375 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 376 | freezable_schedule_timeout_killable_unsafe( |
| 377 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 378 | if (fatal_signal_pending(current)) |
| 379 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | return res; |
| 381 | } |
| 382 | |
| 383 | /* This is the error handling routine for processes that are allowed |
| 384 | * to sleep. |
| 385 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 386 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 387 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 388 | { |
| 389 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 390 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 391 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 393 | int ret = errorcode; |
| 394 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 395 | exception->delay = 0; |
| 396 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 397 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 398 | |
| 399 | if (stateid == NULL && state != NULL) |
| 400 | stateid = &state->stateid; |
| 401 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 402 | switch(errorcode) { |
| 403 | case 0: |
| 404 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 405 | case -NFS4ERR_DELEG_REVOKED: |
| 406 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 407 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 408 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 409 | if (inode != NULL && stateid != NULL) { |
| 410 | nfs_inode_find_state_and_recover(inode, |
| 411 | stateid); |
| 412 | goto wait_on_recovery; |
| 413 | } |
| 414 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 415 | if (inode) { |
| 416 | int err; |
| 417 | |
| 418 | err = nfs_async_inode_return_delegation(inode, |
| 419 | stateid); |
| 420 | if (err == 0) |
| 421 | goto wait_on_recovery; |
| 422 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 423 | exception->retry = 1; |
| 424 | break; |
| 425 | } |
| 426 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 427 | if (state == NULL) |
| 428 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 429 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 430 | if (ret < 0) |
| 431 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 432 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 433 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 434 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 435 | nfs4_schedule_lease_recovery(clp); |
| 436 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 437 | case -NFS4ERR_MOVED: |
| 438 | ret = nfs4_schedule_migration_recovery(server); |
| 439 | if (ret < 0) |
| 440 | break; |
| 441 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 442 | case -NFS4ERR_LEASE_MOVED: |
| 443 | nfs4_schedule_lease_moved_recovery(clp); |
| 444 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 445 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 446 | case -NFS4ERR_BADSESSION: |
| 447 | case -NFS4ERR_BADSLOT: |
| 448 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 449 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 450 | case -NFS4ERR_DEADSESSION: |
| 451 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 452 | case -NFS4ERR_SEQ_MISORDERED: |
| 453 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 454 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 455 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 456 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 457 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 458 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 459 | if (exception->timeout > HZ) { |
| 460 | /* We have retried a decent amount, time to |
| 461 | * fail |
| 462 | */ |
| 463 | ret = -EBUSY; |
| 464 | break; |
| 465 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 466 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 467 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 468 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 469 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 470 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 471 | exception->delay = 1; |
| 472 | return 0; |
| 473 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 474 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 475 | case -NFS4ERR_OLD_STATEID: |
| 476 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 477 | break; |
| 478 | case -NFS4ERR_BADOWNER: |
| 479 | /* The following works around a Linux server bug! */ |
| 480 | case -NFS4ERR_BADNAME: |
| 481 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 482 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 483 | exception->retry = 1; |
| 484 | printk(KERN_WARNING "NFS: v4 server %s " |
| 485 | "does not accept raw " |
| 486 | "uid/gids. " |
| 487 | "Reenabling the idmapper.\n", |
| 488 | server->nfs_client->cl_hostname); |
| 489 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 490 | } |
| 491 | /* We failed to handle the error */ |
| 492 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 493 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 494 | exception->recovering = 1; |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* This is the error handling routine for processes that are allowed |
| 499 | * to sleep. |
| 500 | */ |
| 501 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 502 | { |
| 503 | struct nfs_client *clp = server->nfs_client; |
| 504 | int ret; |
| 505 | |
| 506 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 507 | if (exception->delay) { |
| 508 | ret = nfs4_delay(server->client, &exception->timeout); |
| 509 | goto out_retry; |
| 510 | } |
| 511 | if (exception->recovering) { |
| 512 | ret = nfs4_wait_clnt_recover(clp); |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | return -EIO; |
| 515 | goto out_retry; |
| 516 | } |
| 517 | return ret; |
| 518 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 519 | if (ret == 0) |
| 520 | exception->retry = 1; |
| 521 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 524 | static int |
| 525 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 526 | int errorcode, struct nfs4_exception *exception) |
| 527 | { |
| 528 | struct nfs_client *clp = server->nfs_client; |
| 529 | int ret; |
| 530 | |
| 531 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 532 | if (exception->delay) { |
| 533 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 534 | goto out_retry; |
| 535 | } |
| 536 | if (exception->recovering) { |
| 537 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 538 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 539 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 540 | goto out_retry; |
| 541 | } |
| 542 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 543 | ret = -EIO; |
| 544 | return ret; |
| 545 | out_retry: |
| 546 | if (ret == 0) |
| 547 | exception->retry = 1; |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | static int |
| 552 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 553 | struct nfs4_state *state, long *timeout) |
| 554 | { |
| 555 | struct nfs4_exception exception = { |
| 556 | .state = state, |
| 557 | }; |
| 558 | |
| 559 | if (task->tk_status >= 0) |
| 560 | return 0; |
| 561 | if (timeout) |
| 562 | exception.timeout = *timeout; |
| 563 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 564 | task->tk_status, |
| 565 | &exception); |
| 566 | if (exception.delay && timeout) |
| 567 | *timeout = exception.timeout; |
| 568 | if (exception.retry) |
| 569 | return -EAGAIN; |
| 570 | return 0; |
| 571 | } |
| 572 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 573 | /* |
| 574 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 575 | * or 'false' otherwise. |
| 576 | */ |
| 577 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 578 | { |
| 579 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
Anna Schumaker | eeea536 | 2017-01-11 16:01:21 -0500 | [diff] [blame] | 580 | return (flavor == RPC_AUTH_GSS_KRB5I) || (flavor == RPC_AUTH_GSS_KRB5P); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 581 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 582 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 583 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | spin_lock(&clp->cl_lock); |
| 586 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 587 | clp->cl_last_renewal = timestamp; |
| 588 | spin_unlock(&clp->cl_lock); |
| 589 | } |
| 590 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 591 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 592 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 593 | struct nfs_client *clp = server->nfs_client; |
| 594 | |
| 595 | if (!nfs4_has_session(clp)) |
| 596 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 597 | } |
| 598 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 599 | struct nfs4_call_sync_data { |
| 600 | const struct nfs_server *seq_server; |
| 601 | struct nfs4_sequence_args *seq_args; |
| 602 | struct nfs4_sequence_res *seq_res; |
| 603 | }; |
| 604 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 605 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 606 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 607 | { |
| 608 | args->sa_slot = NULL; |
| 609 | args->sa_cache_this = cache_reply; |
| 610 | args->sa_privileged = 0; |
| 611 | |
| 612 | res->sr_slot = NULL; |
| 613 | } |
| 614 | |
| 615 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 616 | { |
| 617 | args->sa_privileged = 1; |
| 618 | } |
| 619 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 620 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 621 | { |
| 622 | struct nfs4_slot *slot = res->sr_slot; |
| 623 | struct nfs4_slot_table *tbl; |
| 624 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 625 | tbl = slot->table; |
| 626 | spin_lock(&tbl->slot_tbl_lock); |
| 627 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 628 | nfs4_free_slot(tbl, slot); |
| 629 | spin_unlock(&tbl->slot_tbl_lock); |
| 630 | |
| 631 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static int nfs40_sequence_done(struct rpc_task *task, |
| 635 | struct nfs4_sequence_res *res) |
| 636 | { |
| 637 | if (res->sr_slot != NULL) |
| 638 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 639 | return 1; |
| 640 | } |
| 641 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 642 | #if defined(CONFIG_NFS_V4_1) |
| 643 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 644 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 645 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 646 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 647 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 648 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 649 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 650 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 651 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 652 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 653 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 654 | /* Bump the slot sequence number */ |
| 655 | if (slot->seq_done) |
| 656 | slot->seq_nr++; |
| 657 | slot->seq_done = 0; |
| 658 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 659 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 660 | /* Be nice to the server: try to ensure that the last transmitted |
| 661 | * value for highest_user_slotid <= target_highest_slotid |
| 662 | */ |
| 663 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 664 | send_new_highest_used_slotid = true; |
| 665 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 666 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 667 | send_new_highest_used_slotid = false; |
| 668 | goto out_unlock; |
| 669 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 670 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 671 | |
| 672 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 673 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 674 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 675 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 676 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 677 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 678 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 679 | if (waitqueue_active(&tbl->slot_waitq)) |
| 680 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 683 | static int nfs41_sequence_process(struct rpc_task *task, |
| 684 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 685 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 686 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 687 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 688 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 689 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 690 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 691 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 692 | if (slot == NULL) |
| 693 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 694 | /* don't increment the sequence number if the task wasn't sent */ |
| 695 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 696 | goto out; |
| 697 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 698 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 699 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 700 | if (slot->interrupted) { |
Olga Kornievskaia | 88bd4f8 | 2017-04-26 14:21:22 -0400 | [diff] [blame] | 701 | if (res->sr_status != -NFS4ERR_DELAY) |
| 702 | slot->interrupted = 0; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 703 | interrupted = true; |
| 704 | } |
| 705 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 706 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 707 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 708 | switch (res->sr_status) { |
| 709 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 710 | /* If previous op on slot was interrupted and we reused |
| 711 | * the seq# and got a reply from the cache, then retry |
| 712 | */ |
| 713 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 714 | ++slot->seq_nr; |
| 715 | goto retry_nowait; |
| 716 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 717 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 718 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 719 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 720 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 721 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 722 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 723 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 724 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 725 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 726 | case 1: |
| 727 | /* |
| 728 | * sr_status remains 1 if an RPC level error occurred. |
| 729 | * The server may or may not have processed the sequence |
| 730 | * operation.. |
| 731 | * Mark the slot as having hosted an interrupted RPC call. |
| 732 | */ |
| 733 | slot->interrupted = 1; |
| 734 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | case -NFS4ERR_DELAY: |
| 736 | /* The server detected a resend of the RPC call and |
| 737 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 738 | * of RFC5661. |
| 739 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 740 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 741 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 742 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 743 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 744 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 745 | case -NFS4ERR_BADSLOT: |
| 746 | /* |
| 747 | * The slot id we used was probably retired. Try again |
| 748 | * using a different slot id. |
| 749 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 750 | goto retry_nowait; |
| 751 | case -NFS4ERR_SEQ_MISORDERED: |
| 752 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 753 | * Was the last operation on this sequence interrupted? |
| 754 | * If so, retry after bumping the sequence number. |
| 755 | */ |
| 756 | if (interrupted) { |
| 757 | ++slot->seq_nr; |
| 758 | goto retry_nowait; |
| 759 | } |
| 760 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 761 | * Could this slot have been previously retired? |
| 762 | * If so, then the server may be expecting seq_nr = 1! |
| 763 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 764 | if (slot->seq_nr != 1) { |
| 765 | slot->seq_nr = 1; |
| 766 | goto retry_nowait; |
| 767 | } |
| 768 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 769 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 770 | ++slot->seq_nr; |
| 771 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 772 | default: |
| 773 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 774 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 775 | } |
| 776 | out: |
| 777 | /* The session may be reset by one of the error handlers. */ |
| 778 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 779 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 780 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 781 | retry_nowait: |
| 782 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 783 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 784 | task->tk_status = 0; |
| 785 | ret = 0; |
| 786 | } |
| 787 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 788 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 789 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 790 | goto out; |
| 791 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 792 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 793 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 794 | |
| 795 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 796 | { |
| 797 | if (!nfs41_sequence_process(task, res)) |
| 798 | return 0; |
| 799 | if (res->sr_slot != NULL) |
| 800 | nfs41_sequence_free_slot(res); |
| 801 | return 1; |
| 802 | |
| 803 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 804 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
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 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 807 | { |
| 808 | if (res->sr_slot == NULL) |
| 809 | return 1; |
| 810 | if (res->sr_slot->table->session != NULL) |
| 811 | return nfs41_sequence_process(task, res); |
| 812 | return nfs40_sequence_done(task, res); |
| 813 | } |
| 814 | |
| 815 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 816 | { |
| 817 | if (res->sr_slot != NULL) { |
| 818 | if (res->sr_slot->table->session != NULL) |
| 819 | nfs41_sequence_free_slot(res); |
| 820 | else |
| 821 | nfs40_sequence_free_slot(res); |
| 822 | } |
| 823 | } |
| 824 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 825 | 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] | 826 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 827 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 828 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 829 | if (!res->sr_slot->table->session) |
| 830 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 832 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 833 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 834 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 835 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 836 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 837 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 838 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 839 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 840 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 841 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 842 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 845 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 846 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 847 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 848 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 849 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 850 | } |
| 851 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 852 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 853 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 854 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 855 | }; |
| 856 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 857 | #else /* !CONFIG_NFS_V4_1 */ |
| 858 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 859 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 860 | { |
| 861 | return nfs40_sequence_done(task, res); |
| 862 | } |
| 863 | |
| 864 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 865 | { |
| 866 | if (res->sr_slot != NULL) |
| 867 | nfs40_sequence_free_slot(res); |
| 868 | } |
| 869 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 870 | int nfs4_sequence_done(struct rpc_task *task, |
| 871 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 872 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 873 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 874 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 875 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 876 | |
| 877 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 878 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 879 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 880 | struct nfs4_sequence_args *args, |
| 881 | struct nfs4_sequence_res *res, |
| 882 | struct rpc_task *task) |
| 883 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 884 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 885 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 886 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 887 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 888 | /* slot already allocated? */ |
| 889 | if (res->sr_slot != NULL) |
| 890 | goto out_start; |
| 891 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 892 | if (session) { |
| 893 | tbl = &session->fc_slot_table; |
| 894 | task->tk_timeout = 0; |
| 895 | } |
| 896 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 897 | spin_lock(&tbl->slot_tbl_lock); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 898 | /* The state manager will wait until the slot table is empty */ |
| 899 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 900 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 901 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 902 | slot = nfs4_alloc_slot(tbl); |
| 903 | if (IS_ERR(slot)) { |
| 904 | /* Try again in 1/4 second */ |
| 905 | if (slot == ERR_PTR(-ENOMEM)) |
| 906 | task->tk_timeout = HZ >> 2; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 907 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 908 | } |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 909 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 910 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 911 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 912 | args->sa_slot = slot; |
| 913 | |
| 914 | res->sr_slot = slot; |
| 915 | if (session) { |
| 916 | res->sr_timestamp = jiffies; |
| 917 | res->sr_status_flags = 0; |
| 918 | res->sr_status = 1; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 919 | } |
| 920 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 921 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 922 | out_start: |
| 923 | rpc_call_start(task); |
| 924 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 925 | |
| 926 | out_sleep: |
| 927 | if (args->sa_privileged) |
| 928 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 929 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 930 | else |
| 931 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 932 | spin_unlock(&tbl->slot_tbl_lock); |
| 933 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 934 | } |
| 935 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 936 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 937 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 938 | { |
| 939 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 940 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 941 | data->seq_args, data->seq_res, task); |
| 942 | } |
| 943 | |
| 944 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 945 | { |
| 946 | struct nfs4_call_sync_data *data = calldata; |
| 947 | nfs4_sequence_done(task, data->seq_res); |
| 948 | } |
| 949 | |
| 950 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 951 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 952 | .rpc_call_done = nfs40_call_sync_done, |
| 953 | }; |
| 954 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 955 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 956 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 957 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 958 | struct nfs4_sequence_args *args, |
| 959 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 960 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 961 | int ret; |
| 962 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 963 | struct nfs_client *clp = server->nfs_client; |
| 964 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 965 | .seq_server = server, |
| 966 | .seq_args = args, |
| 967 | .seq_res = res, |
| 968 | }; |
| 969 | struct rpc_task_setup task_setup = { |
| 970 | .rpc_client = clnt, |
| 971 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 972 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 973 | .callback_data = &data |
| 974 | }; |
| 975 | |
| 976 | task = rpc_run_task(&task_setup); |
| 977 | if (IS_ERR(task)) |
| 978 | ret = PTR_ERR(task); |
| 979 | else { |
| 980 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 981 | rpc_put_task(task); |
| 982 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 983 | return ret; |
| 984 | } |
| 985 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 986 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 987 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 988 | struct rpc_message *msg, |
| 989 | struct nfs4_sequence_args *args, |
| 990 | struct nfs4_sequence_res *res, |
| 991 | int cache_reply) |
| 992 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 993 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 994 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 997 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 998 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | { |
| 1000 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1001 | |
| 1002 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1003 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1004 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1005 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1006 | nfsi->attrtimeo_timestamp = jiffies; |
| 1007 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1009 | if (cinfo->before != dir->i_version) |
| 1010 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1011 | NFS_INO_INVALID_ACL; |
| 1012 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1013 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1014 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1015 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1016 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | spin_unlock(&dir->i_lock); |
| 1018 | } |
| 1019 | |
| 1020 | struct nfs4_opendata { |
| 1021 | struct kref kref; |
| 1022 | struct nfs_openargs o_arg; |
| 1023 | struct nfs_openres o_res; |
| 1024 | struct nfs_open_confirmargs c_arg; |
| 1025 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1026 | struct nfs4_string owner_name; |
| 1027 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1028 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1030 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1032 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | struct nfs4_state_owner *owner; |
| 1034 | struct nfs4_state *state; |
| 1035 | struct iattr attrs; |
| 1036 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1037 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1038 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1039 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1040 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | int cancelled; |
| 1042 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1043 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1044 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1045 | int err, struct nfs4_exception *exception) |
| 1046 | { |
| 1047 | if (err != -EINVAL) |
| 1048 | return false; |
| 1049 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1050 | return false; |
| 1051 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1052 | exception->retry = 1; |
| 1053 | return true; |
| 1054 | } |
| 1055 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1056 | static u32 |
| 1057 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1058 | fmode_t fmode, int openflags) |
| 1059 | { |
| 1060 | u32 res = 0; |
| 1061 | |
| 1062 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1063 | case FMODE_READ: |
| 1064 | res = NFS4_SHARE_ACCESS_READ; |
| 1065 | break; |
| 1066 | case FMODE_WRITE: |
| 1067 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1068 | break; |
| 1069 | case FMODE_READ|FMODE_WRITE: |
| 1070 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1071 | } |
| 1072 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1073 | goto out; |
| 1074 | /* Want no delegation if we're using O_DIRECT */ |
| 1075 | if (openflags & O_DIRECT) |
| 1076 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1077 | out: |
| 1078 | return res; |
| 1079 | } |
| 1080 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1081 | static enum open_claim_type4 |
| 1082 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1083 | enum open_claim_type4 claim) |
| 1084 | { |
| 1085 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1086 | return claim; |
| 1087 | switch (claim) { |
| 1088 | default: |
| 1089 | return claim; |
| 1090 | case NFS4_OPEN_CLAIM_FH: |
| 1091 | return NFS4_OPEN_CLAIM_NULL; |
| 1092 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1093 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1094 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1095 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1096 | } |
| 1097 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1100 | { |
| 1101 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1102 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1103 | p->o_res.seqid = p->o_arg.seqid; |
| 1104 | p->c_res.seqid = p->c_arg.seqid; |
| 1105 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1106 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1107 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1108 | 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] | 1109 | } |
| 1110 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1111 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1112 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1113 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1114 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1115 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1116 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1117 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1118 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1119 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1120 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1121 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1122 | struct nfs4_opendata *p; |
| 1123 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1124 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1125 | if (p == NULL) |
| 1126 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1127 | |
| 1128 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1129 | if (IS_ERR(p->f_label)) |
| 1130 | goto err_free_p; |
| 1131 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1132 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1133 | if (IS_ERR(p->a_label)) |
| 1134 | goto err_free_f; |
| 1135 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1136 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1137 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1138 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1139 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1140 | nfs_sb_active(dentry->d_sb); |
| 1141 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1142 | p->dir = parent; |
| 1143 | p->owner = sp; |
| 1144 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1145 | p->o_arg.open_flags = flags; |
| 1146 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1147 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1148 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1149 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1150 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1151 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1152 | * will return permission denied for all bits until close */ |
| 1153 | if (!(flags & O_EXCL)) { |
| 1154 | /* ask server to check for all possible rights as results |
| 1155 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1156 | switch (p->o_arg.claim) { |
| 1157 | default: |
| 1158 | break; |
| 1159 | case NFS4_OPEN_CLAIM_NULL: |
| 1160 | case NFS4_OPEN_CLAIM_FH: |
| 1161 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1162 | NFS4_ACCESS_MODIFY | |
| 1163 | NFS4_ACCESS_EXTEND | |
| 1164 | NFS4_ACCESS_EXECUTE; |
| 1165 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1166 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1167 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1168 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1169 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1170 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1171 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1172 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1173 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1174 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1175 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1176 | case NFS4_OPEN_CLAIM_NULL: |
| 1177 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1178 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1179 | p->o_arg.fh = NFS_FH(dir); |
| 1180 | break; |
| 1181 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1182 | case NFS4_OPEN_CLAIM_FH: |
| 1183 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1184 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1185 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1186 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1187 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1188 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1189 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1190 | p->o_arg.u.attrs = &p->attrs; |
| 1191 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1192 | |
| 1193 | verf[0] = jiffies; |
| 1194 | verf[1] = current->pid; |
| 1195 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1196 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1197 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1198 | p->c_arg.fh = &p->o_res.fh; |
| 1199 | p->c_arg.stateid = &p->o_res.stateid; |
| 1200 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1201 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1202 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1203 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1204 | |
| 1205 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1206 | nfs4_label_free(p->a_label); |
| 1207 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1208 | nfs4_label_free(p->f_label); |
| 1209 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1210 | kfree(p); |
| 1211 | err: |
| 1212 | dput(parent); |
| 1213 | return NULL; |
| 1214 | } |
| 1215 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1216 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1217 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1218 | struct nfs4_opendata *p = container_of(kref, |
| 1219 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1220 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1221 | |
| 1222 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1223 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1224 | if (p->state != NULL) |
| 1225 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1226 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1227 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1228 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1229 | nfs4_label_free(p->f_label); |
| 1230 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1231 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1232 | dput(p->dentry); |
| 1233 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1234 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1235 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1236 | kfree(p); |
| 1237 | } |
| 1238 | |
| 1239 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1240 | { |
| 1241 | if (p != NULL) |
| 1242 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1245 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1246 | fmode_t fmode) |
| 1247 | { |
| 1248 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1249 | case FMODE_READ|FMODE_WRITE: |
| 1250 | return state->n_rdwr != 0; |
| 1251 | case FMODE_WRITE: |
| 1252 | return state->n_wronly != 0; |
| 1253 | case FMODE_READ: |
| 1254 | return state->n_rdonly != 0; |
| 1255 | } |
| 1256 | WARN_ON_ONCE(1); |
| 1257 | return false; |
| 1258 | } |
| 1259 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1260 | 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] | 1261 | { |
| 1262 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1263 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1264 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1265 | goto out; |
| 1266 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1267 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1268 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1269 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1270 | break; |
| 1271 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1272 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1273 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1274 | break; |
| 1275 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1276 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1277 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1278 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1279 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1283 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1284 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1285 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1286 | if (delegation == NULL) |
| 1287 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1288 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1289 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1290 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1291 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1292 | switch (claim) { |
| 1293 | case NFS4_OPEN_CLAIM_NULL: |
| 1294 | case NFS4_OPEN_CLAIM_FH: |
| 1295 | break; |
| 1296 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1297 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1298 | break; |
| 1299 | default: |
| 1300 | return 0; |
| 1301 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1302 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1303 | return 1; |
| 1304 | } |
| 1305 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1306 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1307 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1308 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1309 | case FMODE_WRITE: |
| 1310 | state->n_wronly++; |
| 1311 | break; |
| 1312 | case FMODE_READ: |
| 1313 | state->n_rdonly++; |
| 1314 | break; |
| 1315 | case FMODE_READ|FMODE_WRITE: |
| 1316 | state->n_rdwr++; |
| 1317 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1319 | } |
| 1320 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1321 | #ifdef CONFIG_NFS_V4_1 |
| 1322 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1323 | { |
| 1324 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1325 | return true; |
| 1326 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1327 | return true; |
| 1328 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1329 | return true; |
| 1330 | return false; |
| 1331 | } |
| 1332 | #endif /* CONFIG_NFS_V4_1 */ |
| 1333 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1334 | 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] | 1335 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1336 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1337 | bool need_recover = false; |
| 1338 | |
| 1339 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1340 | need_recover = true; |
| 1341 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1342 | need_recover = true; |
| 1343 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1344 | need_recover = true; |
| 1345 | if (need_recover) |
| 1346 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1347 | } |
| 1348 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1349 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1350 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1351 | { |
| 1352 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1353 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1354 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1355 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1356 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1357 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1358 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1359 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1360 | return true; |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1364 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1365 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1366 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1367 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1368 | if (state->n_wronly) |
| 1369 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1370 | if (state->n_rdonly) |
| 1371 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1372 | if (state->n_rdwr) |
| 1373 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1374 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1375 | } |
| 1376 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1377 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1378 | nfs4_stateid *stateid, fmode_t fmode) |
| 1379 | { |
| 1380 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1381 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1382 | case FMODE_WRITE: |
| 1383 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1384 | break; |
| 1385 | case FMODE_READ: |
| 1386 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1387 | break; |
| 1388 | case 0: |
| 1389 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1390 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1391 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1392 | } |
| 1393 | if (stateid == NULL) |
| 1394 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1395 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1396 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1397 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1398 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1399 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1400 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1401 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1402 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1403 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1404 | } |
| 1405 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1406 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1407 | nfs4_stateid *arg_stateid, |
| 1408 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1409 | { |
| 1410 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1411 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1412 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1413 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1414 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1415 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1416 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1417 | } |
| 1418 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1419 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1420 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1421 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1422 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1423 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1424 | case FMODE_READ: |
| 1425 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1426 | break; |
| 1427 | case FMODE_WRITE: |
| 1428 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1429 | break; |
| 1430 | case FMODE_READ|FMODE_WRITE: |
| 1431 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1432 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1433 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1434 | return; |
| 1435 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1436 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1437 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1440 | static void __update_open_stateid(struct nfs4_state *state, |
| 1441 | const nfs4_stateid *open_stateid, |
| 1442 | const nfs4_stateid *deleg_stateid, |
| 1443 | fmode_t fmode, |
| 1444 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1446 | /* |
| 1447 | * Protect the call to nfs4_state_set_mode_locked and |
| 1448 | * serialise the stateid update |
| 1449 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1450 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1451 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1452 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1453 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1454 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1455 | } |
| 1456 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1457 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1458 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1459 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1460 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1463 | static int update_open_stateid(struct nfs4_state *state, |
| 1464 | const nfs4_stateid *open_stateid, |
| 1465 | const nfs4_stateid *delegation, |
| 1466 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1467 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1468 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1469 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1470 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1471 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1472 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1473 | int ret = 0; |
| 1474 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1476 | |
| 1477 | rcu_read_lock(); |
| 1478 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1479 | if (deleg_cur == NULL) |
| 1480 | goto no_delegation; |
| 1481 | |
| 1482 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1483 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1484 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1485 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1486 | goto no_delegation_unlock; |
| 1487 | |
| 1488 | if (delegation == NULL) |
| 1489 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1490 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1491 | goto no_delegation_unlock; |
| 1492 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1493 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1494 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1495 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1496 | ret = 1; |
| 1497 | no_delegation_unlock: |
| 1498 | spin_unlock(&deleg_cur->lock); |
| 1499 | no_delegation: |
| 1500 | rcu_read_unlock(); |
| 1501 | |
| 1502 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1503 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1504 | ret = 1; |
| 1505 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1506 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1507 | nfs4_schedule_state_manager(clp); |
| 1508 | if (freeme.type != 0) |
| 1509 | nfs4_test_and_free_stateid(server, &freeme, |
| 1510 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1511 | |
| 1512 | return ret; |
| 1513 | } |
| 1514 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1515 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1516 | const nfs4_stateid *stateid) |
| 1517 | { |
| 1518 | struct nfs4_state *state = lsp->ls_state; |
| 1519 | bool ret = false; |
| 1520 | |
| 1521 | spin_lock(&state->state_lock); |
| 1522 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1523 | goto out_noupdate; |
| 1524 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1525 | goto out_noupdate; |
| 1526 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1527 | ret = true; |
| 1528 | out_noupdate: |
| 1529 | spin_unlock(&state->state_lock); |
| 1530 | return ret; |
| 1531 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1532 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1533 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1534 | { |
| 1535 | struct nfs_delegation *delegation; |
| 1536 | |
| 1537 | rcu_read_lock(); |
| 1538 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1539 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1540 | rcu_read_unlock(); |
| 1541 | return; |
| 1542 | } |
| 1543 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1544 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1545 | } |
| 1546 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1547 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | { |
| 1549 | struct nfs4_state *state = opendata->state; |
| 1550 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1551 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1552 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1553 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1554 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1555 | nfs4_stateid stateid; |
| 1556 | int ret = -EAGAIN; |
| 1557 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1558 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1559 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1560 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1561 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1562 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1563 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1564 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1565 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1566 | rcu_read_lock(); |
| 1567 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1568 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1569 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1570 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1571 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1572 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1573 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1574 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1575 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1576 | if (!opendata->is_recover) { |
| 1577 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1578 | if (ret != 0) |
| 1579 | goto out; |
| 1580 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1581 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1582 | |
| 1583 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1584 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1585 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1586 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1587 | out: |
| 1588 | return ERR_PTR(ret); |
| 1589 | out_return_state: |
| 1590 | atomic_inc(&state->count); |
| 1591 | return state; |
| 1592 | } |
| 1593 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1594 | static void |
| 1595 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1596 | { |
| 1597 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1598 | struct nfs_delegation *delegation; |
| 1599 | int delegation_flags = 0; |
| 1600 | |
| 1601 | rcu_read_lock(); |
| 1602 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1603 | if (delegation) |
| 1604 | delegation_flags = delegation->flags; |
| 1605 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1606 | switch (data->o_arg.claim) { |
| 1607 | default: |
| 1608 | break; |
| 1609 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1610 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1611 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1612 | "returning a delegation for " |
| 1613 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1614 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1615 | return; |
| 1616 | } |
| 1617 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1618 | nfs_inode_set_delegation(state->inode, |
| 1619 | data->owner->so_cred, |
| 1620 | &data->o_res); |
| 1621 | else |
| 1622 | nfs_inode_reclaim_delegation(state->inode, |
| 1623 | data->owner->so_cred, |
| 1624 | &data->o_res); |
| 1625 | } |
| 1626 | |
| 1627 | /* |
| 1628 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1629 | * and update the nfs4_state. |
| 1630 | */ |
| 1631 | static struct nfs4_state * |
| 1632 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1633 | { |
| 1634 | struct inode *inode = data->state->inode; |
| 1635 | struct nfs4_state *state = data->state; |
| 1636 | int ret; |
| 1637 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1638 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1639 | if (data->rpc_status) |
| 1640 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1641 | /* cached opens have already been processed */ |
| 1642 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1645 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1646 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1647 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1648 | |
| 1649 | if (data->o_res.delegation_type != 0) |
| 1650 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1651 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1652 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1653 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1654 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | |
| 1656 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | static struct nfs4_state * |
| 1660 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1661 | { |
| 1662 | struct inode *inode; |
| 1663 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1664 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1665 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1666 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1667 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1668 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | goto out; |
| 1670 | } |
| 1671 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1672 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1673 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1674 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1675 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr, data->f_label); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1676 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1677 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1678 | goto err; |
| 1679 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1680 | state = nfs4_get_open_state(inode, data->owner); |
| 1681 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1682 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1683 | if (data->o_res.delegation_type != 0) |
| 1684 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1685 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1686 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1687 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1688 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1689 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1690 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1691 | err_put_inode: |
| 1692 | iput(inode); |
| 1693 | err: |
| 1694 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1697 | static struct nfs4_state * |
| 1698 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1699 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1700 | struct nfs4_state *ret; |
| 1701 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1702 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1703 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1704 | else |
| 1705 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1706 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1707 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1710 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1711 | { |
| 1712 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1713 | struct nfs_open_context *ctx; |
| 1714 | |
| 1715 | spin_lock(&state->inode->i_lock); |
| 1716 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1717 | if (ctx->state != state) |
| 1718 | continue; |
| 1719 | get_nfs_open_context(ctx); |
| 1720 | spin_unlock(&state->inode->i_lock); |
| 1721 | return ctx; |
| 1722 | } |
| 1723 | spin_unlock(&state->inode->i_lock); |
| 1724 | return ERR_PTR(-ENOENT); |
| 1725 | } |
| 1726 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1727 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1728 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1729 | { |
| 1730 | struct nfs4_opendata *opendata; |
| 1731 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1732 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1733 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1734 | if (opendata == NULL) |
| 1735 | return ERR_PTR(-ENOMEM); |
| 1736 | opendata->state = state; |
| 1737 | atomic_inc(&state->count); |
| 1738 | return opendata; |
| 1739 | } |
| 1740 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1741 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1742 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1743 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1744 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1745 | int ret; |
| 1746 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1747 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1748 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1749 | opendata->o_arg.open_flags = 0; |
| 1750 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1751 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1752 | NFS_SB(opendata->dentry->d_sb), |
| 1753 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1754 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1755 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1756 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1757 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | if (ret != 0) |
| 1759 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1760 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1761 | if (IS_ERR(newstate)) |
| 1762 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1763 | if (newstate != opendata->state) |
| 1764 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1765 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1766 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1770 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1771 | int ret; |
| 1772 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1773 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1774 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1775 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1776 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1777 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1778 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1779 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1781 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1782 | if (ret != 0) |
| 1783 | return ret; |
| 1784 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1785 | if (ret != 0) |
| 1786 | return ret; |
| 1787 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1788 | if (ret != 0) |
| 1789 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1790 | /* |
| 1791 | * We may have performed cached opens for all three recoveries. |
| 1792 | * Check if we need to update the current stateid. |
| 1793 | */ |
| 1794 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1795 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1796 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1797 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1798 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1799 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1800 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1801 | return 0; |
| 1802 | } |
| 1803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | /* |
| 1805 | * OPEN_RECLAIM: |
| 1806 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1808 | 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] | 1809 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1810 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1811 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1812 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | int status; |
| 1814 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1815 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1816 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1817 | if (IS_ERR(opendata)) |
| 1818 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1819 | rcu_read_lock(); |
| 1820 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1821 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1822 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1823 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1825 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1826 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | return status; |
| 1828 | } |
| 1829 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1830 | 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] | 1831 | { |
| 1832 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1833 | struct nfs4_exception exception = { }; |
| 1834 | int err; |
| 1835 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1836 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1837 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1838 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1839 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1840 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1841 | break; |
| 1842 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } while (exception.retry); |
| 1844 | return err; |
| 1845 | } |
| 1846 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1847 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1848 | { |
| 1849 | struct nfs_open_context *ctx; |
| 1850 | int ret; |
| 1851 | |
| 1852 | ctx = nfs4_state_find_open_context(state); |
| 1853 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1854 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1855 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1856 | put_nfs_open_context(ctx); |
| 1857 | return ret; |
| 1858 | } |
| 1859 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1860 | 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] | 1861 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1862 | switch (err) { |
| 1863 | default: |
| 1864 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1865 | "%d.\n", __func__, err); |
| 1866 | case 0: |
| 1867 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1868 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1869 | case -ESTALE: |
| 1870 | break; |
| 1871 | case -NFS4ERR_BADSESSION: |
| 1872 | case -NFS4ERR_BADSLOT: |
| 1873 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1874 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1875 | case -NFS4ERR_DEADSESSION: |
| 1876 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1877 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1878 | return -EAGAIN; |
| 1879 | case -NFS4ERR_STALE_CLIENTID: |
| 1880 | case -NFS4ERR_STALE_STATEID: |
| 1881 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1882 | /* Don't recall a delegation if it was lost */ |
| 1883 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1884 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1885 | case -NFS4ERR_MOVED: |
| 1886 | nfs4_schedule_migration_recovery(server); |
| 1887 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1888 | case -NFS4ERR_LEASE_MOVED: |
| 1889 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1890 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1891 | case -NFS4ERR_DELEG_REVOKED: |
| 1892 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1893 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1894 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1895 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1896 | nfs_inode_find_state_and_recover(state->inode, |
| 1897 | stateid); |
| 1898 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1899 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1900 | case -NFS4ERR_DELAY: |
| 1901 | case -NFS4ERR_GRACE: |
| 1902 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1903 | ssleep(1); |
| 1904 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1905 | case -ENOMEM: |
| 1906 | case -NFS4ERR_DENIED: |
| 1907 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1908 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | return err; |
| 1911 | } |
| 1912 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1913 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1914 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1915 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1916 | { |
| 1917 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1918 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1919 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1920 | |
| 1921 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1922 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1923 | if (IS_ERR(opendata)) |
| 1924 | return PTR_ERR(opendata); |
| 1925 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1926 | write_seqlock(&state->seqlock); |
| 1927 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1928 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1929 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1930 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1931 | case FMODE_READ|FMODE_WRITE: |
| 1932 | case FMODE_WRITE: |
| 1933 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1934 | if (err) |
| 1935 | break; |
| 1936 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1937 | if (err) |
| 1938 | break; |
| 1939 | case FMODE_READ: |
| 1940 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1941 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1942 | nfs4_opendata_put(opendata); |
| 1943 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1944 | } |
| 1945 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1946 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1947 | { |
| 1948 | struct nfs4_opendata *data = calldata; |
| 1949 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1950 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1951 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1952 | } |
| 1953 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1954 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1955 | { |
| 1956 | struct nfs4_opendata *data = calldata; |
| 1957 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1958 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1959 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1960 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1961 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1962 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1963 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1964 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1965 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1966 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | static void nfs4_open_confirm_release(void *calldata) |
| 1970 | { |
| 1971 | struct nfs4_opendata *data = calldata; |
| 1972 | struct nfs4_state *state = NULL; |
| 1973 | |
| 1974 | /* If this request hasn't been cancelled, do nothing */ |
| 1975 | if (data->cancelled == 0) |
| 1976 | goto out_free; |
| 1977 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1978 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1979 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1980 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1981 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1982 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1983 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1984 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1988 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1989 | .rpc_call_done = nfs4_open_confirm_done, |
| 1990 | .rpc_release = nfs4_open_confirm_release, |
| 1991 | }; |
| 1992 | |
| 1993 | /* |
| 1994 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1995 | */ |
| 1996 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1997 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1998 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1999 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2000 | struct rpc_message msg = { |
| 2001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2002 | .rpc_argp = &data->c_arg, |
| 2003 | .rpc_resp = &data->c_res, |
| 2004 | .rpc_cred = data->owner->so_cred, |
| 2005 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2006 | struct rpc_task_setup task_setup_data = { |
| 2007 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2008 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2009 | .callback_ops = &nfs4_open_confirm_ops, |
| 2010 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2011 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2012 | .flags = RPC_TASK_ASYNC, |
| 2013 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | int status; |
| 2015 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2016 | 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] | 2017 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2018 | data->rpc_done = 0; |
| 2019 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2020 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2021 | if (data->is_recover) |
| 2022 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2023 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2024 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2025 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2026 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2027 | if (status != 0) { |
| 2028 | data->cancelled = 1; |
| 2029 | smp_wmb(); |
| 2030 | } else |
| 2031 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2032 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | return status; |
| 2034 | } |
| 2035 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2036 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2038 | struct nfs4_opendata *data = calldata; |
| 2039 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2040 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2041 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2042 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2043 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2044 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2045 | /* |
| 2046 | * Check if we still need to send an OPEN call, or if we can use |
| 2047 | * a delegation instead. |
| 2048 | */ |
| 2049 | if (data->state != NULL) { |
| 2050 | struct nfs_delegation *delegation; |
| 2051 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2052 | 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] | 2053 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2054 | rcu_read_lock(); |
| 2055 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2056 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2057 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2058 | rcu_read_unlock(); |
| 2059 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2060 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2061 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2062 | switch (claim) { |
| 2063 | default: |
| 2064 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2065 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2066 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2067 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2068 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2069 | case NFS4_OPEN_CLAIM_FH: |
| 2070 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2071 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2072 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2073 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2074 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2075 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2076 | &data->o_res.seq_res, |
| 2077 | task) != 0) |
| 2078 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2079 | |
| 2080 | /* Set the create mode (note dependency on the session type) */ |
| 2081 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2082 | if (data->o_arg.open_flags & O_EXCL) { |
| 2083 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2084 | if (nfs4_has_persistent_session(clp)) |
| 2085 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2086 | else if (clp->cl_mvops->minor_version > 0) |
| 2087 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2088 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2089 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2090 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2091 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2092 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2093 | out_no_action: |
| 2094 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2095 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2096 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2099 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2100 | { |
| 2101 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2103 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2104 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2105 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2106 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2107 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2108 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2109 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2110 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2111 | case S_IFREG: |
| 2112 | break; |
| 2113 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2114 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2115 | break; |
| 2116 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2117 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2118 | break; |
| 2119 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2120 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2121 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2122 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2123 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2124 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2125 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2126 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2127 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2128 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2129 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2130 | static void nfs4_open_release(void *calldata) |
| 2131 | { |
| 2132 | struct nfs4_opendata *data = calldata; |
| 2133 | struct nfs4_state *state = NULL; |
| 2134 | |
| 2135 | /* If this request hasn't been cancelled, do nothing */ |
| 2136 | if (data->cancelled == 0) |
| 2137 | goto out_free; |
| 2138 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2139 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2140 | goto out_free; |
| 2141 | /* In case we need an open_confirm, no cleanup! */ |
| 2142 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2143 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +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 | 24ac23a | 2006-01-03 09:55:11 +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 | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2152 | .rpc_call_prepare = nfs4_open_prepare, |
| 2153 | .rpc_call_done = nfs4_open_done, |
| 2154 | .rpc_release = nfs4_open_release, |
| 2155 | }; |
| 2156 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2157 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2158 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2159 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | struct nfs_server *server = NFS_SERVER(dir); |
| 2161 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2162 | struct nfs_openres *o_res = &data->o_res; |
| 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], |
| 2166 | .rpc_argp = o_arg, |
| 2167 | .rpc_resp = o_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_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 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2178 | int status; |
| 2179 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2180 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2181 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2182 | data->rpc_done = 0; |
| 2183 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2184 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2185 | data->is_recover = 0; |
| 2186 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2187 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2188 | data->is_recover = 1; |
| 2189 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2190 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2191 | if (IS_ERR(task)) |
| 2192 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2193 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2194 | if (status != 0) { |
| 2195 | data->cancelled = 1; |
| 2196 | smp_wmb(); |
| 2197 | } else |
| 2198 | status = data->rpc_status; |
| 2199 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2200 | |
| 2201 | return status; |
| 2202 | } |
| 2203 | |
| 2204 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2205 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2206 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2207 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2208 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2209 | |
| 2210 | status = nfs4_run_open_task(data, 1); |
| 2211 | if (status != 0 || !data->rpc_done) |
| 2212 | return status; |
| 2213 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2214 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2215 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2216 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2217 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2218 | |
| 2219 | return status; |
| 2220 | } |
| 2221 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2222 | /* |
| 2223 | * Additional permission checks in order to distinguish between an |
| 2224 | * open for read, and an open for execute. This works around the |
| 2225 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2226 | * the same. |
| 2227 | * Note that in the non-execute case, we want to turn off permission |
| 2228 | * checking if we just created a new file (POSIX open() semantics). |
| 2229 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2230 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2231 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2232 | struct nfs4_state *state, fmode_t fmode, |
| 2233 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2234 | { |
| 2235 | struct nfs_access_entry cache; |
| 2236 | u32 mask; |
| 2237 | |
| 2238 | /* access call failed or for some reason the server doesn't |
| 2239 | * support any access modes -- defer access call until later */ |
| 2240 | if (opendata->o_res.access_supported == 0) |
| 2241 | return 0; |
| 2242 | |
| 2243 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2244 | /* |
| 2245 | * Use openflags to check for exec, because fmode won't |
| 2246 | * always have FMODE_EXEC set when file open for exec. |
| 2247 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2248 | if (openflags & __FMODE_EXEC) { |
| 2249 | /* ONLY check for exec rights */ |
| 2250 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2251 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2252 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2253 | |
| 2254 | cache.cred = cred; |
| 2255 | cache.jiffies = jiffies; |
| 2256 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2257 | nfs_access_add_cache(state->inode, &cache); |
| 2258 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2259 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2260 | return 0; |
| 2261 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2262 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2263 | } |
| 2264 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2265 | /* |
| 2266 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2267 | */ |
| 2268 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2269 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2270 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2271 | struct nfs_server *server = NFS_SERVER(dir); |
| 2272 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2273 | struct nfs_openres *o_res = &data->o_res; |
| 2274 | int status; |
| 2275 | |
| 2276 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2277 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2278 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2279 | if (status != 0) { |
| 2280 | if (status == -NFS4ERR_BADNAME && |
| 2281 | !(o_arg->open_flags & O_CREAT)) |
| 2282 | return -ENOENT; |
| 2283 | return status; |
| 2284 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2285 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2286 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2287 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2288 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2289 | if (o_arg->open_flags & O_EXCL) |
| 2290 | data->file_created = 1; |
| 2291 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2292 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2293 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2294 | update_changeattr(dir, &o_res->cinfo, |
| 2295 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2296 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2297 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2298 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2300 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2302 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | } |
Trond Myklebust | 56e0d71 | 2017-04-15 19:20:01 -0400 | [diff] [blame] | 2304 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) { |
| 2305 | nfs4_sequence_free_slot(&o_res->seq_res); |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2306 | 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] | 2307 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2308 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | /* |
| 2312 | * OPEN_EXPIRED: |
| 2313 | * reclaim state on the server after a network partition. |
| 2314 | * Assumes caller holds the appropriate lock |
| 2315 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2316 | 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] | 2317 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2318 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2319 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2321 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2322 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2323 | if (IS_ERR(opendata)) |
| 2324 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2325 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2326 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2327 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2328 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2329 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2332 | 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] | 2333 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2334 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2335 | struct nfs4_exception exception = { }; |
| 2336 | int err; |
| 2337 | |
| 2338 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2339 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2340 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2341 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2342 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2343 | switch (err) { |
| 2344 | default: |
| 2345 | goto out; |
| 2346 | case -NFS4ERR_GRACE: |
| 2347 | case -NFS4ERR_DELAY: |
| 2348 | nfs4_handle_exception(server, err, &exception); |
| 2349 | err = 0; |
| 2350 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2351 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2352 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2353 | return err; |
| 2354 | } |
| 2355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2357 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2359 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2361 | ctx = nfs4_state_find_open_context(state); |
| 2362 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2363 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2364 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2365 | put_nfs_open_context(ctx); |
| 2366 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2369 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2370 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2371 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2372 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2373 | write_seqlock(&state->seqlock); |
| 2374 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2375 | write_sequnlock(&state->seqlock); |
| 2376 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2377 | } |
| 2378 | |
| 2379 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2380 | { |
| 2381 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2382 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2386 | { |
| 2387 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2388 | nfs40_clear_delegation_stateid(state); |
| 2389 | return nfs4_open_expired(sp, state); |
| 2390 | } |
| 2391 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2392 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2393 | nfs4_stateid *stateid, |
| 2394 | struct rpc_cred *cred) |
| 2395 | { |
| 2396 | return -NFS4ERR_BAD_STATEID; |
| 2397 | } |
| 2398 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2399 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2400 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2401 | nfs4_stateid *stateid, |
| 2402 | struct rpc_cred *cred) |
| 2403 | { |
| 2404 | int status; |
| 2405 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2406 | switch (stateid->type) { |
| 2407 | default: |
| 2408 | break; |
| 2409 | case NFS4_INVALID_STATEID_TYPE: |
| 2410 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2411 | return -NFS4ERR_BAD_STATEID; |
| 2412 | case NFS4_REVOKED_STATEID_TYPE: |
| 2413 | goto out_free; |
| 2414 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2415 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2416 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2417 | switch (status) { |
| 2418 | case -NFS4ERR_EXPIRED: |
| 2419 | case -NFS4ERR_ADMIN_REVOKED: |
| 2420 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2421 | break; |
| 2422 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2423 | return status; |
| 2424 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2425 | out_free: |
| 2426 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2427 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2428 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2429 | } |
| 2430 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2431 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2432 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2433 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2434 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2435 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2436 | struct rpc_cred *cred; |
| 2437 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2438 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2439 | /* Get the delegation credential for use by test/free_stateid */ |
| 2440 | rcu_read_lock(); |
| 2441 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2442 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2443 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2444 | return; |
| 2445 | } |
| 2446 | |
| 2447 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2448 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2449 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2450 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2451 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2452 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2453 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2454 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2455 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2456 | cred = get_rpccred(delegation->cred); |
| 2457 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2458 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2459 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2460 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2461 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2462 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2463 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2467 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2468 | * |
| 2469 | * @state: NFSv4 state for an inode |
| 2470 | * |
| 2471 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2472 | * Otherwise a negative NFS4ERR value is returned. |
| 2473 | */ |
| 2474 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2475 | { |
| 2476 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2477 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2478 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2479 | |
| 2480 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2481 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2482 | |
| 2483 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2484 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2485 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2486 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2487 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2488 | atomic_inc(&lsp->ls_count); |
| 2489 | spin_unlock(&state->state_lock); |
| 2490 | |
| 2491 | nfs4_put_lock_state(prev); |
| 2492 | prev = lsp; |
| 2493 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2494 | status = nfs41_test_and_free_expired_stateid(server, |
| 2495 | &lsp->ls_stateid, |
| 2496 | cred); |
| 2497 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2498 | if (status == -NFS4ERR_EXPIRED || |
| 2499 | status == -NFS4ERR_BAD_STATEID) { |
| 2500 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2501 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2502 | if (!recover_lost_locks) |
| 2503 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2504 | } else if (status != NFS_OK) { |
| 2505 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2506 | nfs4_put_lock_state(prev); |
| 2507 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2508 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2509 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2510 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2511 | } |
| 2512 | spin_unlock(&state->state_lock); |
| 2513 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2514 | out: |
| 2515 | return ret; |
| 2516 | } |
| 2517 | |
| 2518 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2519 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2520 | * |
| 2521 | * @state: NFSv4 state for an inode |
| 2522 | * |
| 2523 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2524 | * Otherwise a negative NFS4ERR value is returned. |
| 2525 | */ |
| 2526 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2527 | { |
| 2528 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2529 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2530 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2531 | int status; |
| 2532 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2533 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2534 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2535 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2536 | return NFS_OK; |
| 2537 | return -NFS4ERR_OPENMODE; |
| 2538 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2539 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2540 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2541 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2542 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2543 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2544 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2545 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2546 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2547 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2548 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2549 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2550 | if (status != NFS_OK) |
| 2551 | return status; |
| 2552 | if (nfs_open_stateid_recover_openmode(state)) |
| 2553 | return -NFS4ERR_OPENMODE; |
| 2554 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2558 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2559 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2560 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2561 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2562 | status = nfs41_check_expired_locks(state); |
| 2563 | if (status != NFS_OK) |
| 2564 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2565 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2566 | if (status != NFS_OK) |
| 2567 | status = nfs4_open_expired(sp, state); |
| 2568 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2569 | } |
| 2570 | #endif |
| 2571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2573 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2574 | * fields corresponding to attributes that were used to store the verifier. |
| 2575 | * Make sure we clobber those fields in the later setattr call |
| 2576 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2577 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2578 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2579 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2580 | const u32 *attrset = opendata->o_res.attrset; |
| 2581 | |
| 2582 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2583 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2584 | sattr->ia_valid |= ATTR_ATIME; |
| 2585 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2586 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2587 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2588 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2589 | |
| 2590 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2591 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
Benjamin Coddington | 501e7a4 | 2017-06-02 11:21:34 -0400 | [diff] [blame] | 2592 | (attrset[1] & FATTR4_WORD1_MODE || |
| 2593 | attrset[2] & FATTR4_WORD2_MODE_UMASK)) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2594 | sattr->ia_valid &= ~ATTR_MODE; |
| 2595 | |
| 2596 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2597 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2600 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2601 | fmode_t fmode, |
| 2602 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2603 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2604 | { |
| 2605 | struct nfs4_state_owner *sp = opendata->owner; |
| 2606 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2607 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2608 | struct nfs4_state *state; |
| 2609 | unsigned int seq; |
| 2610 | int ret; |
| 2611 | |
| 2612 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2613 | |
| 2614 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2615 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2616 | goto out; |
| 2617 | |
| 2618 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2619 | ret = PTR_ERR(state); |
| 2620 | if (IS_ERR(state)) |
| 2621 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2622 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2623 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2624 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2625 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2626 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2627 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2628 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2629 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2630 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2631 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2632 | alias = d_exact_alias(dentry, state->inode); |
| 2633 | if (!alias) |
| 2634 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2635 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2636 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2637 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2638 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2639 | } |
| 2640 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2641 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2644 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2645 | if (ret != 0) |
| 2646 | goto out; |
| 2647 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2648 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2649 | nfs_inode_attach_open_context(ctx); |
| 2650 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2651 | nfs4_schedule_stateid_recovery(server, state); |
| 2652 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2653 | out: |
| 2654 | return ret; |
| 2655 | } |
| 2656 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2657 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2658 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2660 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2661 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2662 | int flags, |
| 2663 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2664 | struct nfs4_label *label, |
| 2665 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | { |
| 2667 | struct nfs4_state_owner *sp; |
| 2668 | struct nfs4_state *state = NULL; |
| 2669 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2670 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2671 | struct dentry *dentry = ctx->dentry; |
| 2672 | struct rpc_cred *cred = ctx->cred; |
| 2673 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2674 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2675 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2676 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2677 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | |
| 2679 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2681 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2682 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2684 | goto out_err; |
| 2685 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2686 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2687 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2688 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2689 | if (d_really_is_positive(dentry)) |
| 2690 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2691 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2692 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2693 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2694 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2695 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2696 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2697 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2699 | if (label) { |
| 2700 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2701 | if (IS_ERR(olabel)) { |
| 2702 | status = PTR_ERR(olabel); |
| 2703 | goto err_opendata_put; |
| 2704 | } |
| 2705 | } |
| 2706 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2707 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2708 | if (!opendata->f_attr.mdsthreshold) { |
| 2709 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2710 | if (!opendata->f_attr.mdsthreshold) |
| 2711 | goto err_free_label; |
| 2712 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2713 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2714 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2715 | if (d_really_is_positive(dentry)) |
| 2716 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2717 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2718 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2719 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2720 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2721 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2722 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2723 | 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] | 2724 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2725 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2726 | /* |
| 2727 | * send create attributes which was not set by open |
| 2728 | * with an extra setattr. |
| 2729 | */ |
| 2730 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2731 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2732 | status = nfs4_do_setattr(state->inode, cred, |
| 2733 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2734 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2735 | if (status == 0) { |
| 2736 | nfs_setattr_update_inode(state->inode, sattr, |
| 2737 | opendata->o_res.f_attr); |
| 2738 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2739 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2740 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2741 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2742 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2743 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2744 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2745 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2746 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2747 | opendata->f_attr.mdsthreshold = NULL; |
| 2748 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2749 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2750 | nfs4_label_free(olabel); |
| 2751 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2752 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2755 | err_free_label: |
| 2756 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2757 | err_opendata_put: |
| 2758 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2759 | err_put_state_owner: |
| 2760 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | return status; |
| 2763 | } |
| 2764 | |
| 2765 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2766 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2767 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2768 | int flags, |
| 2769 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2770 | struct nfs4_label *label, |
| 2771 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2773 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | struct nfs4_exception exception = { }; |
| 2775 | struct nfs4_state *res; |
| 2776 | int status; |
| 2777 | |
| 2778 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2779 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2780 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2781 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | if (status == 0) |
| 2783 | break; |
| 2784 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2785 | * book-keeping w.r.t. state-changing operations |
| 2786 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2787 | * It is actually a sign of a bug on the client or on the server. |
| 2788 | * |
| 2789 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2790 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | * have unhashed the old state_owner for us, and that we can |
| 2792 | * therefore safely retry using a new one. We should still warn |
| 2793 | * the user though... |
| 2794 | */ |
| 2795 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2796 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2797 | " returned a bad sequence-id error!\n", |
| 2798 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | exception.retry = 1; |
| 2800 | continue; |
| 2801 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2802 | /* |
| 2803 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2804 | * state before it received the OPEN_CONFIRM. |
| 2805 | * Recover by retrying the request as per the discussion |
| 2806 | * on Page 181 of RFC3530. |
| 2807 | */ |
| 2808 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2809 | exception.retry = 1; |
| 2810 | continue; |
| 2811 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2812 | if (status == -EAGAIN) { |
| 2813 | /* We must have found a delegation */ |
| 2814 | exception.retry = 1; |
| 2815 | continue; |
| 2816 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2817 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2818 | continue; |
| 2819 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | status, &exception)); |
| 2821 | } while (exception.retry); |
| 2822 | return res; |
| 2823 | } |
| 2824 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2825 | static int _nfs4_do_setattr(struct inode *inode, |
| 2826 | struct nfs_setattrargs *arg, |
| 2827 | struct nfs_setattrres *res, |
| 2828 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2829 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2830 | { |
| 2831 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2832 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2834 | .rpc_argp = arg, |
| 2835 | .rpc_resp = res, |
| 2836 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2837 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2838 | struct rpc_cred *delegation_cred = NULL; |
| 2839 | unsigned long timestamp = jiffies; |
| 2840 | fmode_t fmode; |
| 2841 | bool truncate; |
| 2842 | int status; |
| 2843 | |
| 2844 | nfs_fattr_init(res->fattr); |
| 2845 | |
| 2846 | /* Servers should only apply open mode checks for file size changes */ |
| 2847 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2848 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2849 | |
| 2850 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2851 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2852 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2853 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2854 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2855 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2856 | l_ctx = nfs_get_lock_context(ctx); |
| 2857 | if (IS_ERR(l_ctx)) |
| 2858 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2859 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2860 | &arg->stateid, &delegation_cred); |
| 2861 | nfs_put_lock_context(l_ctx); |
| 2862 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2863 | return -EBADF; |
| 2864 | } else |
| 2865 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2866 | if (delegation_cred) |
| 2867 | msg.rpc_cred = delegation_cred; |
| 2868 | |
| 2869 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2870 | |
| 2871 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2872 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2873 | renew_lease(server, timestamp); |
| 2874 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2875 | return status; |
| 2876 | } |
| 2877 | |
| 2878 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2879 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2880 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2881 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2883 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2884 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2885 | struct nfs_setattrargs arg = { |
| 2886 | .fh = NFS_FH(inode), |
| 2887 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | .server = server, |
| 2889 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2890 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2891 | }; |
| 2892 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2894 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2896 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2897 | struct nfs4_exception exception = { |
| 2898 | .state = state, |
| 2899 | .inode = inode, |
| 2900 | .stateid = &arg.stateid, |
| 2901 | }; |
| 2902 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2904 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2905 | if (ilabel) |
| 2906 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2909 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2910 | switch (err) { |
| 2911 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2912 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2913 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2914 | "applying open mode checks to " |
| 2915 | "a SETATTR that is not " |
| 2916 | "changing file size.\n", |
| 2917 | server->nfs_client->cl_hostname); |
| 2918 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2919 | if (state && !(state->state & FMODE_WRITE)) { |
| 2920 | err = -EBADF; |
| 2921 | if (sattr->ia_valid & ATTR_OPEN) |
| 2922 | err = -EACCES; |
| 2923 | goto out; |
| 2924 | } |
| 2925 | } |
| 2926 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2928 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | return err; |
| 2930 | } |
| 2931 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2932 | static bool |
| 2933 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2934 | { |
| 2935 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2936 | return false; |
| 2937 | |
| 2938 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2939 | } |
| 2940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | struct nfs4_closedata { |
| 2942 | struct inode *inode; |
| 2943 | struct nfs4_state *state; |
| 2944 | struct nfs_closeargs arg; |
| 2945 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2946 | struct { |
| 2947 | struct nfs4_layoutreturn_args arg; |
| 2948 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 2949 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2950 | u32 roc_barrier; |
| 2951 | bool roc; |
| 2952 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2953 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2954 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | }; |
| 2956 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2957 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2958 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2959 | struct nfs4_closedata *calldata = data; |
| 2960 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2961 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2962 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2963 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 2964 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 2965 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2966 | nfs4_put_open_state(calldata->state); |
| 2967 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2968 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2969 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2970 | kfree(calldata); |
| 2971 | } |
| 2972 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2973 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2975 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2978 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2980 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2981 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2982 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2983 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2984 | |
| 2985 | /* Handle Layoutreturn errors */ |
| 2986 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 2987 | switch (calldata->res.lr_ret) { |
| 2988 | default: |
| 2989 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 2990 | break; |
| 2991 | case 0: |
| 2992 | calldata->arg.lr_args = NULL; |
| 2993 | calldata->res.lr_res = NULL; |
| 2994 | break; |
| 2995 | case -NFS4ERR_ADMIN_REVOKED: |
| 2996 | case -NFS4ERR_DELEG_REVOKED: |
| 2997 | case -NFS4ERR_EXPIRED: |
| 2998 | case -NFS4ERR_BAD_STATEID: |
| 2999 | case -NFS4ERR_OLD_STATEID: |
| 3000 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3001 | case -NFS4ERR_WRONG_CRED: |
| 3002 | calldata->arg.lr_args = NULL; |
| 3003 | calldata->res.lr_res = NULL; |
| 3004 | calldata->res.lr_ret = 0; |
| 3005 | rpc_restart_call_prepare(task); |
| 3006 | return; |
| 3007 | } |
| 3008 | } |
| 3009 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3010 | /* 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] | 3011 | * the state_owner. we keep this around to process errors |
| 3012 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | switch (task->tk_status) { |
| 3014 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3015 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3016 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3017 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3018 | case -NFS4ERR_ACCESS: |
| 3019 | if (calldata->arg.bitmask != NULL) { |
| 3020 | calldata->arg.bitmask = NULL; |
| 3021 | calldata->res.fattr = NULL; |
| 3022 | task->tk_status = 0; |
| 3023 | rpc_restart_call_prepare(task); |
| 3024 | goto out_release; |
| 3025 | |
| 3026 | } |
| 3027 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3028 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3030 | case -NFS4ERR_EXPIRED: |
| 3031 | nfs4_free_revoked_stateid(server, |
| 3032 | &calldata->arg.stateid, |
| 3033 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3034 | case -NFS4ERR_OLD_STATEID: |
| 3035 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3036 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3037 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3038 | rpc_restart_call_prepare(task); |
| 3039 | goto out_release; |
| 3040 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3041 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3042 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3044 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3045 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3046 | goto out_release; |
| 3047 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3049 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3050 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3051 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3052 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3053 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3054 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3057 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3059 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3060 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3061 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3062 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3063 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3064 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3065 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3066 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3067 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3068 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3069 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3070 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3071 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3072 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3073 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3074 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3075 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3076 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3077 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3078 | if (state->n_rdonly == 0) |
| 3079 | call_close |= is_rdonly; |
| 3080 | else if (is_rdonly) |
| 3081 | calldata->arg.fmode |= FMODE_READ; |
| 3082 | if (state->n_wronly == 0) |
| 3083 | call_close |= is_wronly; |
| 3084 | else if (is_wronly) |
| 3085 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3086 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3087 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3088 | } else if (is_rdwr) |
| 3089 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3090 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3091 | if (!nfs4_valid_open_stateid(state) || |
| 3092 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3093 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3094 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3095 | |
| 3096 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3097 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3098 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3099 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3100 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3101 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3102 | nfs_release_seqid(calldata->arg.seqid); |
| 3103 | goto out_wait; |
| 3104 | } |
| 3105 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3106 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3107 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3108 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3109 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3110 | /* Close-to-open cache consistency revalidation */ |
| 3111 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3112 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3113 | else |
| 3114 | calldata->arg.bitmask = NULL; |
| 3115 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3116 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3117 | calldata->arg.share_access = |
| 3118 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3119 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3120 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3121 | if (calldata->res.fattr == NULL) |
| 3122 | calldata->arg.bitmask = NULL; |
| 3123 | else if (calldata->arg.bitmask == NULL) |
| 3124 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3125 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3126 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3127 | &calldata->arg.seq_args, |
| 3128 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3129 | task) != 0) |
| 3130 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3131 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3132 | return; |
| 3133 | out_no_action: |
| 3134 | task->tk_action = NULL; |
| 3135 | out_wait: |
| 3136 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3139 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3140 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3141 | .rpc_call_done = nfs4_close_done, |
| 3142 | .rpc_release = nfs4_free_closedata, |
| 3143 | }; |
| 3144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | /* |
| 3146 | * It is possible for data to be read/written from a mem-mapped file |
| 3147 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3148 | * This means that we can't safely call nfsv4 close on a file until |
| 3149 | * the inode is cleared. This in turn means that we are not good |
| 3150 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3151 | * share state even when we are done with one of the three share |
| 3152 | * stateid's in the inode. |
| 3153 | * |
| 3154 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3155 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3156 | 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] | 3157 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3158 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3159 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3161 | struct nfs4_state_owner *sp = state->owner; |
| 3162 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3163 | struct rpc_message msg = { |
| 3164 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3165 | .rpc_cred = state->owner->so_cred, |
| 3166 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3167 | struct rpc_task_setup task_setup_data = { |
| 3168 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3169 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3170 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3171 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3172 | .flags = RPC_TASK_ASYNC, |
| 3173 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3174 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3176 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3177 | &task_setup_data.rpc_client, &msg); |
| 3178 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3179 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3181 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3182 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3183 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3185 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3187 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3188 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3189 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3190 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3191 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3192 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3193 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3194 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3195 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3196 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3197 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3198 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3199 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3200 | if (calldata->lr.roc) { |
| 3201 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3202 | calldata->res.lr_res = &calldata->lr.res; |
| 3203 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3204 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3205 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3206 | msg.rpc_argp = &calldata->arg; |
| 3207 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3208 | task_setup_data.callback_data = calldata; |
| 3209 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3210 | if (IS_ERR(task)) |
| 3211 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3212 | status = 0; |
| 3213 | if (wait) |
| 3214 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3215 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3216 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3217 | out_free_calldata: |
| 3218 | kfree(calldata); |
| 3219 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3220 | nfs4_put_open_state(state); |
| 3221 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3222 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3225 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3226 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3227 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3230 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3231 | |
| 3232 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3234 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3235 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3236 | |
| 3237 | nfs4_label_release_security(label); |
| 3238 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3239 | if (IS_ERR(state)) |
| 3240 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3241 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3244 | 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] | 3245 | { |
| 3246 | if (ctx->state == NULL) |
| 3247 | return; |
| 3248 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3249 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3250 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3251 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3254 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3255 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3256 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3259 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3260 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3261 | struct nfs4_server_caps_arg args = { |
| 3262 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3263 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3264 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | struct nfs4_server_caps_res res = {}; |
| 3266 | struct rpc_message msg = { |
| 3267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3268 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | .rpc_resp = &res, |
| 3270 | }; |
| 3271 | int status; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3272 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3274 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3275 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3276 | FATTR4_WORD0_LINK_SUPPORT | |
| 3277 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3278 | FATTR4_WORD0_ACLSUPPORT; |
| 3279 | if (minorversion) |
| 3280 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3281 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3282 | 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] | 3283 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3284 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3285 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3286 | case 0: |
| 3287 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3288 | res.attr_bitmask[2] = 0; |
| 3289 | break; |
| 3290 | case 1: |
| 3291 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3292 | break; |
| 3293 | case 2: |
| 3294 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3297 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3298 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3299 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3300 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3301 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3302 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3303 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3304 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | server->caps |= NFS_CAP_ACLS; |
| 3306 | if (res.has_links != 0) |
| 3307 | server->caps |= NFS_CAP_HARDLINKS; |
| 3308 | if (res.has_symlinks != 0) |
| 3309 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3310 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3311 | server->caps |= NFS_CAP_FILEID; |
| 3312 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3313 | server->caps |= NFS_CAP_MODE; |
| 3314 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3315 | server->caps |= NFS_CAP_NLINK; |
| 3316 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3317 | server->caps |= NFS_CAP_OWNER; |
| 3318 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3319 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3320 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3321 | server->caps |= NFS_CAP_ATIME; |
| 3322 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3323 | server->caps |= NFS_CAP_CTIME; |
| 3324 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3325 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3326 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3327 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3328 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3329 | #endif |
| 3330 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3331 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3332 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3333 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3334 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3335 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3336 | 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] | 3337 | server->cache_consistency_bitmask[2] = 0; |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3338 | |
| 3339 | /* Avoid a regression due to buggy server */ |
| 3340 | for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) |
| 3341 | res.exclcreat_bitmask[i] &= res.attr_bitmask[i]; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3342 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3343 | sizeof(server->exclcreat_bitmask)); |
Trond Myklebust | f4b23de | 2017-05-09 15:47:15 -0400 | [diff] [blame] | 3344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3346 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | return status; |
| 3350 | } |
| 3351 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3352 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | { |
| 3354 | struct nfs4_exception exception = { }; |
| 3355 | int err; |
| 3356 | do { |
| 3357 | err = nfs4_handle_exception(server, |
| 3358 | _nfs4_server_capabilities(server, fhandle), |
| 3359 | &exception); |
| 3360 | } while (exception.retry); |
| 3361 | return err; |
| 3362 | } |
| 3363 | |
| 3364 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3365 | struct nfs_fsinfo *info) |
| 3366 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3367 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3369 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | }; |
| 3371 | struct nfs4_lookup_res res = { |
| 3372 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3373 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | .fh = fhandle, |
| 3375 | }; |
| 3376 | struct rpc_message msg = { |
| 3377 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3378 | .rpc_argp = &args, |
| 3379 | .rpc_resp = &res, |
| 3380 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3381 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3382 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3383 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3384 | /* |
| 3385 | * Process the label in the upcoming getfattr |
| 3386 | */ |
| 3387 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3388 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3389 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3390 | 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] | 3391 | } |
| 3392 | |
| 3393 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3394 | struct nfs_fsinfo *info) |
| 3395 | { |
| 3396 | struct nfs4_exception exception = { }; |
| 3397 | int err; |
| 3398 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3399 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3400 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3401 | switch (err) { |
| 3402 | case 0: |
| 3403 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3404 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3405 | default: |
| 3406 | err = nfs4_handle_exception(server, err, &exception); |
| 3407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3409 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | return err; |
| 3411 | } |
| 3412 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3413 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3414 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3415 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3416 | struct rpc_auth_create_args auth_args = { |
| 3417 | .pseudoflavor = flavor, |
| 3418 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3419 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3420 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3421 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3422 | if (IS_ERR(auth)) |
| 3423 | return -EACCES; |
| 3424 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3427 | /* |
| 3428 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3429 | * |
| 3430 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3431 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3432 | * |
| 3433 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3434 | * negative errno value. |
| 3435 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3436 | 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] | 3437 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3439 | /* Per 3530bis 15.33.5 */ |
| 3440 | static const rpc_authflavor_t flav_array[] = { |
| 3441 | RPC_AUTH_GSS_KRB5P, |
| 3442 | RPC_AUTH_GSS_KRB5I, |
| 3443 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3444 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3445 | RPC_AUTH_NULL, |
| 3446 | }; |
| 3447 | int status = -EPERM; |
| 3448 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3450 | if (server->auth_info.flavor_len > 0) { |
| 3451 | /* try each flavor specified by user */ |
| 3452 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3453 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3454 | server->auth_info.flavors[i]); |
| 3455 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3456 | continue; |
| 3457 | break; |
| 3458 | } |
| 3459 | } else { |
| 3460 | /* no flavors specified by user, try default list */ |
| 3461 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3462 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3463 | flav_array[i]); |
| 3464 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3465 | continue; |
| 3466 | break; |
| 3467 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3468 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3469 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3470 | /* |
| 3471 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3472 | * to access the mount. It could also mean that we tried to mount |
| 3473 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3474 | * existing mount programs don't handle -EACCES very well so it should |
| 3475 | * be mapped to -EPERM instead. |
| 3476 | */ |
| 3477 | if (status == -EACCES) |
| 3478 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3479 | return status; |
| 3480 | } |
| 3481 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3482 | /** |
| 3483 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3484 | * @server: initialized nfs_server handle |
| 3485 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3486 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3487 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3488 | * |
| 3489 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3490 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3491 | 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] | 3492 | struct nfs_fsinfo *info, |
| 3493 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3494 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3495 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3496 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3497 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3498 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3499 | |
| 3500 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3501 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3502 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | if (status == 0) |
| 3505 | status = nfs4_server_capabilities(server, fhandle); |
| 3506 | if (status == 0) |
| 3507 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3508 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3509 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3512 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3513 | struct nfs_fsinfo *info) |
| 3514 | { |
| 3515 | int error; |
| 3516 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3517 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3518 | |
| 3519 | error = nfs4_server_capabilities(server, mntfh); |
| 3520 | if (error < 0) { |
| 3521 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3522 | return error; |
| 3523 | } |
| 3524 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3525 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3526 | if (IS_ERR(label)) |
| 3527 | return PTR_ERR(label); |
| 3528 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3529 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3530 | if (error < 0) { |
| 3531 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3532 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3536 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3537 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3538 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3539 | err_free_label: |
| 3540 | nfs4_label_free(label); |
| 3541 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3542 | return error; |
| 3543 | } |
| 3544 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3545 | /* |
| 3546 | * Get locations and (maybe) other attributes of a referral. |
| 3547 | * Note that we'll actually follow the referral later when |
| 3548 | * we detect fsid mismatch in inode revalidation |
| 3549 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3550 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3551 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3552 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3553 | { |
| 3554 | int status = -ENOMEM; |
| 3555 | struct page *page = NULL; |
| 3556 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3557 | |
| 3558 | page = alloc_page(GFP_KERNEL); |
| 3559 | if (page == NULL) |
| 3560 | goto out; |
| 3561 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3562 | if (locations == NULL) |
| 3563 | goto out; |
| 3564 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3565 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3566 | if (status != 0) |
| 3567 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3568 | |
| 3569 | /* |
| 3570 | * If the fsid didn't change, this is a migration event, not a |
| 3571 | * referral. Cause us to drop into the exception handler, which |
| 3572 | * will kick off migration recovery. |
| 3573 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3574 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3575 | dprintk("%s: server did not return a different fsid for" |
| 3576 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3577 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3578 | goto out; |
| 3579 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3580 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3581 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3582 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3583 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3584 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3585 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3586 | out: |
| 3587 | if (page) |
| 3588 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3589 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3590 | return status; |
| 3591 | } |
| 3592 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3593 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3594 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { |
| 3596 | struct nfs4_getattr_arg args = { |
| 3597 | .fh = fhandle, |
| 3598 | .bitmask = server->attr_bitmask, |
| 3599 | }; |
| 3600 | struct nfs4_getattr_res res = { |
| 3601 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3602 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | .server = server, |
| 3604 | }; |
| 3605 | struct rpc_message msg = { |
| 3606 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3607 | .rpc_argp = &args, |
| 3608 | .rpc_resp = &res, |
| 3609 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3610 | |
| 3611 | args.bitmask = nfs4_bitmask(server, label); |
| 3612 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3613 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3614 | 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] | 3615 | } |
| 3616 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3617 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3618 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | { |
| 3620 | struct nfs4_exception exception = { }; |
| 3621 | int err; |
| 3622 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3623 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3624 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3625 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | &exception); |
| 3627 | } while (exception.retry); |
| 3628 | return err; |
| 3629 | } |
| 3630 | |
| 3631 | /* |
| 3632 | * The file is not closed if it is opened due to the a request to change |
| 3633 | * the size of the file. The open call will not be needed once the |
| 3634 | * VFS layer lookup-intents are implemented. |
| 3635 | * |
| 3636 | * Close is called when the inode is destroyed. |
| 3637 | * If we haven't opened the file for O_WRONLY, we |
| 3638 | * need to in the size_change case to obtain a stateid. |
| 3639 | * |
| 3640 | * Got race? |
| 3641 | * Because OPEN is always done by name in nfsv4, it is |
| 3642 | * possible that we opened a different file by the same |
| 3643 | * name. We can recognize this race condition, but we |
| 3644 | * can't do anything about it besides returning an error. |
| 3645 | * |
| 3646 | * This will be fixed with VFS changes (lookup-intent). |
| 3647 | */ |
| 3648 | static int |
| 3649 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3650 | struct iattr *sattr) |
| 3651 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3652 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3653 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3654 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3655 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | int status; |
| 3657 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3658 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3659 | sattr->ia_valid & ATTR_SIZE && |
| 3660 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3661 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3662 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3663 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3665 | /* Deal with open(O_TRUNC) */ |
| 3666 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3667 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3668 | |
| 3669 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3670 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3671 | return 0; |
| 3672 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3673 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3674 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3675 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3676 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3677 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3678 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3679 | } |
| 3680 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3681 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3682 | if (IS_ERR(label)) |
| 3683 | return PTR_ERR(label); |
| 3684 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3685 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3686 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3687 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3688 | nfs_setsecurity(inode, fattr, label); |
| 3689 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3690 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | return status; |
| 3692 | } |
| 3693 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3694 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3695 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3696 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3697 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3698 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3699 | int status; |
| 3700 | struct nfs4_lookup_arg args = { |
| 3701 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3702 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3703 | .name = name, |
| 3704 | }; |
| 3705 | struct nfs4_lookup_res res = { |
| 3706 | .server = server, |
| 3707 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3708 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3709 | .fh = fhandle, |
| 3710 | }; |
| 3711 | struct rpc_message msg = { |
| 3712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3713 | .rpc_argp = &args, |
| 3714 | .rpc_resp = &res, |
| 3715 | }; |
| 3716 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3717 | args.bitmask = nfs4_bitmask(server, label); |
| 3718 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3719 | nfs_fattr_init(fattr); |
| 3720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3722 | 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] | 3723 | dprintk("NFS reply lookup: %d\n", status); |
| 3724 | return status; |
| 3725 | } |
| 3726 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3727 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3728 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3729 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3730 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3731 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3732 | fattr->nlink = 2; |
| 3733 | } |
| 3734 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3735 | 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] | 3736 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3737 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3738 | { |
| 3739 | struct nfs4_exception exception = { }; |
| 3740 | struct rpc_clnt *client = *clnt; |
| 3741 | int err; |
| 3742 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3743 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3744 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3745 | switch (err) { |
| 3746 | case -NFS4ERR_BADNAME: |
| 3747 | err = -ENOENT; |
| 3748 | goto out; |
| 3749 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3750 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3751 | if (err == -NFS4ERR_MOVED) |
| 3752 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3753 | goto out; |
| 3754 | case -NFS4ERR_WRONGSEC: |
| 3755 | err = -EPERM; |
| 3756 | if (client != *clnt) |
| 3757 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3758 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3759 | if (IS_ERR(client)) |
| 3760 | return PTR_ERR(client); |
| 3761 | |
| 3762 | exception.retry = 1; |
| 3763 | break; |
| 3764 | default: |
| 3765 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3766 | } |
| 3767 | } while (exception.retry); |
| 3768 | |
| 3769 | out: |
| 3770 | if (err == 0) |
| 3771 | *clnt = client; |
| 3772 | else if (client != *clnt) |
| 3773 | rpc_shutdown_client(client); |
| 3774 | |
| 3775 | return err; |
| 3776 | } |
| 3777 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3778 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3779 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3780 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3782 | int status; |
| 3783 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3784 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3785 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3786 | if (client != NFS_CLIENT(dir)) { |
| 3787 | rpc_shutdown_client(client); |
| 3788 | nfs_fixup_secinfo_attributes(fattr); |
| 3789 | } |
| 3790 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3793 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3794 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3795 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3796 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3797 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3798 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3799 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3800 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3801 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3802 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3803 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3804 | } |
| 3805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3807 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3808 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | struct nfs4_accessargs args = { |
| 3810 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3811 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3813 | struct nfs4_accessres res = { |
| 3814 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3815 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | struct rpc_message msg = { |
| 3817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3818 | .rpc_argp = &args, |
| 3819 | .rpc_resp = &res, |
| 3820 | .rpc_cred = entry->cred, |
| 3821 | }; |
| 3822 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3823 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
| 3825 | /* |
| 3826 | * Determine which access bits we want to ask for... |
| 3827 | */ |
| 3828 | if (mode & MAY_READ) |
| 3829 | args.access |= NFS4_ACCESS_READ; |
| 3830 | if (S_ISDIR(inode->i_mode)) { |
| 3831 | if (mode & MAY_WRITE) |
| 3832 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3833 | if (mode & MAY_EXEC) |
| 3834 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3835 | } else { |
| 3836 | if (mode & MAY_WRITE) |
| 3837 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3838 | if (mode & MAY_EXEC) |
| 3839 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3840 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3841 | |
| 3842 | res.fattr = nfs_alloc_fattr(); |
| 3843 | if (res.fattr == NULL) |
| 3844 | return -ENOMEM; |
| 3845 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3846 | 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] | 3847 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3848 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3849 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3851 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | return status; |
| 3853 | } |
| 3854 | |
| 3855 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3856 | { |
| 3857 | struct nfs4_exception exception = { }; |
| 3858 | int err; |
| 3859 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3860 | err = _nfs4_proc_access(inode, entry); |
| 3861 | trace_nfs4_access(inode, err); |
| 3862 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | &exception); |
| 3864 | } while (exception.retry); |
| 3865 | return err; |
| 3866 | } |
| 3867 | |
| 3868 | /* |
| 3869 | * TODO: For the time being, we don't try to get any attributes |
| 3870 | * along with any of the zero-copy operations READ, READDIR, |
| 3871 | * READLINK, WRITE. |
| 3872 | * |
| 3873 | * In the case of the first three, we want to put the GETATTR |
| 3874 | * after the read-type operation -- this is because it is hard |
| 3875 | * to predict the length of a GETATTR response in v4, and thus |
| 3876 | * align the READ data correctly. This means that the GETATTR |
| 3877 | * may end up partially falling into the page cache, and we should |
| 3878 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3879 | * To do this efficiently, we need to know the total length |
| 3880 | * of data received, which doesn't seem to be available outside |
| 3881 | * of the RPC layer. |
| 3882 | * |
| 3883 | * In the case of WRITE, we also want to put the GETATTR after |
| 3884 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3885 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | * |
| 3887 | * Both of these changes to the XDR layer would in fact be quite |
| 3888 | * minor, but I decided to leave them for a subsequent patch. |
| 3889 | */ |
| 3890 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3891 | unsigned int pgbase, unsigned int pglen) |
| 3892 | { |
| 3893 | struct nfs4_readlink args = { |
| 3894 | .fh = NFS_FH(inode), |
| 3895 | .pgbase = pgbase, |
| 3896 | .pglen = pglen, |
| 3897 | .pages = &page, |
| 3898 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3899 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | struct rpc_message msg = { |
| 3901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3902 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3903 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | }; |
| 3905 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3906 | 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] | 3907 | } |
| 3908 | |
| 3909 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3910 | unsigned int pgbase, unsigned int pglen) |
| 3911 | { |
| 3912 | struct nfs4_exception exception = { }; |
| 3913 | int err; |
| 3914 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3915 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3916 | trace_nfs4_readlink(inode, err); |
| 3917 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | &exception); |
| 3919 | } while (exception.retry); |
| 3920 | return err; |
| 3921 | } |
| 3922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3924 | * 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] | 3925 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | static int |
| 3927 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3928 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3930 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3931 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3932 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | int status = 0; |
| 3935 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3936 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3937 | if (IS_ERR(ctx)) |
| 3938 | return PTR_ERR(ctx); |
| 3939 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3940 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3941 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3942 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 3943 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3944 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | if (IS_ERR(state)) { |
| 3946 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3947 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3950 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3951 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | return status; |
| 3953 | } |
| 3954 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3955 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3957 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3958 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3960 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3962 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3963 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3964 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3966 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3967 | .rpc_argp = &args, |
| 3968 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 3970 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3971 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3972 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3973 | 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] | 3974 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 3975 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | return status; |
| 3977 | } |
| 3978 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3979 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | { |
| 3981 | struct nfs4_exception exception = { }; |
| 3982 | int err; |
| 3983 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3984 | err = _nfs4_proc_remove(dir, name); |
| 3985 | trace_nfs4_remove(dir, name, err); |
| 3986 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | &exception); |
| 3988 | } while (exception.retry); |
| 3989 | return err; |
| 3990 | } |
| 3991 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3992 | 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] | 3993 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3994 | struct nfs_server *server = NFS_SERVER(dir); |
| 3995 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3996 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3998 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4000 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4001 | |
| 4002 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4005 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4006 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4007 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4008 | &data->args.seq_args, |
| 4009 | &data->res.seq_res, |
| 4010 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4013 | 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] | 4014 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4015 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4016 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4017 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4018 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4019 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4020 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4021 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4022 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4023 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4024 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4025 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4028 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4029 | { |
| 4030 | struct nfs_server *server = NFS_SERVER(dir); |
| 4031 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4032 | struct nfs_renameres *res = msg->rpc_resp; |
| 4033 | |
| 4034 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4035 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4036 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4037 | } |
| 4038 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4039 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4040 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4041 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4042 | &data->args.seq_args, |
| 4043 | &data->res.seq_res, |
| 4044 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4048 | struct inode *new_dir) |
| 4049 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4050 | struct nfs_renamedata *data = task->tk_calldata; |
| 4051 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4052 | |
| 4053 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4054 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4055 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4056 | return 0; |
| 4057 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4058 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4059 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4060 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4061 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4062 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4063 | return 1; |
| 4064 | } |
| 4065 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4066 | 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] | 4067 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4068 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | struct nfs4_link_arg arg = { |
| 4070 | .fh = NFS_FH(inode), |
| 4071 | .dir_fh = NFS_FH(dir), |
| 4072 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4073 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4075 | struct nfs4_link_res res = { |
| 4076 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4077 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4078 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | struct rpc_message msg = { |
| 4080 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4081 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4082 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4084 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4086 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4087 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4088 | goto out; |
| 4089 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4090 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4091 | if (IS_ERR(res.label)) { |
| 4092 | status = PTR_ERR(res.label); |
| 4093 | goto out; |
| 4094 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4095 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4096 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4097 | 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] | 4098 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4099 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4100 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4101 | if (!status) |
| 4102 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4103 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4104 | |
| 4105 | |
| 4106 | nfs4_label_free(res.label); |
| 4107 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4108 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4109 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | return status; |
| 4111 | } |
| 4112 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4113 | 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] | 4114 | { |
| 4115 | struct nfs4_exception exception = { }; |
| 4116 | int err; |
| 4117 | do { |
| 4118 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4119 | _nfs4_proc_link(inode, dir, name), |
| 4120 | &exception); |
| 4121 | } while (exception.retry); |
| 4122 | return err; |
| 4123 | } |
| 4124 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4125 | struct nfs4_createdata { |
| 4126 | struct rpc_message msg; |
| 4127 | struct nfs4_create_arg arg; |
| 4128 | struct nfs4_create_res res; |
| 4129 | struct nfs_fh fh; |
| 4130 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4131 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4132 | }; |
| 4133 | |
| 4134 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4135 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4136 | { |
| 4137 | struct nfs4_createdata *data; |
| 4138 | |
| 4139 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4140 | if (data != NULL) { |
| 4141 | struct nfs_server *server = NFS_SERVER(dir); |
| 4142 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4143 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4144 | if (IS_ERR(data->label)) |
| 4145 | goto out_free; |
| 4146 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4147 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4148 | data->msg.rpc_argp = &data->arg; |
| 4149 | data->msg.rpc_resp = &data->res; |
| 4150 | data->arg.dir_fh = NFS_FH(dir); |
| 4151 | data->arg.server = server; |
| 4152 | data->arg.name = name; |
| 4153 | data->arg.attrs = sattr; |
| 4154 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4155 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4156 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4157 | data->res.server = server; |
| 4158 | data->res.fh = &data->fh; |
| 4159 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4160 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4161 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4162 | } |
| 4163 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4164 | out_free: |
| 4165 | kfree(data); |
| 4166 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4170 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4171 | 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] | 4172 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4173 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4174 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4175 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4176 | 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] | 4177 | } |
| 4178 | return status; |
| 4179 | } |
| 4180 | |
| 4181 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4182 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4183 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4184 | kfree(data); |
| 4185 | } |
| 4186 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4187 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4188 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4189 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4191 | struct nfs4_createdata *data; |
| 4192 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4194 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4195 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4196 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4197 | status = -ENOMEM; |
| 4198 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4199 | if (data == NULL) |
| 4200 | goto out; |
| 4201 | |
| 4202 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4203 | data->arg.u.symlink.pages = &page; |
| 4204 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4205 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4207 | status = nfs4_do_create(dir, dentry, data); |
| 4208 | |
| 4209 | nfs4_free_createdata(data); |
| 4210 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | return status; |
| 4212 | } |
| 4213 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4214 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4215 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | { |
| 4217 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4218 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4220 | |
| 4221 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4224 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4225 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4226 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | &exception); |
| 4228 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4229 | |
| 4230 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | return err; |
| 4232 | } |
| 4233 | |
| 4234 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4235 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4237 | struct nfs4_createdata *data; |
| 4238 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4240 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4241 | if (data == NULL) |
| 4242 | goto out; |
| 4243 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4244 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4245 | status = nfs4_do_create(dir, dentry, data); |
| 4246 | |
| 4247 | nfs4_free_createdata(data); |
| 4248 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | return status; |
| 4250 | } |
| 4251 | |
| 4252 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4253 | struct iattr *sattr) |
| 4254 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4255 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4257 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4259 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4260 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4261 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4262 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4263 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4265 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4266 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4267 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | &exception); |
| 4269 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4270 | nfs4_label_release_security(label); |
| 4271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | return err; |
| 4273 | } |
| 4274 | |
| 4275 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4276 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4278 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | struct nfs4_readdir_arg args = { |
| 4280 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4281 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | .pgbase = 0, |
| 4283 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4284 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4285 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | }; |
| 4287 | struct nfs4_readdir_res res; |
| 4288 | struct rpc_message msg = { |
| 4289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4290 | .rpc_argp = &args, |
| 4291 | .rpc_resp = &res, |
| 4292 | .rpc_cred = cred, |
| 4293 | }; |
| 4294 | int status; |
| 4295 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4296 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4297 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4298 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4299 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4301 | 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] | 4302 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4303 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4304 | status += args.pgbase; |
| 4305 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4306 | |
| 4307 | nfs_invalidate_atime(dir); |
| 4308 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4309 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | return status; |
| 4311 | } |
| 4312 | |
| 4313 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4314 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | { |
| 4316 | struct nfs4_exception exception = { }; |
| 4317 | int err; |
| 4318 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4319 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4320 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4321 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4322 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | &exception); |
| 4324 | } while (exception.retry); |
| 4325 | return err; |
| 4326 | } |
| 4327 | |
| 4328 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4329 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4331 | struct nfs4_createdata *data; |
| 4332 | int mode = sattr->ia_mode; |
| 4333 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4335 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4336 | if (data == NULL) |
| 4337 | goto out; |
| 4338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4340 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4342 | data->arg.ftype = NF4BLK; |
| 4343 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4344 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | } |
| 4346 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4347 | data->arg.ftype = NF4CHR; |
| 4348 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4349 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4350 | } else if (!S_ISSOCK(mode)) { |
| 4351 | status = -EINVAL; |
| 4352 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4354 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4355 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4356 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4357 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4358 | nfs4_free_createdata(data); |
| 4359 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | return status; |
| 4361 | } |
| 4362 | |
| 4363 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4364 | struct iattr *sattr, dev_t rdev) |
| 4365 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4366 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4368 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4370 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4371 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4372 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4373 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4374 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4376 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4377 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4378 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | &exception); |
| 4380 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4381 | |
| 4382 | nfs4_label_release_security(label); |
| 4383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | return err; |
| 4385 | } |
| 4386 | |
| 4387 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4388 | struct nfs_fsstat *fsstat) |
| 4389 | { |
| 4390 | struct nfs4_statfs_arg args = { |
| 4391 | .fh = fhandle, |
| 4392 | .bitmask = server->attr_bitmask, |
| 4393 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4394 | struct nfs4_statfs_res res = { |
| 4395 | .fsstat = fsstat, |
| 4396 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | struct rpc_message msg = { |
| 4398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4399 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4400 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | }; |
| 4402 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4403 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4404 | 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] | 4405 | } |
| 4406 | |
| 4407 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4408 | { |
| 4409 | struct nfs4_exception exception = { }; |
| 4410 | int err; |
| 4411 | do { |
| 4412 | err = nfs4_handle_exception(server, |
| 4413 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4414 | &exception); |
| 4415 | } while (exception.retry); |
| 4416 | return err; |
| 4417 | } |
| 4418 | |
| 4419 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4420 | struct nfs_fsinfo *fsinfo) |
| 4421 | { |
| 4422 | struct nfs4_fsinfo_arg args = { |
| 4423 | .fh = fhandle, |
| 4424 | .bitmask = server->attr_bitmask, |
| 4425 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4426 | struct nfs4_fsinfo_res res = { |
| 4427 | .fsinfo = fsinfo, |
| 4428 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | struct rpc_message msg = { |
| 4430 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4431 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4432 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | }; |
| 4434 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4435 | 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] | 4436 | } |
| 4437 | |
| 4438 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4439 | { |
| 4440 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4441 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | int err; |
| 4443 | |
| 4444 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4445 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4446 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4447 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4448 | nfs4_set_lease_period(server->nfs_client, |
| 4449 | fsinfo->lease_time * HZ, |
| 4450 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4451 | break; |
| 4452 | } |
| 4453 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | } while (exception.retry); |
| 4455 | return err; |
| 4456 | } |
| 4457 | |
| 4458 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4459 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4460 | int error; |
| 4461 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4462 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4463 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4464 | if (error == 0) { |
| 4465 | /* block layout checks this! */ |
| 4466 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4467 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4468 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4469 | |
| 4470 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4474 | struct nfs_pathconf *pathconf) |
| 4475 | { |
| 4476 | struct nfs4_pathconf_arg args = { |
| 4477 | .fh = fhandle, |
| 4478 | .bitmask = server->attr_bitmask, |
| 4479 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4480 | struct nfs4_pathconf_res res = { |
| 4481 | .pathconf = pathconf, |
| 4482 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | struct rpc_message msg = { |
| 4484 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4485 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4486 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | }; |
| 4488 | |
| 4489 | /* None of the pathconf attributes are mandatory to implement */ |
| 4490 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4491 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4492 | return 0; |
| 4493 | } |
| 4494 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4495 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4496 | 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] | 4497 | } |
| 4498 | |
| 4499 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4500 | struct nfs_pathconf *pathconf) |
| 4501 | { |
| 4502 | struct nfs4_exception exception = { }; |
| 4503 | int err; |
| 4504 | |
| 4505 | do { |
| 4506 | err = nfs4_handle_exception(server, |
| 4507 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4508 | &exception); |
| 4509 | } while (exception.retry); |
| 4510 | return err; |
| 4511 | } |
| 4512 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4513 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4514 | const struct nfs_open_context *ctx, |
| 4515 | const struct nfs_lock_context *l_ctx, |
| 4516 | fmode_t fmode) |
| 4517 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4518 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4519 | } |
| 4520 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4521 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4522 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4523 | const struct nfs_open_context *ctx, |
| 4524 | const struct nfs_lock_context *l_ctx, |
| 4525 | fmode_t fmode) |
| 4526 | { |
| 4527 | nfs4_stateid current_stateid; |
| 4528 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4529 | /* If the current stateid represents a lost lock, then exit */ |
| 4530 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4531 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4532 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4533 | } |
| 4534 | |
| 4535 | static bool nfs4_error_stateid_expired(int err) |
| 4536 | { |
| 4537 | switch (err) { |
| 4538 | case -NFS4ERR_DELEG_REVOKED: |
| 4539 | case -NFS4ERR_ADMIN_REVOKED: |
| 4540 | case -NFS4ERR_BAD_STATEID: |
| 4541 | case -NFS4ERR_STALE_STATEID: |
| 4542 | case -NFS4ERR_OLD_STATEID: |
| 4543 | case -NFS4ERR_OPENMODE: |
| 4544 | case -NFS4ERR_EXPIRED: |
| 4545 | return true; |
| 4546 | } |
| 4547 | return false; |
| 4548 | } |
| 4549 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4550 | 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] | 4551 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4552 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4554 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4555 | if (task->tk_status < 0) { |
| 4556 | struct nfs4_exception exception = { |
| 4557 | .inode = hdr->inode, |
| 4558 | .state = hdr->args.context->state, |
| 4559 | .stateid = &hdr->args.stateid, |
| 4560 | }; |
| 4561 | task->tk_status = nfs4_async_handle_exception(task, |
| 4562 | server, task->tk_status, &exception); |
| 4563 | if (exception.retry) { |
| 4564 | rpc_restart_call_prepare(task); |
| 4565 | return -EAGAIN; |
| 4566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4570 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4571 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | } |
| 4573 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4574 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4575 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4576 | { |
| 4577 | |
| 4578 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4579 | nfs4_stateid_is_current(&args->stateid, |
| 4580 | args->context, |
| 4581 | args->lock_context, |
| 4582 | FMODE_READ)) |
| 4583 | return false; |
| 4584 | rpc_restart_call_prepare(task); |
| 4585 | return true; |
| 4586 | } |
| 4587 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4588 | 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] | 4589 | { |
| 4590 | |
| 4591 | dprintk("--> %s\n", __func__); |
| 4592 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4593 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4594 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4595 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4596 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4597 | if (task->tk_status > 0) |
| 4598 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4599 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4600 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4603 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4604 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4606 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4607 | if (!hdr->pgio_done_cb) |
| 4608 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4609 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4610 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4613 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4614 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4615 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4616 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4617 | &hdr->args.seq_args, |
| 4618 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4619 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4620 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4621 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4622 | hdr->args.lock_context, |
Benjamin Coddington | fbe77c3 | 2017-04-19 10:11:35 -0400 | [diff] [blame] | 4623 | hdr->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4624 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4625 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4626 | return -EIO; |
| 4627 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4630 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4631 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4633 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4634 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4635 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4636 | if (task->tk_status < 0) { |
| 4637 | struct nfs4_exception exception = { |
| 4638 | .inode = hdr->inode, |
| 4639 | .state = hdr->args.context->state, |
| 4640 | .stateid = &hdr->args.stateid, |
| 4641 | }; |
| 4642 | task->tk_status = nfs4_async_handle_exception(task, |
| 4643 | NFS_SERVER(inode), task->tk_status, |
| 4644 | &exception); |
| 4645 | if (exception.retry) { |
| 4646 | rpc_restart_call_prepare(task); |
| 4647 | return -EAGAIN; |
| 4648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4650 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4651 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4652 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4653 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4654 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4657 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4658 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4659 | { |
| 4660 | |
| 4661 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4662 | nfs4_stateid_is_current(&args->stateid, |
| 4663 | args->context, |
| 4664 | args->lock_context, |
| 4665 | FMODE_WRITE)) |
| 4666 | return false; |
| 4667 | rpc_restart_call_prepare(task); |
| 4668 | return true; |
| 4669 | } |
| 4670 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | 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] | 4672 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4673 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4674 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4676 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4677 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4678 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4681 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4682 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4683 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4684 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4685 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4686 | return false; |
| 4687 | /* Otherwise, request attributes if and only if we don't hold |
| 4688 | * a delegation |
| 4689 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4690 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4691 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4692 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4693 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4694 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4696 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4697 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4698 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4699 | hdr->args.bitmask = NULL; |
| 4700 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4701 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4703 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4704 | if (!hdr->pgio_done_cb) |
| 4705 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4706 | hdr->res.server = server; |
| 4707 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4709 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4713 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4714 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4715 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4716 | &data->args.seq_args, |
| 4717 | &data->res.seq_res, |
| 4718 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4721 | 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] | 4722 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4724 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4725 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4726 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4727 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4728 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4729 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4731 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4734 | 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] | 4735 | { |
| 4736 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4737 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4738 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4741 | 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] | 4742 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4743 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4744 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4745 | if (data->commit_done_cb == NULL) |
| 4746 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4747 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4748 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4749 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4752 | struct nfs4_renewdata { |
| 4753 | struct nfs_client *client; |
| 4754 | unsigned long timestamp; |
| 4755 | }; |
| 4756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | /* |
| 4758 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4759 | * standalone procedure for queueing an asynchronous RENEW. |
| 4760 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4761 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4762 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4763 | struct nfs4_renewdata *data = calldata; |
| 4764 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4765 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4766 | if (atomic_read(&clp->cl_count) > 1) |
| 4767 | nfs4_schedule_state_renewal(clp); |
| 4768 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4769 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4772 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4774 | struct nfs4_renewdata *data = calldata; |
| 4775 | struct nfs_client *clp = data->client; |
| 4776 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4778 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4779 | switch (task->tk_status) { |
| 4780 | case 0: |
| 4781 | break; |
| 4782 | case -NFS4ERR_LEASE_MOVED: |
| 4783 | nfs4_schedule_lease_moved_recovery(clp); |
| 4784 | break; |
| 4785 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4786 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4787 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4788 | return; |
| 4789 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4790 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4791 | return; |
| 4792 | } |
| 4793 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4795 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4798 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4799 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4800 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4801 | }; |
| 4802 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4803 | 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] | 4804 | { |
| 4805 | struct rpc_message msg = { |
| 4806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4807 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4808 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4810 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4812 | if (renew_flags == 0) |
| 4813 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4814 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4815 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4816 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4817 | if (data == NULL) { |
| 4818 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4819 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 4820 | } |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4821 | data->client = clp; |
| 4822 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4823 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4824 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4827 | 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] | 4828 | { |
| 4829 | struct rpc_message msg = { |
| 4830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4831 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4832 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | }; |
| 4834 | unsigned long now = jiffies; |
| 4835 | int status; |
| 4836 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4837 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | if (status < 0) |
| 4839 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4840 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | return 0; |
| 4842 | } |
| 4843 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4844 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4845 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4846 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4849 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4850 | * 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] | 4851 | * the stack. |
| 4852 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4853 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4854 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4855 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4856 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4857 | { |
| 4858 | struct page *newpage, **spages; |
| 4859 | int rc = 0; |
| 4860 | size_t len; |
| 4861 | spages = pages; |
| 4862 | |
| 4863 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4864 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4865 | newpage = alloc_page(GFP_KERNEL); |
| 4866 | |
| 4867 | if (newpage == NULL) |
| 4868 | goto unwind; |
| 4869 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 4870 | buf += len; |
| 4871 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4872 | *pages++ = newpage; |
| 4873 | rc++; |
| 4874 | } while (buflen != 0); |
| 4875 | |
| 4876 | return rc; |
| 4877 | |
| 4878 | unwind: |
| 4879 | for(; rc > 0; rc--) |
| 4880 | __free_page(spages[rc-1]); |
| 4881 | return -ENOMEM; |
| 4882 | } |
| 4883 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4884 | struct nfs4_cached_acl { |
| 4885 | int cached; |
| 4886 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4887 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4888 | }; |
| 4889 | |
| 4890 | 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] | 4891 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4892 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4893 | |
| 4894 | spin_lock(&inode->i_lock); |
| 4895 | kfree(nfsi->nfs4_acl); |
| 4896 | nfsi->nfs4_acl = acl; |
| 4897 | spin_unlock(&inode->i_lock); |
| 4898 | } |
| 4899 | |
| 4900 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4901 | { |
| 4902 | nfs4_set_cached_acl(inode, NULL); |
| 4903 | } |
| 4904 | |
| 4905 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4906 | { |
| 4907 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4908 | struct nfs4_cached_acl *acl; |
| 4909 | int ret = -ENOENT; |
| 4910 | |
| 4911 | spin_lock(&inode->i_lock); |
| 4912 | acl = nfsi->nfs4_acl; |
| 4913 | if (acl == NULL) |
| 4914 | goto out; |
| 4915 | if (buf == NULL) /* user is just asking for length */ |
| 4916 | goto out_len; |
| 4917 | if (acl->cached == 0) |
| 4918 | goto out; |
| 4919 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4920 | if (acl->len > buflen) |
| 4921 | goto out; |
| 4922 | memcpy(buf, acl->data, acl->len); |
| 4923 | out_len: |
| 4924 | ret = acl->len; |
| 4925 | out: |
| 4926 | spin_unlock(&inode->i_lock); |
| 4927 | return ret; |
| 4928 | } |
| 4929 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4930 | 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] | 4931 | { |
| 4932 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4933 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4934 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4935 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4936 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4937 | if (acl == NULL) |
| 4938 | goto out; |
| 4939 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4940 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4941 | } else { |
| 4942 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4943 | if (acl == NULL) |
| 4944 | goto out; |
| 4945 | acl->cached = 0; |
| 4946 | } |
| 4947 | acl->len = acl_len; |
| 4948 | out: |
| 4949 | nfs4_set_cached_acl(inode, acl); |
| 4950 | } |
| 4951 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4952 | /* |
| 4953 | * The getxattr API returns the required buffer length when called with a |
| 4954 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4955 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4956 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4957 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4958 | * the cache. If not so, we throw away the page, and cache the required |
| 4959 | * length. The next getxattr call will then produce another round trip to |
| 4960 | * the server, this time with the input buf of the required size. |
| 4961 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4962 | 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] | 4963 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 4964 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4965 | struct nfs_getaclargs args = { |
| 4966 | .fh = NFS_FH(inode), |
| 4967 | .acl_pages = pages, |
| 4968 | .acl_len = buflen, |
| 4969 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4970 | struct nfs_getaclres res = { |
| 4971 | .acl_len = buflen, |
| 4972 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4973 | struct rpc_message msg = { |
| 4974 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4975 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4976 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4977 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 4978 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4979 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4980 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4981 | if (npages > ARRAY_SIZE(pages)) |
| 4982 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4983 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4984 | for (i = 0; i < npages; i++) { |
| 4985 | pages[i] = alloc_page(GFP_KERNEL); |
| 4986 | if (!pages[i]) |
| 4987 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4988 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4989 | |
| 4990 | /* for decoding across pages */ |
| 4991 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4992 | if (!res.acl_scratch) |
| 4993 | goto out_free; |
| 4994 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4995 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4996 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4997 | 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] | 4998 | __func__, buf, buflen, npages, args.acl_len); |
| 4999 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5000 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5001 | if (ret) |
| 5002 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5003 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5004 | /* Handle the case where the passed-in buffer is too short */ |
| 5005 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5006 | /* Did the user only issue a request for the acl length? */ |
| 5007 | if (buf == NULL) |
| 5008 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5009 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5010 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5011 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5012 | 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] | 5013 | if (buf) { |
| 5014 | if (res.acl_len > buflen) { |
| 5015 | ret = -ERANGE; |
| 5016 | goto out_free; |
| 5017 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5018 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5019 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5020 | out_ok: |
| 5021 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5022 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5023 | for (i = 0; i < npages; i++) |
| 5024 | if (pages[i]) |
| 5025 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5026 | if (res.acl_scratch) |
| 5027 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5028 | return ret; |
| 5029 | } |
| 5030 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5031 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5032 | { |
| 5033 | struct nfs4_exception exception = { }; |
| 5034 | ssize_t ret; |
| 5035 | do { |
| 5036 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5037 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5038 | if (ret >= 0) |
| 5039 | break; |
| 5040 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5041 | } while (exception.retry); |
| 5042 | return ret; |
| 5043 | } |
| 5044 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5045 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5046 | { |
| 5047 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5048 | int ret; |
| 5049 | |
| 5050 | if (!nfs4_server_supports_acls(server)) |
| 5051 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5052 | ret = nfs_revalidate_inode(server, inode); |
| 5053 | if (ret < 0) |
| 5054 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5055 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5056 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5057 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5058 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5059 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5060 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5061 | return ret; |
| 5062 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5065 | 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] | 5066 | { |
| 5067 | struct nfs_server *server = NFS_SERVER(inode); |
| 5068 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5069 | struct nfs_setaclargs arg = { |
| 5070 | .fh = NFS_FH(inode), |
| 5071 | .acl_pages = pages, |
| 5072 | .acl_len = buflen, |
| 5073 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5074 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5075 | struct rpc_message msg = { |
| 5076 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5077 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5078 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5079 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5080 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5081 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5082 | |
| 5083 | if (!nfs4_server_supports_acls(server)) |
| 5084 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5085 | if (npages > ARRAY_SIZE(pages)) |
| 5086 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5087 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5088 | if (i < 0) |
| 5089 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5090 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5091 | 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] | 5092 | |
| 5093 | /* |
| 5094 | * Free each page after tx, so the only ref left is |
| 5095 | * held by the network stack |
| 5096 | */ |
| 5097 | for (; i > 0; i--) |
| 5098 | put_page(pages[i-1]); |
| 5099 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5100 | /* |
| 5101 | * Acl update can result in inode attribute update. |
| 5102 | * so mark the attribute cache invalid. |
| 5103 | */ |
| 5104 | spin_lock(&inode->i_lock); |
| 5105 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5106 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5107 | nfs_access_zap_cache(inode); |
| 5108 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5109 | return ret; |
| 5110 | } |
| 5111 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5112 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5113 | { |
| 5114 | struct nfs4_exception exception = { }; |
| 5115 | int err; |
| 5116 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5117 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5118 | trace_nfs4_set_acl(inode, err); |
| 5119 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5120 | &exception); |
| 5121 | } while (exception.retry); |
| 5122 | return err; |
| 5123 | } |
| 5124 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5125 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5126 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5127 | size_t buflen) |
| 5128 | { |
| 5129 | struct nfs_server *server = NFS_SERVER(inode); |
| 5130 | struct nfs_fattr fattr; |
| 5131 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5132 | |
| 5133 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5134 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5135 | .fh = NFS_FH(inode), |
| 5136 | .bitmask = bitmask, |
| 5137 | }; |
| 5138 | struct nfs4_getattr_res res = { |
| 5139 | .fattr = &fattr, |
| 5140 | .label = &label, |
| 5141 | .server = server, |
| 5142 | }; |
| 5143 | struct rpc_message msg = { |
| 5144 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5145 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5146 | .rpc_resp = &res, |
| 5147 | }; |
| 5148 | int ret; |
| 5149 | |
| 5150 | nfs_fattr_init(&fattr); |
| 5151 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5152 | 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] | 5153 | if (ret) |
| 5154 | return ret; |
| 5155 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5156 | return -ENOENT; |
| 5157 | if (buflen < label.len) |
| 5158 | return -ERANGE; |
| 5159 | return 0; |
| 5160 | } |
| 5161 | |
| 5162 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5163 | size_t buflen) |
| 5164 | { |
| 5165 | struct nfs4_exception exception = { }; |
| 5166 | int err; |
| 5167 | |
| 5168 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5169 | return -EOPNOTSUPP; |
| 5170 | |
| 5171 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5172 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5173 | trace_nfs4_get_security_label(inode, err); |
| 5174 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5175 | &exception); |
| 5176 | } while (exception.retry); |
| 5177 | return err; |
| 5178 | } |
| 5179 | |
| 5180 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5181 | struct nfs4_label *ilabel, |
| 5182 | struct nfs_fattr *fattr, |
| 5183 | struct nfs4_label *olabel) |
| 5184 | { |
| 5185 | |
| 5186 | struct iattr sattr = {0}; |
| 5187 | struct nfs_server *server = NFS_SERVER(inode); |
| 5188 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5189 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5190 | .fh = NFS_FH(inode), |
| 5191 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5192 | .server = server, |
| 5193 | .bitmask = bitmask, |
| 5194 | .label = ilabel, |
| 5195 | }; |
| 5196 | struct nfs_setattrres res = { |
| 5197 | .fattr = fattr, |
| 5198 | .label = olabel, |
| 5199 | .server = server, |
| 5200 | }; |
| 5201 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5203 | .rpc_argp = &arg, |
| 5204 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5205 | }; |
| 5206 | int status; |
| 5207 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5208 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5209 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5210 | 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] | 5211 | if (status) |
| 5212 | dprintk("%s failed: %d\n", __func__, status); |
| 5213 | |
| 5214 | return status; |
| 5215 | } |
| 5216 | |
| 5217 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5218 | struct nfs4_label *ilabel, |
| 5219 | struct nfs_fattr *fattr, |
| 5220 | struct nfs4_label *olabel) |
| 5221 | { |
| 5222 | struct nfs4_exception exception = { }; |
| 5223 | int err; |
| 5224 | |
| 5225 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5226 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5227 | fattr, olabel); |
| 5228 | trace_nfs4_set_security_label(inode, err); |
| 5229 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5230 | &exception); |
| 5231 | } while (exception.retry); |
| 5232 | return err; |
| 5233 | } |
| 5234 | |
| 5235 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5236 | 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] | 5237 | { |
| 5238 | struct nfs4_label ilabel, *olabel = NULL; |
| 5239 | struct nfs_fattr fattr; |
| 5240 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5241 | int status; |
| 5242 | |
| 5243 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5244 | return -EOPNOTSUPP; |
| 5245 | |
| 5246 | nfs_fattr_init(&fattr); |
| 5247 | |
| 5248 | ilabel.pi = 0; |
| 5249 | ilabel.lfs = 0; |
| 5250 | ilabel.label = (char *)buf; |
| 5251 | ilabel.len = buflen; |
| 5252 | |
| 5253 | cred = rpc_lookup_cred(); |
| 5254 | if (IS_ERR(cred)) |
| 5255 | return PTR_ERR(cred); |
| 5256 | |
| 5257 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5258 | if (IS_ERR(olabel)) { |
| 5259 | status = -PTR_ERR(olabel); |
| 5260 | goto out; |
| 5261 | } |
| 5262 | |
| 5263 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5264 | if (status == 0) |
| 5265 | nfs_setsecurity(inode, &fattr, olabel); |
| 5266 | |
| 5267 | nfs4_label_free(olabel); |
| 5268 | out: |
| 5269 | put_rpccred(cred); |
| 5270 | return status; |
| 5271 | } |
| 5272 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5273 | |
| 5274 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5275 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5276 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5277 | { |
| 5278 | __be32 verf[2]; |
| 5279 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5280 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5281 | /* An impossible timestamp guarantees this value |
| 5282 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5283 | verf[0] = cpu_to_be32(U32_MAX); |
| 5284 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5285 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5286 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5287 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5288 | |
| 5289 | verf[0] = cpu_to_be32(ns >> 32); |
| 5290 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5291 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5292 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5293 | } |
| 5294 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5295 | static int |
| 5296 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5297 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5298 | size_t len; |
| 5299 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5300 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5301 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5302 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5303 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5304 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5305 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5306 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5307 | 1 + |
| 5308 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5309 | 1; |
| 5310 | rcu_read_unlock(); |
| 5311 | |
| 5312 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5313 | return -EINVAL; |
| 5314 | |
| 5315 | /* |
| 5316 | * Since this string is allocated at mount time, and held until the |
| 5317 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5318 | * about a memory-reclaim deadlock. |
| 5319 | */ |
| 5320 | str = kmalloc(len, GFP_KERNEL); |
| 5321 | if (!str) |
| 5322 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5323 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5324 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5325 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5326 | clp->cl_ipaddr, |
| 5327 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5328 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5329 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5330 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5331 | clp->cl_owner_id = str; |
| 5332 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5333 | } |
| 5334 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5335 | static int |
| 5336 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5337 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5338 | size_t len; |
| 5339 | char *str; |
| 5340 | |
| 5341 | len = 10 + 10 + 1 + 10 + 1 + |
| 5342 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5343 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5344 | |
| 5345 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5346 | return -EINVAL; |
| 5347 | |
| 5348 | /* |
| 5349 | * Since this string is allocated at mount time, and held until the |
| 5350 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5351 | * about a memory-reclaim deadlock. |
| 5352 | */ |
| 5353 | str = kmalloc(len, GFP_KERNEL); |
| 5354 | if (!str) |
| 5355 | return -ENOMEM; |
| 5356 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5357 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5358 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5359 | nfs4_client_id_uniquifier, |
| 5360 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5361 | clp->cl_owner_id = str; |
| 5362 | return 0; |
| 5363 | } |
| 5364 | |
| 5365 | static int |
| 5366 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5367 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5368 | size_t len; |
| 5369 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5370 | |
| 5371 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5372 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5373 | |
| 5374 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5375 | return nfs4_init_uniquifier_client_string(clp); |
| 5376 | |
| 5377 | len = 10 + 10 + 1 + 10 + 1 + |
| 5378 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5379 | |
| 5380 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5381 | return -EINVAL; |
| 5382 | |
| 5383 | /* |
| 5384 | * Since this string is allocated at mount time, and held until the |
| 5385 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5386 | * about a memory-reclaim deadlock. |
| 5387 | */ |
| 5388 | str = kmalloc(len, GFP_KERNEL); |
| 5389 | if (!str) |
| 5390 | return -ENOMEM; |
| 5391 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5392 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5393 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5394 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5395 | clp->cl_owner_id = str; |
| 5396 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5397 | } |
| 5398 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5399 | /* |
| 5400 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5401 | * services. Advertise one based on the address family of the |
| 5402 | * clientaddr. |
| 5403 | */ |
| 5404 | static unsigned int |
| 5405 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5406 | { |
| 5407 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5408 | return scnprintf(buf, len, "tcp6"); |
| 5409 | else |
| 5410 | return scnprintf(buf, len, "tcp"); |
| 5411 | } |
| 5412 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5413 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5414 | { |
| 5415 | struct nfs4_setclientid *sc = calldata; |
| 5416 | |
| 5417 | if (task->tk_status == 0) |
| 5418 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5419 | } |
| 5420 | |
| 5421 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5422 | .rpc_call_done = nfs4_setclientid_done, |
| 5423 | }; |
| 5424 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5425 | /** |
| 5426 | * nfs4_proc_setclientid - Negotiate client ID |
| 5427 | * @clp: state data structure |
| 5428 | * @program: RPC program for NFSv4 callback service |
| 5429 | * @port: IP port number for NFS4 callback service |
| 5430 | * @cred: RPC credential to use for this call |
| 5431 | * @res: where to place the result |
| 5432 | * |
| 5433 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5434 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5435 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5436 | unsigned short port, struct rpc_cred *cred, |
| 5437 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | { |
| 5439 | nfs4_verifier sc_verifier; |
| 5440 | struct nfs4_setclientid setclientid = { |
| 5441 | .sc_verifier = &sc_verifier, |
| 5442 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5443 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | }; |
| 5445 | struct rpc_message msg = { |
| 5446 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5447 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5448 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5449 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5451 | struct rpc_task *task; |
| 5452 | struct rpc_task_setup task_setup_data = { |
| 5453 | .rpc_client = clp->cl_rpcclient, |
| 5454 | .rpc_message = &msg, |
| 5455 | .callback_ops = &nfs4_setclientid_ops, |
| 5456 | .callback_data = &setclientid, |
| 5457 | .flags = RPC_TASK_TIMEOUT, |
| 5458 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5459 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5461 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5462 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5463 | |
| 5464 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5465 | status = nfs4_init_uniform_client_string(clp); |
| 5466 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5467 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5468 | |
| 5469 | if (status) |
| 5470 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5471 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5472 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5473 | setclientid.sc_netid_len = |
| 5474 | nfs4_init_callback_netid(clp, |
| 5475 | setclientid.sc_netid, |
| 5476 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5477 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5478 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5480 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5481 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5482 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5483 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5484 | task = rpc_run_task(&task_setup_data); |
| 5485 | if (IS_ERR(task)) { |
| 5486 | status = PTR_ERR(task); |
| 5487 | goto out; |
| 5488 | } |
| 5489 | status = task->tk_status; |
| 5490 | if (setclientid.sc_cred) { |
| 5491 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5492 | put_rpccred(setclientid.sc_cred); |
| 5493 | } |
| 5494 | rpc_put_task(task); |
| 5495 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5496 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5497 | dprintk("NFS reply setclientid: %d\n", status); |
| 5498 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | } |
| 5500 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5501 | /** |
| 5502 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5503 | * @clp: state data structure |
| 5504 | * @res: result of a previous SETCLIENTID |
| 5505 | * @cred: RPC credential to use for this call |
| 5506 | * |
| 5507 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5508 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5509 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5510 | struct nfs4_setclientid_res *arg, |
| 5511 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | struct rpc_message msg = { |
| 5514 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5515 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5516 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | int status; |
| 5519 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5520 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5521 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5522 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5523 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5524 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5525 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | return status; |
| 5527 | } |
| 5528 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5529 | struct nfs4_delegreturndata { |
| 5530 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5531 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5532 | struct nfs_fh fh; |
| 5533 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5534 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5535 | struct { |
| 5536 | struct nfs4_layoutreturn_args arg; |
| 5537 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5538 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5539 | u32 roc_barrier; |
| 5540 | bool roc; |
| 5541 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5542 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5543 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5544 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5545 | }; |
| 5546 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5547 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5548 | { |
| 5549 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5550 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5551 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5552 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5553 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5554 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5555 | |
| 5556 | /* Handle Layoutreturn errors */ |
| 5557 | if (data->args.lr_args && task->tk_status != 0) { |
| 5558 | switch(data->res.lr_ret) { |
| 5559 | default: |
| 5560 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5561 | break; |
| 5562 | case 0: |
| 5563 | data->args.lr_args = NULL; |
| 5564 | data->res.lr_res = NULL; |
| 5565 | break; |
| 5566 | case -NFS4ERR_ADMIN_REVOKED: |
| 5567 | case -NFS4ERR_DELEG_REVOKED: |
| 5568 | case -NFS4ERR_EXPIRED: |
| 5569 | case -NFS4ERR_BAD_STATEID: |
| 5570 | case -NFS4ERR_OLD_STATEID: |
| 5571 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5572 | case -NFS4ERR_WRONG_CRED: |
| 5573 | data->args.lr_args = NULL; |
| 5574 | data->res.lr_res = NULL; |
| 5575 | data->res.lr_ret = 0; |
| 5576 | rpc_restart_call_prepare(task); |
| 5577 | return; |
| 5578 | } |
| 5579 | } |
| 5580 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5581 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5582 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5583 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5584 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5585 | case -NFS4ERR_ADMIN_REVOKED: |
| 5586 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5587 | case -NFS4ERR_EXPIRED: |
| 5588 | nfs4_free_revoked_stateid(data->res.server, |
| 5589 | data->args.stateid, |
| 5590 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5591 | case -NFS4ERR_BAD_STATEID: |
| 5592 | case -NFS4ERR_OLD_STATEID: |
| 5593 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5594 | task->tk_status = 0; |
| 5595 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5596 | case -NFS4ERR_ACCESS: |
| 5597 | if (data->args.bitmask) { |
| 5598 | data->args.bitmask = NULL; |
| 5599 | data->res.fattr = NULL; |
| 5600 | task->tk_status = 0; |
| 5601 | rpc_restart_call_prepare(task); |
| 5602 | return; |
| 5603 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5604 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5605 | if (nfs4_async_handle_error(task, data->res.server, |
| 5606 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5607 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5608 | return; |
| 5609 | } |
| 5610 | } |
| 5611 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | static void nfs4_delegreturn_release(void *calldata) |
| 5615 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5616 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5617 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5618 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5619 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5620 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5621 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5622 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5623 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5624 | nfs_iput_and_deactive(inode); |
| 5625 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5626 | kfree(calldata); |
| 5627 | } |
| 5628 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5629 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5630 | { |
| 5631 | struct nfs4_delegreturndata *d_data; |
| 5632 | |
| 5633 | d_data = (struct nfs4_delegreturndata *)data; |
| 5634 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5635 | 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] | 5636 | return; |
| 5637 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5638 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5639 | &d_data->args.seq_args, |
| 5640 | &d_data->res.seq_res, |
| 5641 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5642 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5643 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5644 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5645 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5646 | .rpc_call_done = nfs4_delegreturn_done, |
| 5647 | .rpc_release = nfs4_delegreturn_release, |
| 5648 | }; |
| 5649 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5650 | 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] | 5651 | { |
| 5652 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5653 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5654 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5655 | struct rpc_message msg = { |
| 5656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5657 | .rpc_cred = cred, |
| 5658 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5659 | struct rpc_task_setup task_setup_data = { |
| 5660 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5661 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5662 | .callback_ops = &nfs4_delegreturn_ops, |
| 5663 | .flags = RPC_TASK_ASYNC, |
| 5664 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5665 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5666 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5667 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5668 | if (data == NULL) |
| 5669 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5670 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5671 | |
| 5672 | nfs4_state_protect(server->nfs_client, |
| 5673 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5674 | &task_setup_data.rpc_client, &msg); |
| 5675 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5676 | data->args.fhandle = &data->fh; |
| 5677 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5678 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5679 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5680 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5681 | data->res.fattr = &data->fattr; |
| 5682 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5683 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5684 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5685 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5686 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5687 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5688 | 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] | 5689 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5690 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5691 | if (data->lr.roc) { |
| 5692 | data->args.lr_args = &data->lr.arg; |
| 5693 | data->res.lr_res = &data->lr.res; |
| 5694 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5695 | } else if (data->lr.roc) { |
| 5696 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5697 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5698 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5699 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5700 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5701 | msg.rpc_argp = &data->args; |
| 5702 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5703 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5704 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5705 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5706 | if (!issync) |
| 5707 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5708 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5709 | if (status != 0) |
| 5710 | goto out; |
| 5711 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5712 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5713 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5714 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | } |
| 5716 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5717 | 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] | 5718 | { |
| 5719 | struct nfs_server *server = NFS_SERVER(inode); |
| 5720 | struct nfs4_exception exception = { }; |
| 5721 | int err; |
| 5722 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5723 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5724 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | switch (err) { |
| 5726 | case -NFS4ERR_STALE_STATEID: |
| 5727 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | case 0: |
| 5729 | return 0; |
| 5730 | } |
| 5731 | err = nfs4_handle_exception(server, err, &exception); |
| 5732 | } while (exception.retry); |
| 5733 | return err; |
| 5734 | } |
| 5735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5737 | { |
| 5738 | struct inode *inode = state->inode; |
| 5739 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5740 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5741 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5743 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5745 | struct nfs_lockt_res res = { |
| 5746 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | }; |
| 5748 | struct rpc_message msg = { |
| 5749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5750 | .rpc_argp = &arg, |
| 5751 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | .rpc_cred = state->owner->so_cred, |
| 5753 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | struct nfs4_lock_state *lsp; |
| 5755 | int status; |
| 5756 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5757 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5758 | status = nfs4_set_lock_state(state, request); |
| 5759 | if (status != 0) |
| 5760 | goto out; |
| 5761 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5762 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5763 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5764 | 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] | 5765 | switch (status) { |
| 5766 | case 0: |
| 5767 | request->fl_type = F_UNLCK; |
| 5768 | break; |
| 5769 | case -NFS4ERR_DENIED: |
| 5770 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5772 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5773 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5774 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | return status; |
| 5776 | } |
| 5777 | |
| 5778 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5779 | { |
| 5780 | struct nfs4_exception exception = { }; |
| 5781 | int err; |
| 5782 | |
| 5783 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5784 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5785 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5786 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | &exception); |
| 5788 | } while (exception.retry); |
| 5789 | return err; |
| 5790 | } |
| 5791 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5792 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5793 | struct nfs_locku_args arg; |
| 5794 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5795 | struct nfs4_lock_state *lsp; |
| 5796 | struct nfs_open_context *ctx; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5797 | struct nfs_lock_context *l_ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5798 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5799 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5800 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5801 | }; |
| 5802 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5803 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5804 | struct nfs_open_context *ctx, |
| 5805 | struct nfs4_lock_state *lsp, |
| 5806 | struct nfs_seqid *seqid) |
| 5807 | { |
| 5808 | struct nfs4_unlockdata *p; |
| 5809 | struct inode *inode = lsp->ls_state->inode; |
| 5810 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5811 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5812 | if (p == NULL) |
| 5813 | return NULL; |
| 5814 | p->arg.fh = NFS_FH(inode); |
| 5815 | p->arg.fl = &p->fl; |
| 5816 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5817 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5818 | p->lsp = lsp; |
| 5819 | atomic_inc(&lsp->ls_count); |
| 5820 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5821 | p->ctx = get_nfs_open_context(ctx); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5822 | p->l_ctx = nfs_get_lock_context(ctx); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5823 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5824 | p->server = NFS_SERVER(inode); |
| 5825 | return p; |
| 5826 | } |
| 5827 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5828 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5829 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5830 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5831 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5832 | nfs4_put_lock_state(calldata->lsp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5833 | nfs_put_lock_context(calldata->l_ctx); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5834 | put_nfs_open_context(calldata->ctx); |
| 5835 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5836 | } |
| 5837 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5838 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5839 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5840 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5841 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5842 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5843 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5844 | switch (task->tk_status) { |
| 5845 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5846 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5847 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5848 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5849 | &calldata->res.stateid)) |
| 5850 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5851 | case -NFS4ERR_ADMIN_REVOKED: |
| 5852 | case -NFS4ERR_EXPIRED: |
| 5853 | nfs4_free_revoked_stateid(calldata->server, |
| 5854 | &calldata->arg.stateid, |
| 5855 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5856 | case -NFS4ERR_BAD_STATEID: |
| 5857 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5858 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5859 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5860 | &calldata->lsp->ls_stateid)) |
| 5861 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5862 | break; |
| 5863 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5864 | if (nfs4_async_handle_error(task, calldata->server, |
| 5865 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5866 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5867 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5868 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5871 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5872 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5873 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5874 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5875 | if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) && |
| 5876 | nfs_async_iocounter_wait(task, calldata->l_ctx)) |
| 5877 | return; |
| 5878 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5879 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5880 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5881 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5882 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5883 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5884 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5885 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5886 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5887 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5888 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5889 | &calldata->res.seq_res, |
| 5890 | task) != 0) |
| 5891 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5892 | return; |
| 5893 | out_no_action: |
| 5894 | task->tk_action = NULL; |
| 5895 | out_wait: |
| 5896 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5897 | } |
| 5898 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5899 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5900 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5901 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5902 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5903 | }; |
| 5904 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5905 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5906 | struct nfs_open_context *ctx, |
| 5907 | struct nfs4_lock_state *lsp, |
| 5908 | struct nfs_seqid *seqid) |
| 5909 | { |
| 5910 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5911 | struct rpc_message msg = { |
| 5912 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5913 | .rpc_cred = ctx->cred, |
| 5914 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5915 | struct rpc_task_setup task_setup_data = { |
| 5916 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5917 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5918 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5919 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5920 | .flags = RPC_TASK_ASYNC, |
| 5921 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5922 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5923 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5924 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5925 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5926 | /* Ensure this is an unlock - when canceling a lock, the |
| 5927 | * canceled lock is passed in, and it won't be an unlock. |
| 5928 | */ |
| 5929 | fl->fl_type = F_UNLCK; |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 5930 | if (fl->fl_flags & FL_CLOSE) |
| 5931 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5932 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5933 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5934 | if (data == NULL) { |
| 5935 | nfs_free_seqid(seqid); |
| 5936 | return ERR_PTR(-ENOMEM); |
| 5937 | } |
| 5938 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5939 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5940 | msg.rpc_argp = &data->arg; |
| 5941 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5942 | task_setup_data.callback_data = data; |
| 5943 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5944 | } |
| 5945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5947 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5948 | struct inode *inode = state->inode; |
| 5949 | struct nfs4_state_owner *sp = state->owner; |
| 5950 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5951 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5952 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5953 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5954 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5955 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5956 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5957 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5958 | status = nfs4_set_lock_state(state, request); |
| 5959 | /* Unlock _before_ we do the RPC call */ |
| 5960 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5961 | /* Exclude nfs_delegation_claim_locks() */ |
| 5962 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5963 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5964 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5965 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5966 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5967 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5968 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5969 | } |
| 5970 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5971 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5972 | if (status != 0) |
| 5973 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5974 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5975 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5976 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5977 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5978 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5979 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5980 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5981 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5982 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5983 | 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] | 5984 | status = PTR_ERR(task); |
| 5985 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5986 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5987 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5988 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5989 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5990 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5991 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5992 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5995 | struct nfs4_lockdata { |
| 5996 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5997 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5998 | struct nfs4_lock_state *lsp; |
| 5999 | struct nfs_open_context *ctx; |
| 6000 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6001 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6002 | int rpc_status; |
| 6003 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6004 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6005 | }; |
| 6006 | |
| 6007 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6008 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6009 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6010 | { |
| 6011 | struct nfs4_lockdata *p; |
| 6012 | struct inode *inode = lsp->ls_state->inode; |
| 6013 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6014 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6015 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6016 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6017 | if (p == NULL) |
| 6018 | return NULL; |
| 6019 | |
| 6020 | p->arg.fh = NFS_FH(inode); |
| 6021 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6022 | 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] | 6023 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6024 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6025 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6026 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6027 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6028 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6029 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6030 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6031 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6032 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6033 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6034 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6035 | atomic_inc(&lsp->ls_count); |
| 6036 | p->ctx = get_nfs_open_context(ctx); |
| 6037 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6038 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6039 | out_free_seqid: |
| 6040 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6041 | out_free: |
| 6042 | kfree(p); |
| 6043 | return NULL; |
| 6044 | } |
| 6045 | |
| 6046 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6047 | { |
| 6048 | struct nfs4_lockdata *data = calldata; |
| 6049 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6051 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6052 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6053 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6054 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6055 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6056 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6057 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6058 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6059 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6060 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6061 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6062 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6063 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6064 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6065 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6066 | &data->lsp->ls_stateid); |
| 6067 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6068 | if (!nfs4_valid_open_stateid(state)) { |
| 6069 | data->rpc_status = -EBADF; |
| 6070 | task->tk_action = NULL; |
| 6071 | goto out_release_open_seqid; |
| 6072 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6073 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6074 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6075 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6076 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6077 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6078 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6079 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6080 | nfs_release_seqid(data->arg.open_seqid); |
| 6081 | out_release_lock_seqid: |
| 6082 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6083 | out_wait: |
| 6084 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6085 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6086 | } |
| 6087 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6088 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6089 | { |
| 6090 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6091 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6092 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6093 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6094 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6095 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6096 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6097 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6098 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6099 | switch (task->tk_status) { |
| 6100 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6101 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6102 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6103 | if (data->arg.new_lock) { |
| 6104 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6105 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6106 | rpc_restart_call_prepare(task); |
| 6107 | break; |
| 6108 | } |
| 6109 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6110 | if (data->arg.new_lock_owner != 0) { |
| 6111 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6112 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6113 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6114 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6115 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6116 | break; |
| 6117 | case -NFS4ERR_BAD_STATEID: |
| 6118 | case -NFS4ERR_OLD_STATEID: |
| 6119 | case -NFS4ERR_STALE_STATEID: |
| 6120 | case -NFS4ERR_EXPIRED: |
| 6121 | if (data->arg.new_lock_owner != 0) { |
| 6122 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6123 | &lsp->ls_state->open_stateid)) |
| 6124 | rpc_restart_call_prepare(task); |
| 6125 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6126 | &lsp->ls_stateid)) |
| 6127 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6128 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6129 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | static void nfs4_lock_release(void *calldata) |
| 6133 | { |
| 6134 | struct nfs4_lockdata *data = calldata; |
| 6135 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6136 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6137 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6138 | if (data->cancelled != 0) { |
| 6139 | struct rpc_task *task; |
| 6140 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6141 | data->arg.lock_seqid); |
| 6142 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6143 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6144 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6145 | } else |
| 6146 | nfs_free_seqid(data->arg.lock_seqid); |
| 6147 | nfs4_put_lock_state(data->lsp); |
| 6148 | put_nfs_open_context(data->ctx); |
| 6149 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6150 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6154 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6155 | .rpc_call_done = nfs4_lock_done, |
| 6156 | .rpc_release = nfs4_lock_release, |
| 6157 | }; |
| 6158 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6159 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6160 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6161 | switch (error) { |
| 6162 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6163 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6164 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6165 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6166 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6167 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6168 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6169 | break; |
| 6170 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6171 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6172 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6173 | }; |
| 6174 | } |
| 6175 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6176 | 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] | 6177 | { |
| 6178 | struct nfs4_lockdata *data; |
| 6179 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6180 | struct rpc_message msg = { |
| 6181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6182 | .rpc_cred = state->owner->so_cred, |
| 6183 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6184 | struct rpc_task_setup task_setup_data = { |
| 6185 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6186 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6187 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6188 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6189 | .flags = RPC_TASK_ASYNC, |
| 6190 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6191 | int ret; |
| 6192 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6193 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6194 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6195 | fl->fl_u.nfs4_fl.owner, |
| 6196 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6197 | if (data == NULL) |
| 6198 | return -ENOMEM; |
| 6199 | if (IS_SETLKW(cmd)) |
| 6200 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6201 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6202 | msg.rpc_argp = &data->arg; |
| 6203 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6204 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6205 | if (recovery_type > NFS_LOCK_NEW) { |
| 6206 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6207 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6208 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6209 | } else |
| 6210 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6211 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6212 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6213 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6214 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6215 | if (ret == 0) { |
| 6216 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6217 | if (ret) |
| 6218 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6219 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6220 | } else |
| 6221 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6222 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6223 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6224 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6225 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6229 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6230 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6231 | struct nfs4_exception exception = { |
| 6232 | .inode = state->inode, |
| 6233 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6234 | int err; |
| 6235 | |
| 6236 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6237 | /* Cache the lock if possible... */ |
| 6238 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6239 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6240 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6241 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6242 | break; |
| 6243 | nfs4_handle_exception(server, err, &exception); |
| 6244 | } while (exception.retry); |
| 6245 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6249 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6250 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6251 | struct nfs4_exception exception = { |
| 6252 | .inode = state->inode, |
| 6253 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6254 | int err; |
| 6255 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6256 | err = nfs4_set_lock_state(state, request); |
| 6257 | if (err != 0) |
| 6258 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6259 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6260 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6261 | return 0; |
| 6262 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6263 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6264 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6265 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6266 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6267 | switch (err) { |
| 6268 | default: |
| 6269 | goto out; |
| 6270 | case -NFS4ERR_GRACE: |
| 6271 | case -NFS4ERR_DELAY: |
| 6272 | nfs4_handle_exception(server, err, &exception); |
| 6273 | err = 0; |
| 6274 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6275 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6276 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6277 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | } |
| 6279 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6280 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6281 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6282 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6283 | struct nfs4_lock_state *lsp; |
| 6284 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6285 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6286 | status = nfs4_set_lock_state(state, request); |
| 6287 | if (status != 0) |
| 6288 | return status; |
| 6289 | lsp = request->fl_u.nfs4_fl.owner; |
| 6290 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6291 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6292 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6293 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6294 | } |
| 6295 | #endif |
| 6296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6298 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6299 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6300 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6301 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6302 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6304 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6305 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6306 | if (status < 0) |
| 6307 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6308 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6309 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6310 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6311 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6312 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6313 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6314 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6315 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6316 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6317 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6318 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6319 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6320 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6321 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6322 | out: |
| 6323 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | return status; |
| 6325 | } |
| 6326 | |
| 6327 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6328 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6329 | struct nfs4_exception exception = { |
| 6330 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6331 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6332 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | int err; |
| 6334 | |
| 6335 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6336 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6337 | if (err == -NFS4ERR_DENIED) |
| 6338 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6340 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | } while (exception.retry); |
| 6342 | return err; |
| 6343 | } |
| 6344 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6345 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6346 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6347 | |
| 6348 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6349 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6350 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6351 | { |
| 6352 | int status = -ERESTARTSYS; |
| 6353 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6354 | |
| 6355 | while(!signalled()) { |
| 6356 | status = nfs4_proc_setlk(state, cmd, request); |
| 6357 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6358 | break; |
| 6359 | freezable_schedule_timeout_interruptible(timeout); |
| 6360 | timeout *= 2; |
| 6361 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6362 | status = -ERESTARTSYS; |
| 6363 | } |
| 6364 | return status; |
| 6365 | } |
| 6366 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6367 | #ifdef CONFIG_NFS_V4_1 |
| 6368 | struct nfs4_lock_waiter { |
| 6369 | struct task_struct *task; |
| 6370 | struct inode *inode; |
| 6371 | struct nfs_lowner *owner; |
| 6372 | bool notified; |
| 6373 | }; |
| 6374 | |
| 6375 | static int |
| 6376 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6377 | { |
| 6378 | int ret; |
| 6379 | struct cb_notify_lock_args *cbnl = key; |
| 6380 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6381 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6382 | *wowner = waiter->owner; |
| 6383 | |
| 6384 | /* Only wake if the callback was for the same owner */ |
| 6385 | if (lowner->clientid != wowner->clientid || |
| 6386 | lowner->id != wowner->id || |
| 6387 | lowner->s_dev != wowner->s_dev) |
| 6388 | return 0; |
| 6389 | |
| 6390 | /* Make sure it's for the right inode */ |
| 6391 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6392 | return 0; |
| 6393 | |
| 6394 | waiter->notified = true; |
| 6395 | |
| 6396 | /* override "private" so we can use default_wake_function */ |
| 6397 | wait->private = waiter->task; |
| 6398 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6399 | wait->private = waiter; |
| 6400 | return ret; |
| 6401 | } |
| 6402 | |
| 6403 | static int |
| 6404 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6405 | { |
| 6406 | int status = -ERESTARTSYS; |
| 6407 | unsigned long flags; |
| 6408 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6409 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6410 | struct nfs_client *clp = server->nfs_client; |
| 6411 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6412 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6413 | .id = lsp->ls_seqid.owner_id, |
| 6414 | .s_dev = server->s_dev }; |
| 6415 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6416 | .inode = state->inode, |
| 6417 | .owner = &owner, |
| 6418 | .notified = false }; |
| 6419 | wait_queue_t wait; |
| 6420 | |
| 6421 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6422 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6423 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6424 | |
| 6425 | init_wait(&wait); |
| 6426 | wait.private = &waiter; |
| 6427 | wait.func = nfs4_wake_lock_waiter; |
| 6428 | add_wait_queue(q, &wait); |
| 6429 | |
| 6430 | while(!signalled()) { |
| 6431 | status = nfs4_proc_setlk(state, cmd, request); |
| 6432 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6433 | break; |
| 6434 | |
| 6435 | status = -ERESTARTSYS; |
| 6436 | spin_lock_irqsave(&q->lock, flags); |
| 6437 | if (waiter.notified) { |
| 6438 | spin_unlock_irqrestore(&q->lock, flags); |
| 6439 | continue; |
| 6440 | } |
| 6441 | set_current_state(TASK_INTERRUPTIBLE); |
| 6442 | spin_unlock_irqrestore(&q->lock, flags); |
| 6443 | |
| 6444 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6445 | } |
| 6446 | |
| 6447 | finish_wait(q, &wait); |
| 6448 | return status; |
| 6449 | } |
| 6450 | #else /* !CONFIG_NFS_V4_1 */ |
| 6451 | static inline int |
| 6452 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6453 | { |
| 6454 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6455 | } |
| 6456 | #endif |
| 6457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | static int |
| 6459 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6460 | { |
| 6461 | struct nfs_open_context *ctx; |
| 6462 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | int status; |
| 6464 | |
| 6465 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6466 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6467 | state = ctx->state; |
| 6468 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6469 | if (IS_GETLK(cmd)) { |
| 6470 | if (state != NULL) |
| 6471 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6472 | return 0; |
| 6473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6474 | |
| 6475 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6476 | return -EINVAL; |
| 6477 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6478 | if (request->fl_type == F_UNLCK) { |
| 6479 | if (state != NULL) |
| 6480 | return nfs4_proc_unlck(state, cmd, request); |
| 6481 | return 0; |
| 6482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6484 | if (state == NULL) |
| 6485 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6486 | |
| 6487 | if ((request->fl_flags & FL_POSIX) && |
| 6488 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6489 | return -ENOLCK; |
| 6490 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6491 | status = nfs4_set_lock_state(state, request); |
| 6492 | if (status != 0) |
| 6493 | return status; |
| 6494 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6495 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6496 | } |
| 6497 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6498 | 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] | 6499 | { |
| 6500 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6501 | int err; |
| 6502 | |
| 6503 | err = nfs4_set_lock_state(state, fl); |
| 6504 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6505 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6506 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6507 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6508 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6509 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6510 | struct nfs_release_lockowner_data { |
| 6511 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6512 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6513 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6514 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6515 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6516 | }; |
| 6517 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6518 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6519 | { |
| 6520 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6521 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6522 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6523 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6524 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6525 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6526 | } |
| 6527 | |
| 6528 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6529 | { |
| 6530 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6531 | struct nfs_server *server = data->server; |
| 6532 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6533 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6534 | |
| 6535 | switch (task->tk_status) { |
| 6536 | case 0: |
| 6537 | renew_lease(server, data->timestamp); |
| 6538 | break; |
| 6539 | case -NFS4ERR_STALE_CLIENTID: |
| 6540 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6541 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6542 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6543 | case -NFS4ERR_LEASE_MOVED: |
| 6544 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6545 | if (nfs4_async_handle_error(task, server, |
| 6546 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6547 | rpc_restart_call_prepare(task); |
| 6548 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6549 | } |
| 6550 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6551 | static void nfs4_release_lockowner_release(void *calldata) |
| 6552 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6553 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6554 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6555 | kfree(calldata); |
| 6556 | } |
| 6557 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6558 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6559 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6560 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6561 | .rpc_release = nfs4_release_lockowner_release, |
| 6562 | }; |
| 6563 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6564 | static void |
| 6565 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6566 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6567 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6568 | struct rpc_message msg = { |
| 6569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6570 | }; |
| 6571 | |
| 6572 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6573 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6574 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6575 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6576 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6577 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6578 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6579 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6580 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6581 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6582 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6583 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6584 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6585 | msg.rpc_resp = &data->res; |
| 6586 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6587 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6588 | } |
| 6589 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6590 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6591 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6592 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6593 | struct dentry *unused, struct inode *inode, |
| 6594 | const char *key, const void *buf, |
| 6595 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6596 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6597 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6600 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6601 | struct dentry *unused, struct inode *inode, |
| 6602 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6603 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6604 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6607 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6608 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6609 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6610 | } |
| 6611 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6612 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6613 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6614 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6615 | struct dentry *unused, struct inode *inode, |
| 6616 | const char *key, const void *buf, |
| 6617 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6618 | { |
| 6619 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6620 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6621 | |
| 6622 | return -EOPNOTSUPP; |
| 6623 | } |
| 6624 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6625 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6626 | struct dentry *unused, struct inode *inode, |
| 6627 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6628 | { |
| 6629 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6630 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6631 | return -EOPNOTSUPP; |
| 6632 | } |
| 6633 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6634 | static ssize_t |
| 6635 | 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] | 6636 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6637 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6638 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6639 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6640 | len = security_inode_listsecurity(inode, list, list_len); |
| 6641 | if (list_len && len > list_len) |
| 6642 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6643 | } |
| 6644 | return len; |
| 6645 | } |
| 6646 | |
| 6647 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6648 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6649 | .get = nfs4_xattr_get_nfs4_label, |
| 6650 | .set = nfs4_xattr_set_nfs4_label, |
| 6651 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6652 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6653 | #else |
| 6654 | |
| 6655 | static ssize_t |
| 6656 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6657 | { |
| 6658 | return 0; |
| 6659 | } |
| 6660 | |
| 6661 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6662 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6663 | /* |
| 6664 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6665 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6666 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6667 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6668 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6669 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6670 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6671 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6672 | return; |
| 6673 | |
| 6674 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6675 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6676 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6677 | fattr->nlink = 2; |
| 6678 | } |
| 6679 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6680 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6681 | const struct qstr *name, |
| 6682 | struct nfs4_fs_locations *fs_locations, |
| 6683 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6684 | { |
| 6685 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6686 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6687 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6688 | }; |
| 6689 | struct nfs4_fs_locations_arg args = { |
| 6690 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6691 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6692 | .page = page, |
| 6693 | .bitmask = bitmask, |
| 6694 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6695 | struct nfs4_fs_locations_res res = { |
| 6696 | .fs_locations = fs_locations, |
| 6697 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6698 | struct rpc_message msg = { |
| 6699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6700 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6701 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6702 | }; |
| 6703 | int status; |
| 6704 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6705 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6706 | |
| 6707 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6708 | * is not supported */ |
| 6709 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6710 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6711 | else |
| 6712 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6713 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6714 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6715 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6716 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6717 | 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] | 6718 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6719 | return status; |
| 6720 | } |
| 6721 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6722 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6723 | const struct qstr *name, |
| 6724 | struct nfs4_fs_locations *fs_locations, |
| 6725 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6726 | { |
| 6727 | struct nfs4_exception exception = { }; |
| 6728 | int err; |
| 6729 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6730 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6731 | fs_locations, page); |
| 6732 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6733 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6734 | &exception); |
| 6735 | } while (exception.retry); |
| 6736 | return err; |
| 6737 | } |
| 6738 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6739 | /* |
| 6740 | * This operation also signals the server that this client is |
| 6741 | * performing migration recovery. The server can stop returning |
| 6742 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6743 | * appended to this compound to identify the client ID which is |
| 6744 | * performing recovery. |
| 6745 | */ |
| 6746 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6747 | struct nfs4_fs_locations *locations, |
| 6748 | struct page *page, struct rpc_cred *cred) |
| 6749 | { |
| 6750 | struct nfs_server *server = NFS_SERVER(inode); |
| 6751 | struct rpc_clnt *clnt = server->client; |
| 6752 | u32 bitmask[2] = { |
| 6753 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6754 | }; |
| 6755 | struct nfs4_fs_locations_arg args = { |
| 6756 | .clientid = server->nfs_client->cl_clientid, |
| 6757 | .fh = NFS_FH(inode), |
| 6758 | .page = page, |
| 6759 | .bitmask = bitmask, |
| 6760 | .migration = 1, /* skip LOOKUP */ |
| 6761 | .renew = 1, /* append RENEW */ |
| 6762 | }; |
| 6763 | struct nfs4_fs_locations_res res = { |
| 6764 | .fs_locations = locations, |
| 6765 | .migration = 1, |
| 6766 | .renew = 1, |
| 6767 | }; |
| 6768 | struct rpc_message msg = { |
| 6769 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6770 | .rpc_argp = &args, |
| 6771 | .rpc_resp = &res, |
| 6772 | .rpc_cred = cred, |
| 6773 | }; |
| 6774 | unsigned long now = jiffies; |
| 6775 | int status; |
| 6776 | |
| 6777 | nfs_fattr_init(&locations->fattr); |
| 6778 | locations->server = server; |
| 6779 | locations->nlocations = 0; |
| 6780 | |
| 6781 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6782 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6783 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6784 | &args.seq_args, &res.seq_res); |
| 6785 | if (status) |
| 6786 | return status; |
| 6787 | |
| 6788 | renew_lease(server, now); |
| 6789 | return 0; |
| 6790 | } |
| 6791 | |
| 6792 | #ifdef CONFIG_NFS_V4_1 |
| 6793 | |
| 6794 | /* |
| 6795 | * This operation also signals the server that this client is |
| 6796 | * performing migration recovery. The server can stop asserting |
| 6797 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6798 | * performing this operation is identified in the SEQUENCE |
| 6799 | * operation in this compound. |
| 6800 | * |
| 6801 | * When the client supports GETATTR(fs_locations_info), it can |
| 6802 | * be plumbed in here. |
| 6803 | */ |
| 6804 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6805 | struct nfs4_fs_locations *locations, |
| 6806 | struct page *page, struct rpc_cred *cred) |
| 6807 | { |
| 6808 | struct nfs_server *server = NFS_SERVER(inode); |
| 6809 | struct rpc_clnt *clnt = server->client; |
| 6810 | u32 bitmask[2] = { |
| 6811 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6812 | }; |
| 6813 | struct nfs4_fs_locations_arg args = { |
| 6814 | .fh = NFS_FH(inode), |
| 6815 | .page = page, |
| 6816 | .bitmask = bitmask, |
| 6817 | .migration = 1, /* skip LOOKUP */ |
| 6818 | }; |
| 6819 | struct nfs4_fs_locations_res res = { |
| 6820 | .fs_locations = locations, |
| 6821 | .migration = 1, |
| 6822 | }; |
| 6823 | struct rpc_message msg = { |
| 6824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6825 | .rpc_argp = &args, |
| 6826 | .rpc_resp = &res, |
| 6827 | .rpc_cred = cred, |
| 6828 | }; |
| 6829 | int status; |
| 6830 | |
| 6831 | nfs_fattr_init(&locations->fattr); |
| 6832 | locations->server = server; |
| 6833 | locations->nlocations = 0; |
| 6834 | |
| 6835 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6836 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6837 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6838 | &args.seq_args, &res.seq_res); |
| 6839 | if (status == NFS4_OK && |
| 6840 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6841 | status = -NFS4ERR_LEASE_MOVED; |
| 6842 | return status; |
| 6843 | } |
| 6844 | |
| 6845 | #endif /* CONFIG_NFS_V4_1 */ |
| 6846 | |
| 6847 | /** |
| 6848 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6849 | * @inode: inode on FSID that is migrating |
| 6850 | * @locations: result of query |
| 6851 | * @page: buffer |
| 6852 | * @cred: credential to use for this operation |
| 6853 | * |
| 6854 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6855 | * operation failed, or a negative errno if a local error occurred. |
| 6856 | * |
| 6857 | * On success, "locations" is filled in, but if the server has |
| 6858 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6859 | * asserted. |
| 6860 | * |
| 6861 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6862 | * from this client that require migration recovery. |
| 6863 | */ |
| 6864 | int nfs4_proc_get_locations(struct inode *inode, |
| 6865 | struct nfs4_fs_locations *locations, |
| 6866 | struct page *page, struct rpc_cred *cred) |
| 6867 | { |
| 6868 | struct nfs_server *server = NFS_SERVER(inode); |
| 6869 | struct nfs_client *clp = server->nfs_client; |
| 6870 | const struct nfs4_mig_recovery_ops *ops = |
| 6871 | clp->cl_mvops->mig_recovery_ops; |
| 6872 | struct nfs4_exception exception = { }; |
| 6873 | int status; |
| 6874 | |
| 6875 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6876 | (unsigned long long)server->fsid.major, |
| 6877 | (unsigned long long)server->fsid.minor, |
| 6878 | clp->cl_hostname); |
| 6879 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6880 | |
| 6881 | do { |
| 6882 | status = ops->get_locations(inode, locations, page, cred); |
| 6883 | if (status != -NFS4ERR_DELAY) |
| 6884 | break; |
| 6885 | nfs4_handle_exception(server, status, &exception); |
| 6886 | } while (exception.retry); |
| 6887 | return status; |
| 6888 | } |
| 6889 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6890 | /* |
| 6891 | * This operation also signals the server that this client is |
| 6892 | * performing "lease moved" recovery. The server can stop |
| 6893 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6894 | * is appended to this compound to identify the client ID which is |
| 6895 | * performing recovery. |
| 6896 | */ |
| 6897 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6898 | { |
| 6899 | struct nfs_server *server = NFS_SERVER(inode); |
| 6900 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6901 | struct rpc_clnt *clnt = server->client; |
| 6902 | struct nfs4_fsid_present_arg args = { |
| 6903 | .fh = NFS_FH(inode), |
| 6904 | .clientid = clp->cl_clientid, |
| 6905 | .renew = 1, /* append RENEW */ |
| 6906 | }; |
| 6907 | struct nfs4_fsid_present_res res = { |
| 6908 | .renew = 1, |
| 6909 | }; |
| 6910 | struct rpc_message msg = { |
| 6911 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6912 | .rpc_argp = &args, |
| 6913 | .rpc_resp = &res, |
| 6914 | .rpc_cred = cred, |
| 6915 | }; |
| 6916 | unsigned long now = jiffies; |
| 6917 | int status; |
| 6918 | |
| 6919 | res.fh = nfs_alloc_fhandle(); |
| 6920 | if (res.fh == NULL) |
| 6921 | return -ENOMEM; |
| 6922 | |
| 6923 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6924 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6925 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6926 | &args.seq_args, &res.seq_res); |
| 6927 | nfs_free_fhandle(res.fh); |
| 6928 | if (status) |
| 6929 | return status; |
| 6930 | |
| 6931 | do_renew_lease(clp, now); |
| 6932 | return 0; |
| 6933 | } |
| 6934 | |
| 6935 | #ifdef CONFIG_NFS_V4_1 |
| 6936 | |
| 6937 | /* |
| 6938 | * This operation also signals the server that this client is |
| 6939 | * performing "lease moved" recovery. The server can stop asserting |
| 6940 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6941 | * this operation is identified in the SEQUENCE operation in this |
| 6942 | * compound. |
| 6943 | */ |
| 6944 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6945 | { |
| 6946 | struct nfs_server *server = NFS_SERVER(inode); |
| 6947 | struct rpc_clnt *clnt = server->client; |
| 6948 | struct nfs4_fsid_present_arg args = { |
| 6949 | .fh = NFS_FH(inode), |
| 6950 | }; |
| 6951 | struct nfs4_fsid_present_res res = { |
| 6952 | }; |
| 6953 | struct rpc_message msg = { |
| 6954 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6955 | .rpc_argp = &args, |
| 6956 | .rpc_resp = &res, |
| 6957 | .rpc_cred = cred, |
| 6958 | }; |
| 6959 | int status; |
| 6960 | |
| 6961 | res.fh = nfs_alloc_fhandle(); |
| 6962 | if (res.fh == NULL) |
| 6963 | return -ENOMEM; |
| 6964 | |
| 6965 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6966 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6967 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6968 | &args.seq_args, &res.seq_res); |
| 6969 | nfs_free_fhandle(res.fh); |
| 6970 | if (status == NFS4_OK && |
| 6971 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6972 | status = -NFS4ERR_LEASE_MOVED; |
| 6973 | return status; |
| 6974 | } |
| 6975 | |
| 6976 | #endif /* CONFIG_NFS_V4_1 */ |
| 6977 | |
| 6978 | /** |
| 6979 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6980 | * @inode: inode on FSID to check |
| 6981 | * @cred: credential to use for this operation |
| 6982 | * |
| 6983 | * Server indicates whether the FSID is present, moved, or not |
| 6984 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6985 | * condition for this client ID. |
| 6986 | * |
| 6987 | * Returns NFS4_OK if the FSID is present on this server, |
| 6988 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6989 | * NFS4ERR code if some error occurred on the server, or a |
| 6990 | * negative errno if a local failure occurred. |
| 6991 | */ |
| 6992 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6993 | { |
| 6994 | struct nfs_server *server = NFS_SERVER(inode); |
| 6995 | struct nfs_client *clp = server->nfs_client; |
| 6996 | const struct nfs4_mig_recovery_ops *ops = |
| 6997 | clp->cl_mvops->mig_recovery_ops; |
| 6998 | struct nfs4_exception exception = { }; |
| 6999 | int status; |
| 7000 | |
| 7001 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7002 | (unsigned long long)server->fsid.major, |
| 7003 | (unsigned long long)server->fsid.minor, |
| 7004 | clp->cl_hostname); |
| 7005 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7006 | |
| 7007 | do { |
| 7008 | status = ops->fsid_present(inode, cred); |
| 7009 | if (status != -NFS4ERR_DELAY) |
| 7010 | break; |
| 7011 | nfs4_handle_exception(server, status, &exception); |
| 7012 | } while (exception.retry); |
| 7013 | return status; |
| 7014 | } |
| 7015 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7016 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7017 | * If 'use_integrity' is true and the state managment nfs_client |
| 7018 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7019 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7020 | * Considerations sections. Otherwise, just use the user cred with the |
| 7021 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7022 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7023 | 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] | 7024 | { |
| 7025 | int status; |
| 7026 | struct nfs4_secinfo_arg args = { |
| 7027 | .dir_fh = NFS_FH(dir), |
| 7028 | .name = name, |
| 7029 | }; |
| 7030 | struct nfs4_secinfo_res res = { |
| 7031 | .flavors = flavors, |
| 7032 | }; |
| 7033 | struct rpc_message msg = { |
| 7034 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7035 | .rpc_argp = &args, |
| 7036 | .rpc_resp = &res, |
| 7037 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7038 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7039 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7040 | |
| 7041 | if (use_integrity) { |
| 7042 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7043 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7044 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7045 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7046 | |
| 7047 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7048 | |
| 7049 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7050 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7051 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7052 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7053 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7054 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7055 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7056 | if (cred) |
| 7057 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7058 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7059 | return status; |
| 7060 | } |
| 7061 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7062 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7063 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7064 | { |
| 7065 | struct nfs4_exception exception = { }; |
| 7066 | int err; |
| 7067 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7068 | err = -NFS4ERR_WRONGSEC; |
| 7069 | |
| 7070 | /* try to use integrity protection with machine cred */ |
| 7071 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7072 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7073 | |
| 7074 | /* |
| 7075 | * if unable to use integrity protection, or SECINFO with |
| 7076 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7077 | * disallowed by spec, but exists in deployed servers) use |
| 7078 | * the current filesystem's rpc_client and the user cred. |
| 7079 | */ |
| 7080 | if (err == -NFS4ERR_WRONGSEC) |
| 7081 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7082 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7083 | trace_nfs4_secinfo(dir, name, err); |
| 7084 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7085 | &exception); |
| 7086 | } while (exception.retry); |
| 7087 | return err; |
| 7088 | } |
| 7089 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7090 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7091 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7092 | * Check the exchange flags returned by the server for invalid flags, having |
| 7093 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7094 | * DS flags set. |
| 7095 | */ |
| 7096 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7097 | { |
| 7098 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7099 | goto out_inval; |
| 7100 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7101 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7102 | goto out_inval; |
| 7103 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7104 | goto out_inval; |
| 7105 | return NFS_OK; |
| 7106 | out_inval: |
| 7107 | return -NFS4ERR_INVAL; |
| 7108 | } |
| 7109 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7110 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7111 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7112 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7113 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7114 | if (a->server_scope_sz != b->server_scope_sz) |
| 7115 | return false; |
| 7116 | 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] | 7117 | } |
| 7118 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7119 | static void |
| 7120 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7121 | { |
| 7122 | } |
| 7123 | |
| 7124 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7125 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7126 | }; |
| 7127 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7128 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7129 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7130 | * |
| 7131 | * The 4.1 client currently uses the same TCP connection for the |
| 7132 | * fore and backchannel. |
| 7133 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7134 | static |
| 7135 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7136 | struct rpc_xprt *xprt, |
| 7137 | struct nfs_client *clp, |
| 7138 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7139 | { |
| 7140 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7141 | struct nfs41_bind_conn_to_session_args args = { |
| 7142 | .client = clp, |
| 7143 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7144 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7145 | struct nfs41_bind_conn_to_session_res res; |
| 7146 | struct rpc_message msg = { |
| 7147 | .rpc_proc = |
| 7148 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7149 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7150 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7151 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7152 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7153 | struct rpc_task_setup task_setup_data = { |
| 7154 | .rpc_client = clnt, |
| 7155 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7156 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7157 | .rpc_message = &msg, |
| 7158 | .flags = RPC_TASK_TIMEOUT, |
| 7159 | }; |
| 7160 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7161 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7162 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7163 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7164 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7165 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7166 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7167 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7168 | args.dir = NFS4_CDFC4_FORE; |
| 7169 | |
| 7170 | task = rpc_run_task(&task_setup_data); |
| 7171 | if (!IS_ERR(task)) { |
| 7172 | status = task->tk_status; |
| 7173 | rpc_put_task(task); |
| 7174 | } else |
| 7175 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7176 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7177 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7178 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7179 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7180 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7181 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7182 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7183 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7184 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7185 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7186 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7187 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7188 | 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] | 7189 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7190 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7191 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7192 | } |
| 7193 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame] | 7194 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7195 | return status; |
| 7196 | } |
| 7197 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7198 | struct rpc_bind_conn_calldata { |
| 7199 | struct nfs_client *clp; |
| 7200 | struct rpc_cred *cred; |
| 7201 | }; |
| 7202 | |
| 7203 | static int |
| 7204 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7205 | struct rpc_xprt *xprt, |
| 7206 | void *calldata) |
| 7207 | { |
| 7208 | struct rpc_bind_conn_calldata *p = calldata; |
| 7209 | |
| 7210 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7211 | } |
| 7212 | |
| 7213 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7214 | { |
| 7215 | struct rpc_bind_conn_calldata data = { |
| 7216 | .clp = clp, |
| 7217 | .cred = cred, |
| 7218 | }; |
| 7219 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7220 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7221 | } |
| 7222 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7223 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7224 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7225 | * 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] | 7226 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7227 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7228 | .how = SP4_MACH_CRED, |
| 7229 | .enforce.u.words = { |
| 7230 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7231 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7232 | 1 << (OP_CREATE_SESSION - 32) | |
| 7233 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7234 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7235 | }, |
| 7236 | .allow.u.words = { |
| 7237 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7238 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7239 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7240 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7241 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7242 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7243 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7244 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7245 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7246 | 1 << (OP_FREE_STATEID - 32) | |
| 7247 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7248 | } |
| 7249 | }; |
| 7250 | |
| 7251 | /* |
| 7252 | * Select the state protection mode for client `clp' given the server results |
| 7253 | * from exchange_id in `sp'. |
| 7254 | * |
| 7255 | * Returns 0 on success, negative errno otherwise. |
| 7256 | */ |
| 7257 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7258 | struct nfs41_state_protection *sp) |
| 7259 | { |
| 7260 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7261 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7262 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7263 | 1 << (OP_CREATE_SESSION - 32) | |
| 7264 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7265 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7266 | }; |
| 7267 | unsigned int i; |
| 7268 | |
| 7269 | if (sp->how == SP4_MACH_CRED) { |
| 7270 | /* Print state protect result */ |
| 7271 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7272 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7273 | if (test_bit(i, sp->enforce.u.longs)) |
| 7274 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7275 | if (test_bit(i, sp->allow.u.longs)) |
| 7276 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7277 | } |
| 7278 | |
| 7279 | /* make sure nothing is on enforce list that isn't supported */ |
| 7280 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7281 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7282 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7283 | return -EINVAL; |
| 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | /* |
| 7288 | * Minimal mode - state operations are allowed to use machine |
| 7289 | * credential. Note this already happens by default, so the |
| 7290 | * client doesn't have to do anything more than the negotiation. |
| 7291 | * |
| 7292 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7293 | * we're already using the machine cred for exchange_id |
| 7294 | * and will never use a different cred. |
| 7295 | */ |
| 7296 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7297 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7298 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7299 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7300 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7301 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7302 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7303 | } else { |
| 7304 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7305 | return -EINVAL; |
| 7306 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7307 | |
| 7308 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7309 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7310 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7311 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7312 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7313 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7314 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7315 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7316 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7317 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7318 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7319 | &clp->cl_sp4_flags); |
| 7320 | } |
| 7321 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7322 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7323 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7324 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7325 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7326 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7327 | |
| 7328 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7329 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7330 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7331 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7332 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7333 | |
| 7334 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7335 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7336 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7337 | } |
| 7338 | |
| 7339 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7340 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7341 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7342 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | return 0; |
| 7346 | } |
| 7347 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7348 | struct nfs41_exchange_id_data { |
| 7349 | struct nfs41_exchange_id_res res; |
| 7350 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7351 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7352 | int rpc_status; |
| 7353 | }; |
| 7354 | |
| 7355 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7356 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7357 | struct nfs41_exchange_id_data *cdata = |
| 7358 | (struct nfs41_exchange_id_data *)data; |
| 7359 | struct nfs_client *clp = cdata->args.client; |
| 7360 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7361 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7362 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7363 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7364 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7365 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7366 | |
| 7367 | if (cdata->xprt && status == 0) { |
| 7368 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7369 | cdata->xprt); |
| 7370 | goto out; |
| 7371 | } |
| 7372 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7373 | if (status == 0) |
| 7374 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7375 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7376 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7377 | clp->cl_clientid = cdata->res.clientid; |
| 7378 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7379 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7380 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7381 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7382 | &clp->cl_session->session_state); |
| 7383 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7384 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7385 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7386 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7387 | clp->cl_serverowner = cdata->res.server_owner; |
| 7388 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7389 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7390 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7391 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7392 | clp->cl_implid = cdata->res.impl_id; |
| 7393 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7394 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7395 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7396 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7397 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7398 | dprintk("%s: server_scope mismatch detected\n", |
| 7399 | __func__); |
| 7400 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7401 | kfree(clp->cl_serverscope); |
| 7402 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7403 | } |
| 7404 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7405 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7406 | clp->cl_serverscope = cdata->res.server_scope; |
| 7407 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7408 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7409 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7410 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7411 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7412 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7413 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7414 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7415 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | static void nfs4_exchange_id_release(void *data) |
| 7419 | { |
| 7420 | struct nfs41_exchange_id_data *cdata = |
| 7421 | (struct nfs41_exchange_id_data *)data; |
| 7422 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7423 | if (cdata->xprt) { |
| 7424 | xprt_put(cdata->xprt); |
| 7425 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7426 | } |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7427 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7428 | kfree(cdata->res.impl_id); |
| 7429 | kfree(cdata->res.server_scope); |
| 7430 | kfree(cdata->res.server_owner); |
| 7431 | kfree(cdata); |
| 7432 | } |
| 7433 | |
| 7434 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7435 | .rpc_call_done = nfs4_exchange_id_done, |
| 7436 | .rpc_release = nfs4_exchange_id_release, |
| 7437 | }; |
| 7438 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7439 | /* |
| 7440 | * _nfs4_proc_exchange_id() |
| 7441 | * |
| 7442 | * Wrapper for EXCHANGE_ID operation. |
| 7443 | */ |
| 7444 | static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7445 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7446 | { |
| 7447 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7448 | struct rpc_message msg = { |
| 7449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7450 | .rpc_cred = cred, |
| 7451 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7452 | struct rpc_task_setup task_setup_data = { |
| 7453 | .rpc_client = clp->cl_rpcclient, |
| 7454 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7455 | .rpc_message = &msg, |
| 7456 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7457 | }; |
| 7458 | struct nfs41_exchange_id_data *calldata; |
| 7459 | struct rpc_task *task; |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7460 | int status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7461 | |
| 7462 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7463 | return -EIO; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7464 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7465 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7466 | if (!calldata) { |
| 7467 | nfs_put_client(clp); |
Anna Schumaker | e917f0d | 2017-04-07 14:15:22 -0400 | [diff] [blame] | 7468 | return -ENOMEM; |
Dave Wysochanski | 5c737cb | 2017-04-27 10:45:15 -0400 | [diff] [blame] | 7469 | } |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7470 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7471 | if (!xprt) |
| 7472 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7473 | |
| 7474 | status = nfs4_init_uniform_client_string(clp); |
| 7475 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7476 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7477 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7478 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7479 | GFP_NOFS); |
| 7480 | status = -ENOMEM; |
| 7481 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7482 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7483 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7484 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7485 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7486 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7487 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7488 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7489 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7490 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7491 | goto out_server_scope; |
| 7492 | |
| 7493 | switch (sp4_how) { |
| 7494 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7495 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7496 | break; |
| 7497 | |
| 7498 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7499 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7500 | break; |
| 7501 | |
| 7502 | default: |
| 7503 | /* unsupported! */ |
| 7504 | WARN_ON_ONCE(1); |
| 7505 | status = -EINVAL; |
| 7506 | goto out_impl_id; |
| 7507 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7508 | if (xprt) { |
| 7509 | calldata->xprt = xprt; |
| 7510 | task_setup_data.rpc_xprt = xprt; |
| 7511 | task_setup_data.flags = |
| 7512 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7513 | calldata->args.verifier = &clp->cl_confirm; |
| 7514 | } else { |
| 7515 | calldata->args.verifier = &verifier; |
| 7516 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7517 | calldata->args.client = clp; |
| 7518 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7519 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7520 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7521 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7522 | #else |
| 7523 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7524 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7525 | #endif |
| 7526 | msg.rpc_argp = &calldata->args; |
| 7527 | msg.rpc_resp = &calldata->res; |
| 7528 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7529 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7530 | task = rpc_run_task(&task_setup_data); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7531 | if (IS_ERR(task)) |
| 7532 | return PTR_ERR(task); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7533 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7534 | if (!xprt) { |
| 7535 | status = rpc_wait_for_completion_task(task); |
| 7536 | if (!status) |
| 7537 | status = calldata->rpc_status; |
| 7538 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7539 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7540 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7541 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7542 | out: |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7543 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7544 | |
| 7545 | out_impl_id: |
| 7546 | kfree(calldata->res.impl_id); |
| 7547 | out_server_scope: |
| 7548 | kfree(calldata->res.server_scope); |
| 7549 | out_server_owner: |
| 7550 | kfree(calldata->res.server_owner); |
| 7551 | out_calldata: |
| 7552 | kfree(calldata); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7553 | nfs_put_client(clp); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7554 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7555 | } |
| 7556 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7557 | /* |
| 7558 | * nfs4_proc_exchange_id() |
| 7559 | * |
| 7560 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7561 | * |
| 7562 | * Since the clientid has expired, all compounds using sessions |
| 7563 | * associated with the stale clientid will be returning |
| 7564 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7565 | * be in some phase of session reset. |
| 7566 | * |
| 7567 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7568 | */ |
| 7569 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7570 | { |
| 7571 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7572 | int status; |
| 7573 | |
| 7574 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7575 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7576 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7577 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7578 | if (!status) |
| 7579 | return 0; |
| 7580 | } |
| 7581 | |
| 7582 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7583 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7584 | } |
| 7585 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7586 | /** |
| 7587 | * nfs4_test_session_trunk |
| 7588 | * |
| 7589 | * This is an add_xprt_test() test function called from |
| 7590 | * rpc_clnt_setup_test_and_add_xprt. |
| 7591 | * |
| 7592 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7593 | * and is dereferrenced in nfs4_exchange_id_release |
| 7594 | * |
| 7595 | * Upon success, add the new transport to the rpc_clnt |
| 7596 | * |
| 7597 | * @clnt: struct rpc_clnt to get new transport |
| 7598 | * @xprt: the rpc_xprt to test |
| 7599 | * @data: call data for _nfs4_proc_exchange_id. |
| 7600 | */ |
| 7601 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7602 | void *data) |
| 7603 | { |
| 7604 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7605 | u32 sp4_how; |
| 7606 | |
| 7607 | dprintk("--> %s try %s\n", __func__, |
| 7608 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7609 | |
| 7610 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7611 | |
| 7612 | /* Test connection for session trunking. Async exchange_id call */ |
| 7613 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7614 | } |
| 7615 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7616 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7617 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7618 | struct rpc_cred *cred) |
| 7619 | { |
| 7620 | struct rpc_message msg = { |
| 7621 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7622 | .rpc_argp = clp, |
| 7623 | .rpc_cred = cred, |
| 7624 | }; |
| 7625 | int status; |
| 7626 | |
| 7627 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7628 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7629 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7630 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7631 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7632 | return status; |
| 7633 | } |
| 7634 | |
| 7635 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7636 | struct rpc_cred *cred) |
| 7637 | { |
| 7638 | unsigned int loop; |
| 7639 | int ret; |
| 7640 | |
| 7641 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7642 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7643 | switch (ret) { |
| 7644 | case -NFS4ERR_DELAY: |
| 7645 | case -NFS4ERR_CLIENTID_BUSY: |
| 7646 | ssleep(1); |
| 7647 | break; |
| 7648 | default: |
| 7649 | return ret; |
| 7650 | } |
| 7651 | } |
| 7652 | return 0; |
| 7653 | } |
| 7654 | |
| 7655 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7656 | { |
| 7657 | struct rpc_cred *cred; |
| 7658 | int ret = 0; |
| 7659 | |
| 7660 | if (clp->cl_mvops->minor_version < 1) |
| 7661 | goto out; |
| 7662 | if (clp->cl_exchange_flags == 0) |
| 7663 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7664 | if (clp->cl_preserve_clid) |
| 7665 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7666 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7667 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7668 | if (cred) |
| 7669 | put_rpccred(cred); |
| 7670 | switch (ret) { |
| 7671 | case 0: |
| 7672 | case -NFS4ERR_STALE_CLIENTID: |
| 7673 | clp->cl_exchange_flags = 0; |
| 7674 | } |
| 7675 | out: |
| 7676 | return ret; |
| 7677 | } |
| 7678 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7679 | struct nfs4_get_lease_time_data { |
| 7680 | struct nfs4_get_lease_time_args *args; |
| 7681 | struct nfs4_get_lease_time_res *res; |
| 7682 | struct nfs_client *clp; |
| 7683 | }; |
| 7684 | |
| 7685 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7686 | void *calldata) |
| 7687 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7688 | struct nfs4_get_lease_time_data *data = |
| 7689 | (struct nfs4_get_lease_time_data *)calldata; |
| 7690 | |
| 7691 | dprintk("--> %s\n", __func__); |
| 7692 | /* just setup sequence, do not trigger session recovery |
| 7693 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7694 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7695 | &data->args->la_seq_args, |
| 7696 | &data->res->lr_seq_res, |
| 7697 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7698 | dprintk("<-- %s\n", __func__); |
| 7699 | } |
| 7700 | |
| 7701 | /* |
| 7702 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7703 | * from sequence operation or clientid errors. |
| 7704 | */ |
| 7705 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7706 | { |
| 7707 | struct nfs4_get_lease_time_data *data = |
| 7708 | (struct nfs4_get_lease_time_data *)calldata; |
| 7709 | |
| 7710 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7711 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7712 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7713 | switch (task->tk_status) { |
| 7714 | case -NFS4ERR_DELAY: |
| 7715 | case -NFS4ERR_GRACE: |
| 7716 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7717 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7718 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7719 | /* fall through */ |
| 7720 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7721 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7722 | return; |
| 7723 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7724 | dprintk("<-- %s\n", __func__); |
| 7725 | } |
| 7726 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7727 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7728 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7729 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7730 | }; |
| 7731 | |
| 7732 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7733 | { |
| 7734 | struct rpc_task *task; |
| 7735 | struct nfs4_get_lease_time_args args; |
| 7736 | struct nfs4_get_lease_time_res res = { |
| 7737 | .lr_fsinfo = fsinfo, |
| 7738 | }; |
| 7739 | struct nfs4_get_lease_time_data data = { |
| 7740 | .args = &args, |
| 7741 | .res = &res, |
| 7742 | .clp = clp, |
| 7743 | }; |
| 7744 | struct rpc_message msg = { |
| 7745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7746 | .rpc_argp = &args, |
| 7747 | .rpc_resp = &res, |
| 7748 | }; |
| 7749 | struct rpc_task_setup task_setup = { |
| 7750 | .rpc_client = clp->cl_rpcclient, |
| 7751 | .rpc_message = &msg, |
| 7752 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7753 | .callback_data = &data, |
| 7754 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7755 | }; |
| 7756 | int status; |
| 7757 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7758 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7759 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7760 | task = rpc_run_task(&task_setup); |
| 7761 | |
| 7762 | if (IS_ERR(task)) |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7763 | return PTR_ERR(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7764 | |
Anna Schumaker | f614871 | 2017-04-07 14:15:23 -0400 | [diff] [blame] | 7765 | status = task->tk_status; |
| 7766 | rpc_put_task(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7767 | return status; |
| 7768 | } |
| 7769 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7770 | /* |
| 7771 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7772 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7773 | * use them. |
| 7774 | * |
| 7775 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7776 | * always set csa_cachethis to FALSE because the current implementation |
| 7777 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7778 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7779 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7780 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7781 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7782 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7783 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7784 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7785 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7786 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7787 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7788 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7789 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7790 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7791 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7792 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7793 | |
| 7794 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7795 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7796 | __func__, |
| 7797 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7798 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7799 | |
| 7800 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7801 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7802 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7803 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7804 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7805 | 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] | 7806 | |
| 7807 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7808 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7809 | __func__, |
| 7810 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7811 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7812 | args->bc_attrs.max_reqs); |
| 7813 | } |
| 7814 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7815 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7816 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7817 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7818 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7819 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7820 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7821 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7822 | return -EINVAL; |
| 7823 | /* |
| 7824 | * Our requested max_ops is the minimum we need; we're not |
| 7825 | * prepared to break up compounds into smaller pieces than that. |
| 7826 | * So, no point even trying to continue if the server won't |
| 7827 | * cooperate: |
| 7828 | */ |
| 7829 | if (rcvd->max_ops < sent->max_ops) |
| 7830 | return -EINVAL; |
| 7831 | if (rcvd->max_reqs == 0) |
| 7832 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7833 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7834 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7835 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7836 | } |
| 7837 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7838 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7839 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7840 | { |
| 7841 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7842 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7843 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7844 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7845 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7846 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7847 | return -EINVAL; |
| 7848 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7849 | return -EINVAL; |
| 7850 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7851 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7852 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7853 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7854 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7855 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7856 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7857 | return 0; |
| 7858 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7859 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7860 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7861 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7862 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7863 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7864 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7865 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7866 | if (ret) |
| 7867 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7868 | return nfs4_verify_back_channel_attrs(args, res); |
| 7869 | } |
| 7870 | |
| 7871 | static void nfs4_update_session(struct nfs4_session *session, |
| 7872 | struct nfs41_create_session_res *res) |
| 7873 | { |
| 7874 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7875 | /* Mark client id and session as being confirmed */ |
| 7876 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7877 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7878 | session->flags = res->flags; |
| 7879 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7880 | if (res->flags & SESSION4_BACK_CHAN) |
| 7881 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7882 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7883 | } |
| 7884 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7885 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7886 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7887 | { |
| 7888 | struct nfs4_session *session = clp->cl_session; |
| 7889 | struct nfs41_create_session_args args = { |
| 7890 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7891 | .clientid = clp->cl_clientid, |
| 7892 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7893 | .cb_program = NFS4_CALLBACK, |
| 7894 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7895 | struct nfs41_create_session_res res; |
| 7896 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7897 | struct rpc_message msg = { |
| 7898 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7899 | .rpc_argp = &args, |
| 7900 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7901 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7902 | }; |
| 7903 | int status; |
| 7904 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7905 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7906 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7907 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7908 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7909 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7910 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7911 | switch (status) { |
| 7912 | case -NFS4ERR_STALE_CLIENTID: |
| 7913 | case -NFS4ERR_DELAY: |
| 7914 | case -ETIMEDOUT: |
| 7915 | case -EACCES: |
| 7916 | case -EAGAIN: |
| 7917 | goto out; |
| 7918 | }; |
| 7919 | |
| 7920 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7921 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7922 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7923 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7924 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7925 | if (status) |
| 7926 | goto out; |
| 7927 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7928 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7929 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7930 | return status; |
| 7931 | } |
| 7932 | |
| 7933 | /* |
| 7934 | * Issues a CREATE_SESSION operation to the server. |
| 7935 | * It is the responsibility of the caller to verify the session is |
| 7936 | * expired before calling this routine. |
| 7937 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7938 | 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] | 7939 | { |
| 7940 | int status; |
| 7941 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7942 | struct nfs4_session *session = clp->cl_session; |
| 7943 | |
| 7944 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7945 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7946 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7947 | if (status) |
| 7948 | goto out; |
| 7949 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7950 | /* Init or reset the session slot tables */ |
| 7951 | status = nfs4_setup_session_slot_tables(session); |
| 7952 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7953 | if (status) |
| 7954 | goto out; |
| 7955 | |
| 7956 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7957 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7958 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7959 | out: |
| 7960 | dprintk("<-- %s\n", __func__); |
| 7961 | return status; |
| 7962 | } |
| 7963 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7964 | /* |
| 7965 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7966 | * The caller must serialize access to this routine. |
| 7967 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7968 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7969 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7970 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7971 | struct rpc_message msg = { |
| 7972 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7973 | .rpc_argp = session, |
| 7974 | .rpc_cred = cred, |
| 7975 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7976 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7977 | |
| 7978 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7979 | |
| 7980 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7981 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7982 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7983 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7984 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7985 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7986 | |
| 7987 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7988 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7989 | "Session has been destroyed regardless...\n", status); |
| 7990 | |
| 7991 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7992 | return status; |
| 7993 | } |
| 7994 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7995 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7996 | * Renew the cl_session lease. |
| 7997 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7998 | struct nfs4_sequence_data { |
| 7999 | struct nfs_client *clp; |
| 8000 | struct nfs4_sequence_args args; |
| 8001 | struct nfs4_sequence_res res; |
| 8002 | }; |
| 8003 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8004 | static void nfs41_sequence_release(void *data) |
| 8005 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8006 | struct nfs4_sequence_data *calldata = data; |
| 8007 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8008 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8009 | if (atomic_read(&clp->cl_count) > 1) |
| 8010 | nfs4_schedule_state_renewal(clp); |
| 8011 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8012 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8013 | } |
| 8014 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8015 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8016 | { |
| 8017 | switch(task->tk_status) { |
| 8018 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8019 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8020 | return -EAGAIN; |
| 8021 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8022 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8023 | } |
| 8024 | return 0; |
| 8025 | } |
| 8026 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8027 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8028 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8029 | struct nfs4_sequence_data *calldata = data; |
| 8030 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8031 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8032 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8033 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8034 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8035 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8036 | if (task->tk_status < 0) { |
| 8037 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8038 | if (atomic_read(&clp->cl_count) == 1) |
| 8039 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8040 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8041 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8042 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8043 | return; |
| 8044 | } |
| 8045 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8046 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8047 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8048 | dprintk("<-- %s\n", __func__); |
| 8049 | } |
| 8050 | |
| 8051 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8052 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8053 | struct nfs4_sequence_data *calldata = data; |
| 8054 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8055 | struct nfs4_sequence_args *args; |
| 8056 | struct nfs4_sequence_res *res; |
| 8057 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8058 | args = task->tk_msg.rpc_argp; |
| 8059 | res = task->tk_msg.rpc_resp; |
| 8060 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8061 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8062 | } |
| 8063 | |
| 8064 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8065 | .rpc_call_done = nfs41_sequence_call_done, |
| 8066 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8067 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8068 | }; |
| 8069 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8070 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8071 | struct rpc_cred *cred, |
| 8072 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8073 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8074 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8075 | struct rpc_message msg = { |
| 8076 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8077 | .rpc_cred = cred, |
| 8078 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8079 | struct rpc_task_setup task_setup_data = { |
| 8080 | .rpc_client = clp->cl_rpcclient, |
| 8081 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8082 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8083 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8084 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8085 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8086 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8087 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8088 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8089 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8090 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8091 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8092 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8093 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8094 | if (is_privileged) |
| 8095 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8096 | msg.rpc_argp = &calldata->args; |
| 8097 | msg.rpc_resp = &calldata->res; |
| 8098 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8099 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8100 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8101 | return rpc_run_task(&task_setup_data); |
| 8102 | } |
| 8103 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8104 | 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] | 8105 | { |
| 8106 | struct rpc_task *task; |
| 8107 | int ret = 0; |
| 8108 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8109 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8110 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8111 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8112 | if (IS_ERR(task)) |
| 8113 | ret = PTR_ERR(task); |
| 8114 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8115 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8116 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8117 | return ret; |
| 8118 | } |
| 8119 | |
| 8120 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8121 | { |
| 8122 | struct rpc_task *task; |
| 8123 | int ret; |
| 8124 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8125 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8126 | if (IS_ERR(task)) { |
| 8127 | ret = PTR_ERR(task); |
| 8128 | goto out; |
| 8129 | } |
| 8130 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8131 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8132 | ret = task->tk_status; |
| 8133 | rpc_put_task(task); |
| 8134 | out: |
| 8135 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8136 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8137 | } |
| 8138 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8139 | struct nfs4_reclaim_complete_data { |
| 8140 | struct nfs_client *clp; |
| 8141 | struct nfs41_reclaim_complete_args arg; |
| 8142 | struct nfs41_reclaim_complete_res res; |
| 8143 | }; |
| 8144 | |
| 8145 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8146 | { |
| 8147 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8148 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8149 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8150 | &calldata->arg.seq_args, |
| 8151 | &calldata->res.seq_res, |
| 8152 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8153 | } |
| 8154 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8155 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8156 | { |
| 8157 | switch(task->tk_status) { |
| 8158 | case 0: |
| 8159 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8160 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8161 | break; |
| 8162 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8163 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8164 | /* fall through */ |
| 8165 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8166 | return -EAGAIN; |
Trond Myklebust | 0048fdd | 2017-05-04 13:44:04 -0400 | [diff] [blame] | 8167 | case -NFS4ERR_BADSESSION: |
| 8168 | case -NFS4ERR_DEADSESSION: |
| 8169 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8170 | nfs4_schedule_session_recovery(clp->cl_session, |
| 8171 | task->tk_status); |
| 8172 | break; |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8173 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8174 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8175 | } |
| 8176 | return 0; |
| 8177 | } |
| 8178 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8179 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8180 | { |
| 8181 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8182 | struct nfs_client *clp = calldata->clp; |
| 8183 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8184 | |
| 8185 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8186 | if (!nfs41_sequence_done(task, res)) |
| 8187 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8188 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8189 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8190 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8191 | rpc_restart_call_prepare(task); |
| 8192 | return; |
| 8193 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8194 | dprintk("<-- %s\n", __func__); |
| 8195 | } |
| 8196 | |
| 8197 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8198 | { |
| 8199 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8200 | |
| 8201 | kfree(calldata); |
| 8202 | } |
| 8203 | |
| 8204 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8205 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8206 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8207 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8208 | }; |
| 8209 | |
| 8210 | /* |
| 8211 | * Issue a global reclaim complete. |
| 8212 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8213 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8214 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8215 | { |
| 8216 | struct nfs4_reclaim_complete_data *calldata; |
| 8217 | struct rpc_task *task; |
| 8218 | struct rpc_message msg = { |
| 8219 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8220 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8221 | }; |
| 8222 | struct rpc_task_setup task_setup_data = { |
| 8223 | .rpc_client = clp->cl_rpcclient, |
| 8224 | .rpc_message = &msg, |
| 8225 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8226 | .flags = RPC_TASK_ASYNC, |
| 8227 | }; |
| 8228 | int status = -ENOMEM; |
| 8229 | |
| 8230 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8231 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8232 | if (calldata == NULL) |
| 8233 | goto out; |
| 8234 | calldata->clp = clp; |
| 8235 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8236 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8237 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8238 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8239 | msg.rpc_argp = &calldata->arg; |
| 8240 | msg.rpc_resp = &calldata->res; |
| 8241 | task_setup_data.callback_data = calldata; |
| 8242 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8243 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8244 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8245 | goto out; |
| 8246 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8247 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8248 | if (status == 0) |
| 8249 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8250 | rpc_put_task(task); |
| 8251 | out: |
| 8252 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8253 | return status; |
| 8254 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8255 | |
| 8256 | static void |
| 8257 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8258 | { |
| 8259 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8260 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8261 | |
| 8262 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8263 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8264 | &lgp->res.seq_res, task); |
| 8265 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8266 | } |
| 8267 | |
| 8268 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8269 | { |
| 8270 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8271 | |
| 8272 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8273 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8274 | dprintk("<-- %s\n", __func__); |
| 8275 | } |
| 8276 | |
| 8277 | static int |
| 8278 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8279 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8280 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8281 | struct inode *inode = lgp->args.inode; |
| 8282 | struct nfs_server *server = NFS_SERVER(inode); |
| 8283 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8284 | int nfs4err = task->tk_status; |
| 8285 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8286 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8287 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8288 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8289 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8290 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8291 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8292 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8293 | |
| 8294 | /* |
| 8295 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8296 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8297 | * retry go inband. |
| 8298 | */ |
| 8299 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8300 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8301 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8302 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8303 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8304 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8305 | */ |
| 8306 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8307 | status = -EOVERFLOW; |
| 8308 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8309 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8310 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8311 | * (or clients) writing to the same RAID stripe except when |
| 8312 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8313 | * |
| 8314 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8315 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8316 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8317 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8318 | if (lgp->args.minlength == 0) { |
| 8319 | status = -EOVERFLOW; |
| 8320 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8321 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8322 | status = -EBUSY; |
| 8323 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8324 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8325 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8326 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8327 | case -NFS4ERR_DELEG_REVOKED: |
| 8328 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8329 | case -NFS4ERR_EXPIRED: |
| 8330 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8331 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8332 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8333 | lo = NFS_I(inode)->layout; |
| 8334 | /* If the open stateid was bad, then recover it. */ |
| 8335 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8336 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8337 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8338 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8339 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8340 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8341 | break; |
| 8342 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8343 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8344 | /* |
| 8345 | * Mark the bad layout state as invalid, then retry |
| 8346 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8347 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8348 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 8349 | nfs_commit_inode(inode, 0); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8350 | pnfs_free_lseg_list(&head); |
| 8351 | status = -EAGAIN; |
| 8352 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8353 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8354 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8355 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8356 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8357 | if (!status) { |
| 8358 | if (exception->retry) |
| 8359 | status = -EAGAIN; |
| 8360 | else |
| 8361 | status = err; |
| 8362 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8363 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8364 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8365 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8366 | } |
| 8367 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8368 | static size_t max_response_pages(struct nfs_server *server) |
| 8369 | { |
| 8370 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8371 | return nfs_page_array_len(0, max_resp_sz); |
| 8372 | } |
| 8373 | |
| 8374 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8375 | { |
| 8376 | int i; |
| 8377 | |
| 8378 | if (!pages) |
| 8379 | return; |
| 8380 | |
| 8381 | for (i = 0; i < size; i++) { |
| 8382 | if (!pages[i]) |
| 8383 | break; |
| 8384 | __free_page(pages[i]); |
| 8385 | } |
| 8386 | kfree(pages); |
| 8387 | } |
| 8388 | |
| 8389 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8390 | { |
| 8391 | struct page **pages; |
| 8392 | int i; |
| 8393 | |
| 8394 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8395 | if (!pages) { |
| 8396 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8397 | return NULL; |
| 8398 | } |
| 8399 | |
| 8400 | for (i = 0; i < size; i++) { |
| 8401 | pages[i] = alloc_page(gfp_flags); |
| 8402 | if (!pages[i]) { |
| 8403 | dprintk("%s: failed to allocate page\n", __func__); |
| 8404 | nfs4_free_pages(pages, size); |
| 8405 | return NULL; |
| 8406 | } |
| 8407 | } |
| 8408 | |
| 8409 | return pages; |
| 8410 | } |
| 8411 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8412 | static void nfs4_layoutget_release(void *calldata) |
| 8413 | { |
| 8414 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8415 | struct inode *inode = lgp->args.inode; |
| 8416 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8417 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8418 | |
| 8419 | dprintk("--> %s\n", __func__); |
Trond Myklebust | bd17193 | 2017-06-27 17:33:38 -0400 | [diff] [blame^] | 8420 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8421 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8422 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8423 | put_nfs_open_context(lgp->args.ctx); |
| 8424 | kfree(calldata); |
| 8425 | dprintk("<-- %s\n", __func__); |
| 8426 | } |
| 8427 | |
| 8428 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8429 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8430 | .rpc_call_done = nfs4_layoutget_done, |
| 8431 | .rpc_release = nfs4_layoutget_release, |
| 8432 | }; |
| 8433 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8434 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8435 | 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] | 8436 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8437 | struct inode *inode = lgp->args.inode; |
| 8438 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8439 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8440 | struct rpc_task *task; |
| 8441 | struct rpc_message msg = { |
| 8442 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8443 | .rpc_argp = &lgp->args, |
| 8444 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8445 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8446 | }; |
| 8447 | struct rpc_task_setup task_setup_data = { |
| 8448 | .rpc_client = server->client, |
| 8449 | .rpc_message = &msg, |
| 8450 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8451 | .callback_data = lgp, |
| 8452 | .flags = RPC_TASK_ASYNC, |
| 8453 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8454 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8455 | struct nfs4_exception exception = { |
| 8456 | .inode = inode, |
| 8457 | .timeout = *timeout, |
| 8458 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8459 | int status = 0; |
| 8460 | |
| 8461 | dprintk("--> %s\n", __func__); |
| 8462 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8463 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8464 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8465 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8466 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8467 | if (!lgp->args.layout.pages) { |
| 8468 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8469 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8470 | } |
| 8471 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8472 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8473 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8474 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8475 | 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] | 8476 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8477 | task = rpc_run_task(&task_setup_data); |
| 8478 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8479 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8480 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8481 | if (status == 0) { |
| 8482 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8483 | *timeout = exception.timeout; |
| 8484 | } |
| 8485 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8486 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8487 | &lgp->args.range, |
| 8488 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8489 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8490 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8491 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8492 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8493 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8494 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8495 | rpc_put_task(task); |
| 8496 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8497 | if (status) |
| 8498 | return ERR_PTR(status); |
| 8499 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8500 | } |
| 8501 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8502 | static void |
| 8503 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8504 | { |
| 8505 | struct nfs4_layoutreturn *lrp = calldata; |
| 8506 | |
| 8507 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8508 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8509 | &lrp->args.seq_args, |
| 8510 | &lrp->res.seq_res, |
| 8511 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8515 | { |
| 8516 | struct nfs4_layoutreturn *lrp = calldata; |
| 8517 | struct nfs_server *server; |
| 8518 | |
| 8519 | dprintk("--> %s\n", __func__); |
| 8520 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8521 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8522 | return; |
| 8523 | |
| 8524 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8525 | switch (task->tk_status) { |
| 8526 | default: |
| 8527 | task->tk_status = 0; |
| 8528 | case 0: |
| 8529 | break; |
| 8530 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8531 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8532 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8533 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8534 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8535 | return; |
| 8536 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8537 | dprintk("<-- %s\n", __func__); |
| 8538 | } |
| 8539 | |
| 8540 | static void nfs4_layoutreturn_release(void *calldata) |
| 8541 | { |
| 8542 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8543 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8544 | |
| 8545 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8546 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8547 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8548 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8549 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8550 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8551 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8552 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8553 | kfree(calldata); |
| 8554 | dprintk("<-- %s\n", __func__); |
| 8555 | } |
| 8556 | |
| 8557 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8558 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8559 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8560 | .rpc_release = nfs4_layoutreturn_release, |
| 8561 | }; |
| 8562 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8563 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8564 | { |
| 8565 | struct rpc_task *task; |
| 8566 | struct rpc_message msg = { |
| 8567 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8568 | .rpc_argp = &lrp->args, |
| 8569 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8570 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8571 | }; |
| 8572 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8573 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8574 | .rpc_message = &msg, |
| 8575 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8576 | .callback_data = lrp, |
| 8577 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8578 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8579 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8580 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8581 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8582 | &task_setup_data.rpc_client, &msg); |
| 8583 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8584 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8585 | if (!sync) { |
| 8586 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8587 | if (!lrp->inode) { |
| 8588 | nfs4_layoutreturn_release(lrp); |
| 8589 | return -EAGAIN; |
| 8590 | } |
| 8591 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8592 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8593 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8594 | task = rpc_run_task(&task_setup_data); |
| 8595 | if (IS_ERR(task)) |
| 8596 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8597 | if (sync) |
| 8598 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8599 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8600 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8601 | rpc_put_task(task); |
| 8602 | return status; |
| 8603 | } |
| 8604 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8605 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8606 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8607 | struct pnfs_device *pdev, |
| 8608 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8609 | { |
| 8610 | struct nfs4_getdeviceinfo_args args = { |
| 8611 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8612 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8613 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8614 | }; |
| 8615 | struct nfs4_getdeviceinfo_res res = { |
| 8616 | .pdev = pdev, |
| 8617 | }; |
| 8618 | struct rpc_message msg = { |
| 8619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8620 | .rpc_argp = &args, |
| 8621 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8622 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8623 | }; |
| 8624 | int status; |
| 8625 | |
| 8626 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8627 | 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] | 8628 | if (res.notification & ~args.notify_types) |
| 8629 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8630 | if (res.notification != args.notify_types) |
| 8631 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8632 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8633 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8634 | |
| 8635 | return status; |
| 8636 | } |
| 8637 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8638 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8639 | struct pnfs_device *pdev, |
| 8640 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8641 | { |
| 8642 | struct nfs4_exception exception = { }; |
| 8643 | int err; |
| 8644 | |
| 8645 | do { |
| 8646 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8647 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8648 | &exception); |
| 8649 | } while (exception.retry); |
| 8650 | return err; |
| 8651 | } |
| 8652 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8653 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8654 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8655 | { |
| 8656 | struct nfs4_layoutcommit_data *data = calldata; |
| 8657 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8658 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8659 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8660 | &data->args.seq_args, |
| 8661 | &data->res.seq_res, |
| 8662 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8663 | } |
| 8664 | |
| 8665 | static void |
| 8666 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8667 | { |
| 8668 | struct nfs4_layoutcommit_data *data = calldata; |
| 8669 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8670 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8671 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8672 | return; |
| 8673 | |
| 8674 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8675 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8676 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8677 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8678 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8679 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8680 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8681 | break; |
| 8682 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8683 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8684 | rpc_restart_call_prepare(task); |
| 8685 | return; |
| 8686 | } |
| 8687 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8688 | } |
| 8689 | |
| 8690 | static void nfs4_layoutcommit_release(void *calldata) |
| 8691 | { |
| 8692 | struct nfs4_layoutcommit_data *data = calldata; |
| 8693 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8694 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8695 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8696 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8697 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8698 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8699 | kfree(data); |
| 8700 | } |
| 8701 | |
| 8702 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8703 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8704 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8705 | .rpc_release = nfs4_layoutcommit_release, |
| 8706 | }; |
| 8707 | |
| 8708 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8709 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8710 | { |
| 8711 | struct rpc_message msg = { |
| 8712 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8713 | .rpc_argp = &data->args, |
| 8714 | .rpc_resp = &data->res, |
| 8715 | .rpc_cred = data->cred, |
| 8716 | }; |
| 8717 | struct rpc_task_setup task_setup_data = { |
| 8718 | .task = &data->task, |
| 8719 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8720 | .rpc_message = &msg, |
| 8721 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8722 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8723 | }; |
| 8724 | struct rpc_task *task; |
| 8725 | int status = 0; |
| 8726 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8727 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8728 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8729 | data->args.lastbytewritten, |
| 8730 | data->args.inode->i_ino); |
| 8731 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8732 | if (!sync) { |
| 8733 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8734 | if (data->inode == NULL) { |
| 8735 | nfs4_layoutcommit_release(data); |
| 8736 | return -EAGAIN; |
| 8737 | } |
| 8738 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8739 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8740 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8741 | task = rpc_run_task(&task_setup_data); |
| 8742 | if (IS_ERR(task)) |
| 8743 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8744 | if (sync) |
| 8745 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8746 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8747 | dprintk("%s: status %d\n", __func__, status); |
| 8748 | rpc_put_task(task); |
| 8749 | return status; |
| 8750 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8751 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8752 | /** |
| 8753 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8754 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8755 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8756 | static int |
| 8757 | _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] | 8758 | struct nfs_fsinfo *info, |
| 8759 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8760 | { |
| 8761 | struct nfs41_secinfo_no_name_args args = { |
| 8762 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8763 | }; |
| 8764 | struct nfs4_secinfo_res res = { |
| 8765 | .flavors = flavors, |
| 8766 | }; |
| 8767 | struct rpc_message msg = { |
| 8768 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8769 | .rpc_argp = &args, |
| 8770 | .rpc_resp = &res, |
| 8771 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8772 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8773 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8774 | int status; |
| 8775 | |
| 8776 | if (use_integrity) { |
| 8777 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8778 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8779 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8780 | } |
| 8781 | |
| 8782 | dprintk("--> %s\n", __func__); |
| 8783 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8784 | &res.seq_res, 0); |
| 8785 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8786 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8787 | if (cred) |
| 8788 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8789 | |
| 8790 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8791 | } |
| 8792 | |
| 8793 | static int |
| 8794 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8795 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8796 | { |
| 8797 | struct nfs4_exception exception = { }; |
| 8798 | int err; |
| 8799 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8800 | /* first try using integrity protection */ |
| 8801 | err = -NFS4ERR_WRONGSEC; |
| 8802 | |
| 8803 | /* try to use integrity protection with machine cred */ |
| 8804 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8805 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8806 | flavors, true); |
| 8807 | |
| 8808 | /* |
| 8809 | * if unable to use integrity protection, or SECINFO with |
| 8810 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8811 | * disallowed by spec, but exists in deployed servers) use |
| 8812 | * the current filesystem's rpc_client and the user cred. |
| 8813 | */ |
| 8814 | if (err == -NFS4ERR_WRONGSEC) |
| 8815 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8816 | flavors, false); |
| 8817 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8818 | switch (err) { |
| 8819 | case 0: |
| 8820 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8821 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8822 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8823 | default: |
| 8824 | err = nfs4_handle_exception(server, err, &exception); |
| 8825 | } |
| 8826 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8827 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8828 | return err; |
| 8829 | } |
| 8830 | |
| 8831 | static int |
| 8832 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8833 | struct nfs_fsinfo *info) |
| 8834 | { |
| 8835 | int err; |
| 8836 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8837 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8838 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8839 | struct nfs4_secinfo4 *secinfo; |
| 8840 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8841 | |
| 8842 | page = alloc_page(GFP_KERNEL); |
| 8843 | if (!page) { |
| 8844 | err = -ENOMEM; |
| 8845 | goto out; |
| 8846 | } |
| 8847 | |
| 8848 | flavors = page_address(page); |
| 8849 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8850 | |
| 8851 | /* |
| 8852 | * Fall back on "guess and check" method if |
| 8853 | * the server doesn't support SECINFO_NO_NAME |
| 8854 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8855 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8856 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8857 | goto out_freepage; |
| 8858 | } |
| 8859 | if (err) |
| 8860 | goto out_freepage; |
| 8861 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8862 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8863 | secinfo = &flavors->flavors[i]; |
| 8864 | |
| 8865 | switch (secinfo->flavor) { |
| 8866 | case RPC_AUTH_NULL: |
| 8867 | case RPC_AUTH_UNIX: |
| 8868 | case RPC_AUTH_GSS: |
| 8869 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8870 | &secinfo->flavor_info); |
| 8871 | break; |
| 8872 | default: |
| 8873 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8874 | break; |
| 8875 | } |
| 8876 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8877 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8878 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8879 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8880 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8881 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8882 | info, flavor); |
| 8883 | if (!err) |
| 8884 | break; |
| 8885 | } |
| 8886 | } |
| 8887 | |
| 8888 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8889 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8890 | |
| 8891 | out_freepage: |
| 8892 | put_page(page); |
| 8893 | if (err == -EACCES) |
| 8894 | return -EPERM; |
| 8895 | out: |
| 8896 | return err; |
| 8897 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8898 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8899 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8900 | nfs4_stateid *stateid, |
| 8901 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8902 | { |
| 8903 | int status; |
| 8904 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8905 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8906 | }; |
| 8907 | struct nfs41_test_stateid_res res; |
| 8908 | struct rpc_message msg = { |
| 8909 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8910 | .rpc_argp = &args, |
| 8911 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8912 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8913 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8914 | struct rpc_clnt *rpc_client = server->client; |
| 8915 | |
| 8916 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8917 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8918 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8919 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8920 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8921 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8922 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8923 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8924 | if (status != NFS_OK) { |
| 8925 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8926 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8927 | } |
| 8928 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8929 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8930 | } |
| 8931 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8932 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8933 | int err, struct nfs4_exception *exception) |
| 8934 | { |
| 8935 | exception->retry = 0; |
| 8936 | switch(err) { |
| 8937 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8938 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8939 | nfs4_handle_exception(server, err, exception); |
| 8940 | break; |
| 8941 | case -NFS4ERR_BADSESSION: |
| 8942 | case -NFS4ERR_BADSLOT: |
| 8943 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8944 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8945 | case -NFS4ERR_DEADSESSION: |
| 8946 | nfs4_do_handle_exception(server, err, exception); |
| 8947 | } |
| 8948 | } |
| 8949 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8950 | /** |
| 8951 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8952 | * |
| 8953 | * @server: server / transport on which to perform the operation |
| 8954 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8955 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8956 | * |
| 8957 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8958 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8959 | * failed or the state ID is not currently valid. |
| 8960 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8961 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8962 | nfs4_stateid *stateid, |
| 8963 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8964 | { |
| 8965 | struct nfs4_exception exception = { }; |
| 8966 | int err; |
| 8967 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8968 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8969 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8970 | } while (exception.retry); |
| 8971 | return err; |
| 8972 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8973 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8974 | struct nfs_free_stateid_data { |
| 8975 | struct nfs_server *server; |
| 8976 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8977 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8978 | }; |
| 8979 | |
| 8980 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8981 | { |
| 8982 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8983 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8984 | &data->args.seq_args, |
| 8985 | &data->res.seq_res, |
| 8986 | task); |
| 8987 | } |
| 8988 | |
| 8989 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8990 | { |
| 8991 | struct nfs_free_stateid_data *data = calldata; |
| 8992 | |
| 8993 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8994 | |
| 8995 | switch (task->tk_status) { |
| 8996 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8997 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8998 | rpc_restart_call_prepare(task); |
| 8999 | } |
| 9000 | } |
| 9001 | |
| 9002 | static void nfs41_free_stateid_release(void *calldata) |
| 9003 | { |
| 9004 | kfree(calldata); |
| 9005 | } |
| 9006 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9007 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9008 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9009 | .rpc_call_done = nfs41_free_stateid_done, |
| 9010 | .rpc_release = nfs41_free_stateid_release, |
| 9011 | }; |
| 9012 | |
| 9013 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9014 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9015 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9016 | bool privileged) |
| 9017 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9018 | struct rpc_message msg = { |
| 9019 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9020 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9021 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9022 | struct rpc_task_setup task_setup = { |
| 9023 | .rpc_client = server->client, |
| 9024 | .rpc_message = &msg, |
| 9025 | .callback_ops = &nfs41_free_stateid_ops, |
| 9026 | .flags = RPC_TASK_ASYNC, |
| 9027 | }; |
| 9028 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9029 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9030 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9031 | &task_setup.rpc_client, &msg); |
| 9032 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9033 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9034 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9035 | if (!data) |
| 9036 | return ERR_PTR(-ENOMEM); |
| 9037 | data->server = server; |
| 9038 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9039 | |
| 9040 | task_setup.callback_data = data; |
| 9041 | |
| 9042 | msg.rpc_argp = &data->args; |
| 9043 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9044 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9045 | if (privileged) |
| 9046 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9047 | |
| 9048 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9049 | } |
| 9050 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9051 | /** |
| 9052 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9053 | * |
| 9054 | * @server: server / transport on which to perform the operation |
| 9055 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9056 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9057 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9058 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9059 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9060 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9061 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9062 | const nfs4_stateid *stateid, |
| 9063 | struct rpc_cred *cred, |
| 9064 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9065 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9066 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9067 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9068 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9069 | if (IS_ERR(task)) |
| 9070 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9071 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9072 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9073 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9074 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9075 | static void |
| 9076 | 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] | 9077 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9078 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9079 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9080 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9081 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9082 | } |
| 9083 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9084 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9085 | const nfs4_stateid *s2) |
| 9086 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9087 | if (s1->type != s2->type) |
| 9088 | return false; |
| 9089 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9090 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9091 | return false; |
| 9092 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9093 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9094 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9095 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9096 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9097 | } |
| 9098 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9099 | #endif /* CONFIG_NFS_V4_1 */ |
| 9100 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9101 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9102 | const nfs4_stateid *s2) |
| 9103 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9104 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9105 | } |
| 9106 | |
| 9107 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9108 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9109 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9110 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9111 | .recover_open = nfs4_open_reclaim, |
| 9112 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9113 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9114 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9115 | }; |
| 9116 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9117 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9118 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9119 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9120 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9121 | .recover_open = nfs4_open_reclaim, |
| 9122 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9123 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9124 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9125 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9126 | }; |
| 9127 | #endif /* CONFIG_NFS_V4_1 */ |
| 9128 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9129 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9130 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9131 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9132 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9133 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9134 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9135 | }; |
| 9136 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9137 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9138 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9139 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9140 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9141 | .recover_open = nfs41_open_expired, |
| 9142 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9143 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9144 | }; |
| 9145 | #endif /* CONFIG_NFS_V4_1 */ |
| 9146 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9147 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9148 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9149 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9150 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9151 | }; |
| 9152 | |
| 9153 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9154 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9155 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9156 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9157 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9158 | }; |
| 9159 | #endif |
| 9160 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9161 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9162 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9163 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9164 | }; |
| 9165 | |
| 9166 | #if defined(CONFIG_NFS_V4_1) |
| 9167 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9168 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9169 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9170 | }; |
| 9171 | #endif /* CONFIG_NFS_V4_1 */ |
| 9172 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9173 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9174 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9175 | .init_caps = NFS_CAP_READDIRPLUS |
| 9176 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9177 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9178 | .init_client = nfs40_init_client, |
| 9179 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9180 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9181 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9182 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9183 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9184 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9185 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9186 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9187 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9188 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9189 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9190 | }; |
| 9191 | |
| 9192 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9193 | static struct nfs_seqid * |
| 9194 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9195 | { |
| 9196 | return NULL; |
| 9197 | } |
| 9198 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9199 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9200 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9201 | .init_caps = NFS_CAP_READDIRPLUS |
| 9202 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9203 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9204 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9205 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9206 | .init_client = nfs41_init_client, |
| 9207 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9208 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9209 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9210 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9211 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9212 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9213 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9214 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9215 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9216 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9217 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9218 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9219 | }; |
| 9220 | #endif |
| 9221 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9222 | #if defined(CONFIG_NFS_V4_2) |
| 9223 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9224 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9225 | .init_caps = NFS_CAP_READDIRPLUS |
| 9226 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9227 | | NFS_CAP_POSIX_LOCK |
| 9228 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9229 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9230 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9231 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9232 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9233 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9234 | | NFS_CAP_LAYOUTSTATS |
| 9235 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9236 | .init_client = nfs41_init_client, |
| 9237 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9238 | .match_stateid = nfs41_match_stateid, |
| 9239 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9240 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9241 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9242 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9243 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9244 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9245 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9246 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9247 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9248 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9249 | }; |
| 9250 | #endif |
| 9251 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9252 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9253 | [0] = &nfs_v4_0_minor_ops, |
| 9254 | #if defined(CONFIG_NFS_V4_1) |
| 9255 | [1] = &nfs_v4_1_minor_ops, |
| 9256 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9257 | #if defined(CONFIG_NFS_V4_2) |
| 9258 | [2] = &nfs_v4_2_minor_ops, |
| 9259 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9260 | }; |
| 9261 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9262 | 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] | 9263 | { |
| 9264 | ssize_t error, error2; |
| 9265 | |
| 9266 | error = generic_listxattr(dentry, list, size); |
| 9267 | if (error < 0) |
| 9268 | return error; |
| 9269 | if (list) { |
| 9270 | list += error; |
| 9271 | size -= error; |
| 9272 | } |
| 9273 | |
| 9274 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9275 | if (error2 < 0) |
| 9276 | return error2; |
| 9277 | return error + error2; |
| 9278 | } |
| 9279 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9280 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9281 | .create = nfs_create, |
| 9282 | .lookup = nfs_lookup, |
| 9283 | .atomic_open = nfs_atomic_open, |
| 9284 | .link = nfs_link, |
| 9285 | .unlink = nfs_unlink, |
| 9286 | .symlink = nfs_symlink, |
| 9287 | .mkdir = nfs_mkdir, |
| 9288 | .rmdir = nfs_rmdir, |
| 9289 | .mknod = nfs_mknod, |
| 9290 | .rename = nfs_rename, |
| 9291 | .permission = nfs_permission, |
| 9292 | .getattr = nfs_getattr, |
| 9293 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9294 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9295 | }; |
| 9296 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9297 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9298 | .permission = nfs_permission, |
| 9299 | .getattr = nfs_getattr, |
| 9300 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9301 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9302 | }; |
| 9303 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9304 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9305 | .version = 4, /* protocol version */ |
| 9306 | .dentry_ops = &nfs4_dentry_operations, |
| 9307 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9308 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9309 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9310 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9311 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9312 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9313 | .getattr = nfs4_proc_getattr, |
| 9314 | .setattr = nfs4_proc_setattr, |
| 9315 | .lookup = nfs4_proc_lookup, |
| 9316 | .access = nfs4_proc_access, |
| 9317 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9318 | .create = nfs4_proc_create, |
| 9319 | .remove = nfs4_proc_remove, |
| 9320 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9321 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9322 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9323 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9324 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9325 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9326 | .link = nfs4_proc_link, |
| 9327 | .symlink = nfs4_proc_symlink, |
| 9328 | .mkdir = nfs4_proc_mkdir, |
| 9329 | .rmdir = nfs4_proc_remove, |
| 9330 | .readdir = nfs4_proc_readdir, |
| 9331 | .mknod = nfs4_proc_mknod, |
| 9332 | .statfs = nfs4_proc_statfs, |
| 9333 | .fsinfo = nfs4_proc_fsinfo, |
| 9334 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9335 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9336 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9337 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9338 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9339 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9340 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9341 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9342 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9343 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9344 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9345 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9346 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9347 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9348 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9349 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9350 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9351 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9352 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9353 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9354 | .create_server = nfs4_create_server, |
| 9355 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9356 | }; |
| 9357 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9358 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9359 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9360 | .list = nfs4_xattr_list_nfs4_acl, |
| 9361 | .get = nfs4_xattr_get_nfs4_acl, |
| 9362 | .set = nfs4_xattr_set_nfs4_acl, |
| 9363 | }; |
| 9364 | |
| 9365 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9366 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9367 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9368 | &nfs4_xattr_nfs4_label_handler, |
| 9369 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9370 | NULL |
| 9371 | }; |
| 9372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9373 | /* |
| 9374 | * Local variables: |
| 9375 | * c-basic-offset: 8 |
| 9376 | * End: |
| 9377 | */ |