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) { |
| 701 | slot->interrupted = 0; |
| 702 | interrupted = true; |
| 703 | } |
| 704 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 705 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 706 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 707 | switch (res->sr_status) { |
| 708 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 709 | /* If previous op on slot was interrupted and we reused |
| 710 | * the seq# and got a reply from the cache, then retry |
| 711 | */ |
| 712 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 713 | ++slot->seq_nr; |
| 714 | goto retry_nowait; |
| 715 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 716 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 717 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 718 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 719 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 720 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 721 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 722 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 723 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 724 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 725 | case 1: |
| 726 | /* |
| 727 | * sr_status remains 1 if an RPC level error occurred. |
| 728 | * The server may or may not have processed the sequence |
| 729 | * operation.. |
| 730 | * Mark the slot as having hosted an interrupted RPC call. |
| 731 | */ |
| 732 | slot->interrupted = 1; |
| 733 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 734 | case -NFS4ERR_DELAY: |
| 735 | /* The server detected a resend of the RPC call and |
| 736 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 737 | * of RFC5661. |
| 738 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 739 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 740 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 741 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 742 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 743 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 744 | case -NFS4ERR_BADSLOT: |
| 745 | /* |
| 746 | * The slot id we used was probably retired. Try again |
| 747 | * using a different slot id. |
| 748 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 749 | goto retry_nowait; |
| 750 | case -NFS4ERR_SEQ_MISORDERED: |
| 751 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 752 | * Was the last operation on this sequence interrupted? |
| 753 | * If so, retry after bumping the sequence number. |
| 754 | */ |
| 755 | if (interrupted) { |
| 756 | ++slot->seq_nr; |
| 757 | goto retry_nowait; |
| 758 | } |
| 759 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 760 | * Could this slot have been previously retired? |
| 761 | * If so, then the server may be expecting seq_nr = 1! |
| 762 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 763 | if (slot->seq_nr != 1) { |
| 764 | slot->seq_nr = 1; |
| 765 | goto retry_nowait; |
| 766 | } |
| 767 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 768 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 769 | ++slot->seq_nr; |
| 770 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | default: |
| 772 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 773 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 774 | } |
| 775 | out: |
| 776 | /* The session may be reset by one of the error handlers. */ |
| 777 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 778 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 779 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 780 | retry_nowait: |
| 781 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 782 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 783 | task->tk_status = 0; |
| 784 | ret = 0; |
| 785 | } |
| 786 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 787 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 788 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 789 | goto out; |
| 790 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 791 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 792 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | |
| 794 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 795 | { |
| 796 | if (!nfs41_sequence_process(task, res)) |
| 797 | return 0; |
| 798 | if (res->sr_slot != NULL) |
| 799 | nfs41_sequence_free_slot(res); |
| 800 | return 1; |
| 801 | |
| 802 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 803 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 804 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 805 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 806 | { |
| 807 | if (res->sr_slot == NULL) |
| 808 | return 1; |
| 809 | if (res->sr_slot->table->session != NULL) |
| 810 | return nfs41_sequence_process(task, res); |
| 811 | return nfs40_sequence_done(task, res); |
| 812 | } |
| 813 | |
| 814 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 815 | { |
| 816 | if (res->sr_slot != NULL) { |
| 817 | if (res->sr_slot->table->session != NULL) |
| 818 | nfs41_sequence_free_slot(res); |
| 819 | else |
| 820 | nfs40_sequence_free_slot(res); |
| 821 | } |
| 822 | } |
| 823 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 824 | 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] | 825 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 826 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 827 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 828 | if (!res->sr_slot->table->session) |
| 829 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 830 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 831 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 832 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 833 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 834 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 835 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 836 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 837 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 838 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 839 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 840 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 841 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 842 | } |
| 843 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 844 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 845 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 846 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 847 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 848 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 849 | } |
| 850 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 851 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 852 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 853 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 854 | }; |
| 855 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 856 | #else /* !CONFIG_NFS_V4_1 */ |
| 857 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 858 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 859 | { |
| 860 | return nfs40_sequence_done(task, res); |
| 861 | } |
| 862 | |
| 863 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 864 | { |
| 865 | if (res->sr_slot != NULL) |
| 866 | nfs40_sequence_free_slot(res); |
| 867 | } |
| 868 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 869 | int nfs4_sequence_done(struct rpc_task *task, |
| 870 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 871 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 872 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 873 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 874 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 875 | |
| 876 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 877 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 878 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 879 | struct nfs4_sequence_args *args, |
| 880 | struct nfs4_sequence_res *res, |
| 881 | struct rpc_task *task) |
| 882 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 883 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 884 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 885 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 886 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 887 | /* slot already allocated? */ |
| 888 | if (res->sr_slot != NULL) |
| 889 | goto out_start; |
| 890 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 891 | if (session) { |
| 892 | tbl = &session->fc_slot_table; |
| 893 | task->tk_timeout = 0; |
| 894 | } |
| 895 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 896 | spin_lock(&tbl->slot_tbl_lock); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 897 | /* The state manager will wait until the slot table is empty */ |
| 898 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 899 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 900 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 901 | slot = nfs4_alloc_slot(tbl); |
| 902 | if (IS_ERR(slot)) { |
| 903 | /* Try again in 1/4 second */ |
| 904 | if (slot == ERR_PTR(-ENOMEM)) |
| 905 | task->tk_timeout = HZ >> 2; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 906 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 907 | } |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 908 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 909 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 910 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 911 | args->sa_slot = slot; |
| 912 | |
| 913 | res->sr_slot = slot; |
| 914 | if (session) { |
| 915 | res->sr_timestamp = jiffies; |
| 916 | res->sr_status_flags = 0; |
| 917 | res->sr_status = 1; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 918 | } |
| 919 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 920 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 921 | out_start: |
| 922 | rpc_call_start(task); |
| 923 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 924 | |
| 925 | out_sleep: |
| 926 | if (args->sa_privileged) |
| 927 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 928 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 929 | else |
| 930 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 931 | spin_unlock(&tbl->slot_tbl_lock); |
| 932 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 933 | } |
| 934 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 935 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 936 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 937 | { |
| 938 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 939 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 940 | data->seq_args, data->seq_res, task); |
| 941 | } |
| 942 | |
| 943 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 944 | { |
| 945 | struct nfs4_call_sync_data *data = calldata; |
| 946 | nfs4_sequence_done(task, data->seq_res); |
| 947 | } |
| 948 | |
| 949 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 950 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 951 | .rpc_call_done = nfs40_call_sync_done, |
| 952 | }; |
| 953 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 954 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 955 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 957 | struct nfs4_sequence_args *args, |
| 958 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 959 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 960 | int ret; |
| 961 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 962 | struct nfs_client *clp = server->nfs_client; |
| 963 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 964 | .seq_server = server, |
| 965 | .seq_args = args, |
| 966 | .seq_res = res, |
| 967 | }; |
| 968 | struct rpc_task_setup task_setup = { |
| 969 | .rpc_client = clnt, |
| 970 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 971 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 972 | .callback_data = &data |
| 973 | }; |
| 974 | |
| 975 | task = rpc_run_task(&task_setup); |
| 976 | if (IS_ERR(task)) |
| 977 | ret = PTR_ERR(task); |
| 978 | else { |
| 979 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 980 | rpc_put_task(task); |
| 981 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 982 | return ret; |
| 983 | } |
| 984 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 985 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 986 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 987 | struct rpc_message *msg, |
| 988 | struct nfs4_sequence_args *args, |
| 989 | struct nfs4_sequence_res *res, |
| 990 | int cache_reply) |
| 991 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 992 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 993 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 994 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 996 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 997 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | { |
| 999 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1000 | |
| 1001 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1002 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1003 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1004 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1005 | nfsi->attrtimeo_timestamp = jiffies; |
| 1006 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1008 | if (cinfo->before != dir->i_version) |
| 1009 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1010 | NFS_INO_INVALID_ACL; |
| 1011 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1012 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1013 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1014 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1015 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | spin_unlock(&dir->i_lock); |
| 1017 | } |
| 1018 | |
| 1019 | struct nfs4_opendata { |
| 1020 | struct kref kref; |
| 1021 | struct nfs_openargs o_arg; |
| 1022 | struct nfs_openres o_res; |
| 1023 | struct nfs_open_confirmargs c_arg; |
| 1024 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1025 | struct nfs4_string owner_name; |
| 1026 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1027 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1029 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1031 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | struct nfs4_state_owner *owner; |
| 1033 | struct nfs4_state *state; |
| 1034 | struct iattr attrs; |
| 1035 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1036 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1037 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1038 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1039 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | int cancelled; |
| 1041 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1042 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1043 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1044 | int err, struct nfs4_exception *exception) |
| 1045 | { |
| 1046 | if (err != -EINVAL) |
| 1047 | return false; |
| 1048 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1049 | return false; |
| 1050 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1051 | exception->retry = 1; |
| 1052 | return true; |
| 1053 | } |
| 1054 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1055 | static u32 |
| 1056 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1057 | fmode_t fmode, int openflags) |
| 1058 | { |
| 1059 | u32 res = 0; |
| 1060 | |
| 1061 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1062 | case FMODE_READ: |
| 1063 | res = NFS4_SHARE_ACCESS_READ; |
| 1064 | break; |
| 1065 | case FMODE_WRITE: |
| 1066 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1067 | break; |
| 1068 | case FMODE_READ|FMODE_WRITE: |
| 1069 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1070 | } |
| 1071 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1072 | goto out; |
| 1073 | /* Want no delegation if we're using O_DIRECT */ |
| 1074 | if (openflags & O_DIRECT) |
| 1075 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1076 | out: |
| 1077 | return res; |
| 1078 | } |
| 1079 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1080 | static enum open_claim_type4 |
| 1081 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1082 | enum open_claim_type4 claim) |
| 1083 | { |
| 1084 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1085 | return claim; |
| 1086 | switch (claim) { |
| 1087 | default: |
| 1088 | return claim; |
| 1089 | case NFS4_OPEN_CLAIM_FH: |
| 1090 | return NFS4_OPEN_CLAIM_NULL; |
| 1091 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1092 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1093 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1094 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1095 | } |
| 1096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
| 1098 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1099 | { |
| 1100 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1101 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1102 | p->o_res.seqid = p->o_arg.seqid; |
| 1103 | p->c_res.seqid = p->c_arg.seqid; |
| 1104 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1105 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1106 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1107 | 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] | 1108 | } |
| 1109 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1110 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1111 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1112 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1113 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1114 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1115 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1116 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1117 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1118 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1119 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1120 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1121 | struct nfs4_opendata *p; |
| 1122 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1123 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1124 | if (p == NULL) |
| 1125 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1126 | |
| 1127 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1128 | if (IS_ERR(p->f_label)) |
| 1129 | goto err_free_p; |
| 1130 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1131 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1132 | if (IS_ERR(p->a_label)) |
| 1133 | goto err_free_f; |
| 1134 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1135 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1136 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1137 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1138 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1139 | nfs_sb_active(dentry->d_sb); |
| 1140 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1141 | p->dir = parent; |
| 1142 | p->owner = sp; |
| 1143 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1144 | p->o_arg.open_flags = flags; |
| 1145 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1146 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1147 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1148 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1149 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1150 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1151 | * will return permission denied for all bits until close */ |
| 1152 | if (!(flags & O_EXCL)) { |
| 1153 | /* ask server to check for all possible rights as results |
| 1154 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1155 | switch (p->o_arg.claim) { |
| 1156 | default: |
| 1157 | break; |
| 1158 | case NFS4_OPEN_CLAIM_NULL: |
| 1159 | case NFS4_OPEN_CLAIM_FH: |
| 1160 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1161 | NFS4_ACCESS_MODIFY | |
| 1162 | NFS4_ACCESS_EXTEND | |
| 1163 | NFS4_ACCESS_EXECUTE; |
| 1164 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1165 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1166 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1167 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1168 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1169 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1170 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1171 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1172 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1173 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1174 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1175 | case NFS4_OPEN_CLAIM_NULL: |
| 1176 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1177 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1178 | p->o_arg.fh = NFS_FH(dir); |
| 1179 | break; |
| 1180 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1181 | case NFS4_OPEN_CLAIM_FH: |
| 1182 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1183 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1184 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1185 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1186 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1187 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1188 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | p->o_arg.u.attrs = &p->attrs; |
| 1190 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1191 | |
| 1192 | verf[0] = jiffies; |
| 1193 | verf[1] = current->pid; |
| 1194 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1195 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1196 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1197 | p->c_arg.fh = &p->o_res.fh; |
| 1198 | p->c_arg.stateid = &p->o_res.stateid; |
| 1199 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1200 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1201 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1202 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1203 | |
| 1204 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1205 | nfs4_label_free(p->a_label); |
| 1206 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1207 | nfs4_label_free(p->f_label); |
| 1208 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1209 | kfree(p); |
| 1210 | err: |
| 1211 | dput(parent); |
| 1212 | return NULL; |
| 1213 | } |
| 1214 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1215 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1216 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1217 | struct nfs4_opendata *p = container_of(kref, |
| 1218 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1219 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1220 | |
| 1221 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1222 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1223 | if (p->state != NULL) |
| 1224 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1225 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1226 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1227 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1228 | nfs4_label_free(p->f_label); |
| 1229 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1230 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1231 | dput(p->dentry); |
| 1232 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1233 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1234 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1235 | kfree(p); |
| 1236 | } |
| 1237 | |
| 1238 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1239 | { |
| 1240 | if (p != NULL) |
| 1241 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1244 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1245 | fmode_t fmode) |
| 1246 | { |
| 1247 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1248 | case FMODE_READ|FMODE_WRITE: |
| 1249 | return state->n_rdwr != 0; |
| 1250 | case FMODE_WRITE: |
| 1251 | return state->n_wronly != 0; |
| 1252 | case FMODE_READ: |
| 1253 | return state->n_rdonly != 0; |
| 1254 | } |
| 1255 | WARN_ON_ONCE(1); |
| 1256 | return false; |
| 1257 | } |
| 1258 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1259 | 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] | 1260 | { |
| 1261 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1262 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1263 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1264 | goto out; |
| 1265 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1266 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1267 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1268 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1269 | break; |
| 1270 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1271 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1272 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1273 | break; |
| 1274 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1275 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1276 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1277 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1278 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1279 | return ret; |
| 1280 | } |
| 1281 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1282 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1283 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1284 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1285 | if (delegation == NULL) |
| 1286 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1287 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1288 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1289 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1290 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1291 | switch (claim) { |
| 1292 | case NFS4_OPEN_CLAIM_NULL: |
| 1293 | case NFS4_OPEN_CLAIM_FH: |
| 1294 | break; |
| 1295 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1296 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1297 | break; |
| 1298 | default: |
| 1299 | return 0; |
| 1300 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1301 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1302 | return 1; |
| 1303 | } |
| 1304 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1305 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1306 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1307 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1308 | case FMODE_WRITE: |
| 1309 | state->n_wronly++; |
| 1310 | break; |
| 1311 | case FMODE_READ: |
| 1312 | state->n_rdonly++; |
| 1313 | break; |
| 1314 | case FMODE_READ|FMODE_WRITE: |
| 1315 | state->n_rdwr++; |
| 1316 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1317 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1320 | #ifdef CONFIG_NFS_V4_1 |
| 1321 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1322 | { |
| 1323 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1324 | return true; |
| 1325 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1326 | return true; |
| 1327 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1328 | return true; |
| 1329 | return false; |
| 1330 | } |
| 1331 | #endif /* CONFIG_NFS_V4_1 */ |
| 1332 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1333 | 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] | 1334 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1335 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1336 | bool need_recover = false; |
| 1337 | |
| 1338 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1339 | need_recover = true; |
| 1340 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1341 | need_recover = true; |
| 1342 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1343 | need_recover = true; |
| 1344 | if (need_recover) |
| 1345 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1346 | } |
| 1347 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1348 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1349 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1350 | { |
| 1351 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1352 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1353 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1354 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1355 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1356 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1357 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1358 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1359 | return true; |
| 1360 | return false; |
| 1361 | } |
| 1362 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1363 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1364 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1365 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1366 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1367 | if (state->n_wronly) |
| 1368 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1369 | if (state->n_rdonly) |
| 1370 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1371 | if (state->n_rdwr) |
| 1372 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1373 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1374 | } |
| 1375 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1376 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1377 | nfs4_stateid *stateid, fmode_t fmode) |
| 1378 | { |
| 1379 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1380 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1381 | case FMODE_WRITE: |
| 1382 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1383 | break; |
| 1384 | case FMODE_READ: |
| 1385 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1386 | break; |
| 1387 | case 0: |
| 1388 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1389 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1390 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1391 | } |
| 1392 | if (stateid == NULL) |
| 1393 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1394 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1395 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1396 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1397 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1398 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1399 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1400 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1401 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1402 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1403 | } |
| 1404 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1405 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1406 | nfs4_stateid *arg_stateid, |
| 1407 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1408 | { |
| 1409 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1410 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1411 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1412 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1413 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1414 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1415 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1416 | } |
| 1417 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1418 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1419 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1420 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1421 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1422 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1423 | case FMODE_READ: |
| 1424 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1425 | break; |
| 1426 | case FMODE_WRITE: |
| 1427 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1428 | break; |
| 1429 | case FMODE_READ|FMODE_WRITE: |
| 1430 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1431 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1432 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1433 | return; |
| 1434 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1435 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1436 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1439 | static void __update_open_stateid(struct nfs4_state *state, |
| 1440 | const nfs4_stateid *open_stateid, |
| 1441 | const nfs4_stateid *deleg_stateid, |
| 1442 | fmode_t fmode, |
| 1443 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1445 | /* |
| 1446 | * Protect the call to nfs4_state_set_mode_locked and |
| 1447 | * serialise the stateid update |
| 1448 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1449 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1450 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1451 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1452 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1453 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1454 | } |
| 1455 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1456 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1457 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1458 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1459 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1462 | static int update_open_stateid(struct nfs4_state *state, |
| 1463 | const nfs4_stateid *open_stateid, |
| 1464 | const nfs4_stateid *delegation, |
| 1465 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1466 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1467 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1468 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1469 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1470 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1471 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1472 | int ret = 0; |
| 1473 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1474 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1475 | |
| 1476 | rcu_read_lock(); |
| 1477 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1478 | if (deleg_cur == NULL) |
| 1479 | goto no_delegation; |
| 1480 | |
| 1481 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1482 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1483 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1484 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1485 | goto no_delegation_unlock; |
| 1486 | |
| 1487 | if (delegation == NULL) |
| 1488 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1489 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1490 | goto no_delegation_unlock; |
| 1491 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1492 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1493 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1494 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1495 | ret = 1; |
| 1496 | no_delegation_unlock: |
| 1497 | spin_unlock(&deleg_cur->lock); |
| 1498 | no_delegation: |
| 1499 | rcu_read_unlock(); |
| 1500 | |
| 1501 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1502 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1503 | ret = 1; |
| 1504 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1505 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1506 | nfs4_schedule_state_manager(clp); |
| 1507 | if (freeme.type != 0) |
| 1508 | nfs4_test_and_free_stateid(server, &freeme, |
| 1509 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1510 | |
| 1511 | return ret; |
| 1512 | } |
| 1513 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1514 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1515 | const nfs4_stateid *stateid) |
| 1516 | { |
| 1517 | struct nfs4_state *state = lsp->ls_state; |
| 1518 | bool ret = false; |
| 1519 | |
| 1520 | spin_lock(&state->state_lock); |
| 1521 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1522 | goto out_noupdate; |
| 1523 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1524 | goto out_noupdate; |
| 1525 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1526 | ret = true; |
| 1527 | out_noupdate: |
| 1528 | spin_unlock(&state->state_lock); |
| 1529 | return ret; |
| 1530 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1531 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1532 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1533 | { |
| 1534 | struct nfs_delegation *delegation; |
| 1535 | |
| 1536 | rcu_read_lock(); |
| 1537 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1538 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1539 | rcu_read_unlock(); |
| 1540 | return; |
| 1541 | } |
| 1542 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1543 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1546 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1547 | { |
| 1548 | struct nfs4_state *state = opendata->state; |
| 1549 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1550 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1551 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1552 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1553 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1554 | nfs4_stateid stateid; |
| 1555 | int ret = -EAGAIN; |
| 1556 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1557 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1558 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1559 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1560 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1561 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1562 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1563 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1564 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1565 | rcu_read_lock(); |
| 1566 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1567 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1568 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1569 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1570 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1571 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1572 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1573 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1574 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1575 | if (!opendata->is_recover) { |
| 1576 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1577 | if (ret != 0) |
| 1578 | goto out; |
| 1579 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1580 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1581 | |
| 1582 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1583 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1584 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1585 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1586 | out: |
| 1587 | return ERR_PTR(ret); |
| 1588 | out_return_state: |
| 1589 | atomic_inc(&state->count); |
| 1590 | return state; |
| 1591 | } |
| 1592 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1593 | static void |
| 1594 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1595 | { |
| 1596 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1597 | struct nfs_delegation *delegation; |
| 1598 | int delegation_flags = 0; |
| 1599 | |
| 1600 | rcu_read_lock(); |
| 1601 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1602 | if (delegation) |
| 1603 | delegation_flags = delegation->flags; |
| 1604 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1605 | switch (data->o_arg.claim) { |
| 1606 | default: |
| 1607 | break; |
| 1608 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1609 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1610 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1611 | "returning a delegation for " |
| 1612 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1613 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1614 | return; |
| 1615 | } |
| 1616 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1617 | nfs_inode_set_delegation(state->inode, |
| 1618 | data->owner->so_cred, |
| 1619 | &data->o_res); |
| 1620 | else |
| 1621 | nfs_inode_reclaim_delegation(state->inode, |
| 1622 | data->owner->so_cred, |
| 1623 | &data->o_res); |
| 1624 | } |
| 1625 | |
| 1626 | /* |
| 1627 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1628 | * and update the nfs4_state. |
| 1629 | */ |
| 1630 | static struct nfs4_state * |
| 1631 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1632 | { |
| 1633 | struct inode *inode = data->state->inode; |
| 1634 | struct nfs4_state *state = data->state; |
| 1635 | int ret; |
| 1636 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1637 | if (!data->rpc_done) { |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1638 | if (data->rpc_status) |
| 1639 | return ERR_PTR(data->rpc_status); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1640 | /* cached opens have already been processed */ |
| 1641 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1642 | } |
| 1643 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1644 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1645 | if (ret) |
Anna Schumaker | 37a8484 | 2017-01-11 16:08:35 -0500 | [diff] [blame] | 1646 | return ERR_PTR(ret); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1647 | |
| 1648 | if (data->o_res.delegation_type != 0) |
| 1649 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1650 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1651 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1652 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1653 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1654 | |
| 1655 | return state; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | static struct nfs4_state * |
| 1659 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1660 | { |
| 1661 | struct inode *inode; |
| 1662 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1663 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1664 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1665 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1666 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1667 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1668 | goto out; |
| 1669 | } |
| 1670 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1671 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1672 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1673 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1674 | 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] | 1675 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1676 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1677 | goto err; |
| 1678 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1679 | state = nfs4_get_open_state(inode, data->owner); |
| 1680 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1681 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1682 | if (data->o_res.delegation_type != 0) |
| 1683 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1684 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1685 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1687 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1688 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1689 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1690 | err_put_inode: |
| 1691 | iput(inode); |
| 1692 | err: |
| 1693 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1696 | static struct nfs4_state * |
| 1697 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1698 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1699 | struct nfs4_state *ret; |
| 1700 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1701 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1702 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1703 | else |
| 1704 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1705 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1706 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1707 | } |
| 1708 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1709 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1710 | { |
| 1711 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1712 | struct nfs_open_context *ctx; |
| 1713 | |
| 1714 | spin_lock(&state->inode->i_lock); |
| 1715 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1716 | if (ctx->state != state) |
| 1717 | continue; |
| 1718 | get_nfs_open_context(ctx); |
| 1719 | spin_unlock(&state->inode->i_lock); |
| 1720 | return ctx; |
| 1721 | } |
| 1722 | spin_unlock(&state->inode->i_lock); |
| 1723 | return ERR_PTR(-ENOENT); |
| 1724 | } |
| 1725 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1726 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1727 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1728 | { |
| 1729 | struct nfs4_opendata *opendata; |
| 1730 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1731 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1732 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1733 | if (opendata == NULL) |
| 1734 | return ERR_PTR(-ENOMEM); |
| 1735 | opendata->state = state; |
| 1736 | atomic_inc(&state->count); |
| 1737 | return opendata; |
| 1738 | } |
| 1739 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1740 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1741 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1742 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1743 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1744 | int ret; |
| 1745 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1746 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1747 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1748 | opendata->o_arg.open_flags = 0; |
| 1749 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1750 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1751 | NFS_SB(opendata->dentry->d_sb), |
| 1752 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1753 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1754 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1755 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1756 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1757 | if (ret != 0) |
| 1758 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1759 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1760 | if (IS_ERR(newstate)) |
| 1761 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1762 | if (newstate != opendata->state) |
| 1763 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1764 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1765 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1769 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1770 | int ret; |
| 1771 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1772 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1773 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1774 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1775 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1776 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1777 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1778 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1779 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1780 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1781 | if (ret != 0) |
| 1782 | return ret; |
| 1783 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1784 | if (ret != 0) |
| 1785 | return ret; |
| 1786 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1787 | if (ret != 0) |
| 1788 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1789 | /* |
| 1790 | * We may have performed cached opens for all three recoveries. |
| 1791 | * Check if we need to update the current stateid. |
| 1792 | */ |
| 1793 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1794 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1795 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1796 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1797 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1798 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1799 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1800 | return 0; |
| 1801 | } |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | /* |
| 1804 | * OPEN_RECLAIM: |
| 1805 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1807 | 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] | 1808 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1809 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1810 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1811 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | int status; |
| 1813 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1814 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1815 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1816 | if (IS_ERR(opendata)) |
| 1817 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1818 | rcu_read_lock(); |
| 1819 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1820 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1821 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1822 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1823 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1824 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1825 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | return status; |
| 1827 | } |
| 1828 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1829 | 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] | 1830 | { |
| 1831 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1832 | struct nfs4_exception exception = { }; |
| 1833 | int err; |
| 1834 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1835 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1836 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1837 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1838 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1839 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1840 | break; |
| 1841 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | } while (exception.retry); |
| 1843 | return err; |
| 1844 | } |
| 1845 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1846 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1847 | { |
| 1848 | struct nfs_open_context *ctx; |
| 1849 | int ret; |
| 1850 | |
| 1851 | ctx = nfs4_state_find_open_context(state); |
| 1852 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1853 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1854 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1855 | put_nfs_open_context(ctx); |
| 1856 | return ret; |
| 1857 | } |
| 1858 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1859 | 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] | 1860 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1861 | switch (err) { |
| 1862 | default: |
| 1863 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1864 | "%d.\n", __func__, err); |
| 1865 | case 0: |
| 1866 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1867 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1868 | case -ESTALE: |
| 1869 | break; |
| 1870 | case -NFS4ERR_BADSESSION: |
| 1871 | case -NFS4ERR_BADSLOT: |
| 1872 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1873 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1874 | case -NFS4ERR_DEADSESSION: |
| 1875 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1876 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1877 | return -EAGAIN; |
| 1878 | case -NFS4ERR_STALE_CLIENTID: |
| 1879 | case -NFS4ERR_STALE_STATEID: |
| 1880 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1881 | /* Don't recall a delegation if it was lost */ |
| 1882 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1883 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1884 | case -NFS4ERR_MOVED: |
| 1885 | nfs4_schedule_migration_recovery(server); |
| 1886 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1887 | case -NFS4ERR_LEASE_MOVED: |
| 1888 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1889 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1890 | case -NFS4ERR_DELEG_REVOKED: |
| 1891 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1892 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1893 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1894 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1895 | nfs_inode_find_state_and_recover(state->inode, |
| 1896 | stateid); |
| 1897 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1898 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1899 | case -NFS4ERR_DELAY: |
| 1900 | case -NFS4ERR_GRACE: |
| 1901 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1902 | ssleep(1); |
| 1903 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1904 | case -ENOMEM: |
| 1905 | case -NFS4ERR_DENIED: |
| 1906 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1907 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | return err; |
| 1910 | } |
| 1911 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1912 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1913 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1914 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1915 | { |
| 1916 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1917 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1918 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1919 | |
| 1920 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1921 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1922 | if (IS_ERR(opendata)) |
| 1923 | return PTR_ERR(opendata); |
| 1924 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1925 | write_seqlock(&state->seqlock); |
| 1926 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1927 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1928 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1929 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1930 | case FMODE_READ|FMODE_WRITE: |
| 1931 | case FMODE_WRITE: |
| 1932 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1933 | if (err) |
| 1934 | break; |
| 1935 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1936 | if (err) |
| 1937 | break; |
| 1938 | case FMODE_READ: |
| 1939 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1940 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1941 | nfs4_opendata_put(opendata); |
| 1942 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1943 | } |
| 1944 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1945 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1946 | { |
| 1947 | struct nfs4_opendata *data = calldata; |
| 1948 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1949 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1950 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1951 | } |
| 1952 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1953 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1954 | { |
| 1955 | struct nfs4_opendata *data = calldata; |
| 1956 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1957 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1958 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1959 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1960 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1961 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1962 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1963 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1964 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1965 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | static void nfs4_open_confirm_release(void *calldata) |
| 1969 | { |
| 1970 | struct nfs4_opendata *data = calldata; |
| 1971 | struct nfs4_state *state = NULL; |
| 1972 | |
| 1973 | /* If this request hasn't been cancelled, do nothing */ |
| 1974 | if (data->cancelled == 0) |
| 1975 | goto out_free; |
| 1976 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1977 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1978 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1979 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1980 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1981 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1982 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1983 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1987 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1988 | .rpc_call_done = nfs4_open_confirm_done, |
| 1989 | .rpc_release = nfs4_open_confirm_release, |
| 1990 | }; |
| 1991 | |
| 1992 | /* |
| 1993 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1994 | */ |
| 1995 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1996 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1997 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1998 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1999 | struct rpc_message msg = { |
| 2000 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2001 | .rpc_argp = &data->c_arg, |
| 2002 | .rpc_resp = &data->c_res, |
| 2003 | .rpc_cred = data->owner->so_cred, |
| 2004 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2005 | struct rpc_task_setup task_setup_data = { |
| 2006 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2007 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2008 | .callback_ops = &nfs4_open_confirm_ops, |
| 2009 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2010 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2011 | .flags = RPC_TASK_ASYNC, |
| 2012 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | int status; |
| 2014 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2015 | 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] | 2016 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2017 | data->rpc_done = 0; |
| 2018 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2019 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2020 | if (data->is_recover) |
| 2021 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2023 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2024 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2025 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2026 | if (status != 0) { |
| 2027 | data->cancelled = 1; |
| 2028 | smp_wmb(); |
| 2029 | } else |
| 2030 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2031 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | return status; |
| 2033 | } |
| 2034 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2035 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2037 | struct nfs4_opendata *data = calldata; |
| 2038 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2039 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2040 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2041 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2042 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2043 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2044 | /* |
| 2045 | * Check if we still need to send an OPEN call, or if we can use |
| 2046 | * a delegation instead. |
| 2047 | */ |
| 2048 | if (data->state != NULL) { |
| 2049 | struct nfs_delegation *delegation; |
| 2050 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2051 | 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] | 2052 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2053 | rcu_read_lock(); |
| 2054 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2055 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2056 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2057 | rcu_read_unlock(); |
| 2058 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2059 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2060 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2061 | switch (claim) { |
| 2062 | default: |
| 2063 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2064 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2065 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2066 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2067 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2068 | case NFS4_OPEN_CLAIM_FH: |
| 2069 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2070 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2071 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2072 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2073 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2074 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2075 | &data->o_res.seq_res, |
| 2076 | task) != 0) |
| 2077 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2078 | |
| 2079 | /* Set the create mode (note dependency on the session type) */ |
| 2080 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2081 | if (data->o_arg.open_flags & O_EXCL) { |
| 2082 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2083 | if (nfs4_has_persistent_session(clp)) |
| 2084 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2085 | else if (clp->cl_mvops->minor_version > 0) |
| 2086 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2087 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2088 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2089 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2090 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2091 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2092 | out_no_action: |
| 2093 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2094 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2095 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2096 | } |
| 2097 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2098 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2099 | { |
| 2100 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2102 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2103 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2104 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2105 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2106 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2107 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2108 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2109 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2110 | case S_IFREG: |
| 2111 | break; |
| 2112 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2113 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2114 | break; |
| 2115 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2116 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2117 | break; |
| 2118 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2119 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2120 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2121 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2122 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2123 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2124 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2125 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2126 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2127 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2128 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2129 | static void nfs4_open_release(void *calldata) |
| 2130 | { |
| 2131 | struct nfs4_opendata *data = calldata; |
| 2132 | struct nfs4_state *state = NULL; |
| 2133 | |
| 2134 | /* If this request hasn't been cancelled, do nothing */ |
| 2135 | if (data->cancelled == 0) |
| 2136 | goto out_free; |
| 2137 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2138 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2139 | goto out_free; |
| 2140 | /* In case we need an open_confirm, no cleanup! */ |
| 2141 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2142 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2144 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2145 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2146 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2147 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2151 | .rpc_call_prepare = nfs4_open_prepare, |
| 2152 | .rpc_call_done = nfs4_open_done, |
| 2153 | .rpc_release = nfs4_open_release, |
| 2154 | }; |
| 2155 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2156 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2157 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2158 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2159 | struct nfs_server *server = NFS_SERVER(dir); |
| 2160 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2161 | struct nfs_openres *o_res = &data->o_res; |
| 2162 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2163 | struct rpc_message msg = { |
| 2164 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2165 | .rpc_argp = o_arg, |
| 2166 | .rpc_resp = o_res, |
| 2167 | .rpc_cred = data->owner->so_cred, |
| 2168 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2169 | struct rpc_task_setup task_setup_data = { |
| 2170 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2171 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2172 | .callback_ops = &nfs4_open_ops, |
| 2173 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2174 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2175 | .flags = RPC_TASK_ASYNC, |
| 2176 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2177 | int status; |
| 2178 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2179 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2180 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2181 | data->rpc_done = 0; |
| 2182 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2183 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2184 | data->is_recover = 0; |
| 2185 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2186 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2187 | data->is_recover = 1; |
| 2188 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2190 | if (IS_ERR(task)) |
| 2191 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 2192 | status = rpc_wait_for_completion_task(task); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2193 | if (status != 0) { |
| 2194 | data->cancelled = 1; |
| 2195 | smp_wmb(); |
| 2196 | } else |
| 2197 | status = data->rpc_status; |
| 2198 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2199 | |
| 2200 | return status; |
| 2201 | } |
| 2202 | |
| 2203 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2204 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2205 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2206 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2207 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2208 | |
| 2209 | status = nfs4_run_open_task(data, 1); |
| 2210 | if (status != 0 || !data->rpc_done) |
| 2211 | return status; |
| 2212 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2213 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2214 | |
Anna Schumaker | d7e9825 | 2017-01-11 16:13:29 -0500 | [diff] [blame] | 2215 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2216 | status = _nfs4_proc_open_confirm(data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2217 | |
| 2218 | return status; |
| 2219 | } |
| 2220 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2221 | /* |
| 2222 | * Additional permission checks in order to distinguish between an |
| 2223 | * open for read, and an open for execute. This works around the |
| 2224 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2225 | * the same. |
| 2226 | * Note that in the non-execute case, we want to turn off permission |
| 2227 | * checking if we just created a new file (POSIX open() semantics). |
| 2228 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2229 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2230 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2231 | struct nfs4_state *state, fmode_t fmode, |
| 2232 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2233 | { |
| 2234 | struct nfs_access_entry cache; |
| 2235 | u32 mask; |
| 2236 | |
| 2237 | /* access call failed or for some reason the server doesn't |
| 2238 | * support any access modes -- defer access call until later */ |
| 2239 | if (opendata->o_res.access_supported == 0) |
| 2240 | return 0; |
| 2241 | |
| 2242 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2243 | /* |
| 2244 | * Use openflags to check for exec, because fmode won't |
| 2245 | * always have FMODE_EXEC set when file open for exec. |
| 2246 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2247 | if (openflags & __FMODE_EXEC) { |
| 2248 | /* ONLY check for exec rights */ |
| 2249 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2250 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2251 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2252 | |
| 2253 | cache.cred = cred; |
| 2254 | cache.jiffies = jiffies; |
| 2255 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2256 | nfs_access_add_cache(state->inode, &cache); |
| 2257 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2258 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2259 | return 0; |
| 2260 | |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2261 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2262 | } |
| 2263 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2264 | /* |
| 2265 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2266 | */ |
| 2267 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2268 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2269 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2270 | struct nfs_server *server = NFS_SERVER(dir); |
| 2271 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2272 | struct nfs_openres *o_res = &data->o_res; |
| 2273 | int status; |
| 2274 | |
| 2275 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2276 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2277 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2278 | if (status != 0) { |
| 2279 | if (status == -NFS4ERR_BADNAME && |
| 2280 | !(o_arg->open_flags & O_CREAT)) |
| 2281 | return -ENOENT; |
| 2282 | return status; |
| 2283 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2284 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2285 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2286 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2287 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2288 | if (o_arg->open_flags & O_EXCL) |
| 2289 | data->file_created = 1; |
| 2290 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2291 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2292 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2293 | update_changeattr(dir, &o_res->cinfo, |
| 2294 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2295 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2296 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2297 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2299 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2301 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | } |
| 2303 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2304 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2305 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | /* |
| 2309 | * OPEN_EXPIRED: |
| 2310 | * reclaim state on the server after a network partition. |
| 2311 | * Assumes caller holds the appropriate lock |
| 2312 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2313 | 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] | 2314 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2315 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2316 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2318 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2319 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2320 | if (IS_ERR(opendata)) |
| 2321 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2322 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2323 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2324 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2325 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2326 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2329 | 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] | 2330 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2331 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2332 | struct nfs4_exception exception = { }; |
| 2333 | int err; |
| 2334 | |
| 2335 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2336 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2337 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2338 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2339 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2340 | switch (err) { |
| 2341 | default: |
| 2342 | goto out; |
| 2343 | case -NFS4ERR_GRACE: |
| 2344 | case -NFS4ERR_DELAY: |
| 2345 | nfs4_handle_exception(server, err, &exception); |
| 2346 | err = 0; |
| 2347 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2348 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2349 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2350 | return err; |
| 2351 | } |
| 2352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2354 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2356 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2358 | ctx = nfs4_state_find_open_context(state); |
| 2359 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2360 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2361 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2362 | put_nfs_open_context(ctx); |
| 2363 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2366 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2367 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2368 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2369 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2370 | write_seqlock(&state->seqlock); |
| 2371 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2372 | write_sequnlock(&state->seqlock); |
| 2373 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2374 | } |
| 2375 | |
| 2376 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2377 | { |
| 2378 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2379 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2383 | { |
| 2384 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2385 | nfs40_clear_delegation_stateid(state); |
| 2386 | return nfs4_open_expired(sp, state); |
| 2387 | } |
| 2388 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2389 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2390 | nfs4_stateid *stateid, |
| 2391 | struct rpc_cred *cred) |
| 2392 | { |
| 2393 | return -NFS4ERR_BAD_STATEID; |
| 2394 | } |
| 2395 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2396 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2397 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2398 | nfs4_stateid *stateid, |
| 2399 | struct rpc_cred *cred) |
| 2400 | { |
| 2401 | int status; |
| 2402 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2403 | switch (stateid->type) { |
| 2404 | default: |
| 2405 | break; |
| 2406 | case NFS4_INVALID_STATEID_TYPE: |
| 2407 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2408 | return -NFS4ERR_BAD_STATEID; |
| 2409 | case NFS4_REVOKED_STATEID_TYPE: |
| 2410 | goto out_free; |
| 2411 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2412 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2413 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2414 | switch (status) { |
| 2415 | case -NFS4ERR_EXPIRED: |
| 2416 | case -NFS4ERR_ADMIN_REVOKED: |
| 2417 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2418 | break; |
| 2419 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2420 | return status; |
| 2421 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2422 | out_free: |
| 2423 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2424 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2425 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2426 | } |
| 2427 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2428 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2429 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2430 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2431 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2432 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2433 | struct rpc_cred *cred; |
| 2434 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2435 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2436 | /* Get the delegation credential for use by test/free_stateid */ |
| 2437 | rcu_read_lock(); |
| 2438 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2439 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2440 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2441 | return; |
| 2442 | } |
| 2443 | |
| 2444 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Olga Kornievskaia | 0e3d3e5 | 2017-03-30 13:49:03 -0400 | [diff] [blame] | 2445 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2446 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 2447 | &delegation->flags)) { |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2448 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2449 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2450 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2451 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2452 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2453 | cred = get_rpccred(delegation->cred); |
| 2454 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2455 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2456 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2457 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2458 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2459 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2460 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2464 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2465 | * |
| 2466 | * @state: NFSv4 state for an inode |
| 2467 | * |
| 2468 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2469 | * Otherwise a negative NFS4ERR value is returned. |
| 2470 | */ |
| 2471 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2472 | { |
| 2473 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2474 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2475 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2476 | |
| 2477 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2478 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2479 | |
| 2480 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2481 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2482 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2483 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2484 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2485 | atomic_inc(&lsp->ls_count); |
| 2486 | spin_unlock(&state->state_lock); |
| 2487 | |
| 2488 | nfs4_put_lock_state(prev); |
| 2489 | prev = lsp; |
| 2490 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2491 | status = nfs41_test_and_free_expired_stateid(server, |
| 2492 | &lsp->ls_stateid, |
| 2493 | cred); |
| 2494 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2495 | if (status == -NFS4ERR_EXPIRED || |
| 2496 | status == -NFS4ERR_BAD_STATEID) { |
| 2497 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2498 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2499 | if (!recover_lost_locks) |
| 2500 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2501 | } else if (status != NFS_OK) { |
| 2502 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2503 | nfs4_put_lock_state(prev); |
| 2504 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2505 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2506 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2507 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2508 | } |
| 2509 | spin_unlock(&state->state_lock); |
| 2510 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2511 | out: |
| 2512 | return ret; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2516 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2517 | * |
| 2518 | * @state: NFSv4 state for an inode |
| 2519 | * |
| 2520 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2521 | * Otherwise a negative NFS4ERR value is returned. |
| 2522 | */ |
| 2523 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2524 | { |
| 2525 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2526 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2527 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2528 | int status; |
| 2529 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2530 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2531 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2532 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2533 | return NFS_OK; |
| 2534 | return -NFS4ERR_OPENMODE; |
| 2535 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2536 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2537 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2538 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2539 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2540 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2541 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2542 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2543 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2544 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2545 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2546 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2547 | if (status != NFS_OK) |
| 2548 | return status; |
| 2549 | if (nfs_open_stateid_recover_openmode(state)) |
| 2550 | return -NFS4ERR_OPENMODE; |
| 2551 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2555 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2556 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2557 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2558 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2559 | status = nfs41_check_expired_locks(state); |
| 2560 | if (status != NFS_OK) |
| 2561 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2562 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2563 | if (status != NFS_OK) |
| 2564 | status = nfs4_open_expired(sp, state); |
| 2565 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2566 | } |
| 2567 | #endif |
| 2568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2570 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2571 | * fields corresponding to attributes that were used to store the verifier. |
| 2572 | * Make sure we clobber those fields in the later setattr call |
| 2573 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2574 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2575 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2576 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2577 | const u32 *attrset = opendata->o_res.attrset; |
| 2578 | |
| 2579 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2580 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2581 | sattr->ia_valid |= ATTR_ATIME; |
| 2582 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2583 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2584 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2585 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2586 | |
| 2587 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2588 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2589 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2590 | sattr->ia_valid &= ~ATTR_MODE; |
| 2591 | |
| 2592 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2593 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2594 | } |
| 2595 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2596 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2597 | fmode_t fmode, |
| 2598 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2599 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2600 | { |
| 2601 | struct nfs4_state_owner *sp = opendata->owner; |
| 2602 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2603 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2604 | struct nfs4_state *state; |
| 2605 | unsigned int seq; |
| 2606 | int ret; |
| 2607 | |
| 2608 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2609 | |
| 2610 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2611 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2612 | goto out; |
| 2613 | |
| 2614 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2615 | ret = PTR_ERR(state); |
| 2616 | if (IS_ERR(state)) |
| 2617 | goto out; |
Trond Myklebust | a974dee | 2017-02-08 11:29:46 -0500 | [diff] [blame] | 2618 | ctx->state = state; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2619 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2620 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2621 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2622 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2623 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2624 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2625 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2626 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2627 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2628 | alias = d_exact_alias(dentry, state->inode); |
| 2629 | if (!alias) |
| 2630 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2631 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2632 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2633 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2634 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2635 | } |
| 2636 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2637 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2638 | } |
| 2639 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2640 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2641 | if (ret != 0) |
| 2642 | goto out; |
| 2643 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2644 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2645 | nfs_inode_attach_open_context(ctx); |
| 2646 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2647 | nfs4_schedule_stateid_recovery(server, state); |
| 2648 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2649 | out: |
| 2650 | return ret; |
| 2651 | } |
| 2652 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2653 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2654 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2656 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2657 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2658 | int flags, |
| 2659 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2660 | struct nfs4_label *label, |
| 2661 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | { |
| 2663 | struct nfs4_state_owner *sp; |
| 2664 | struct nfs4_state *state = NULL; |
| 2665 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2666 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2667 | struct dentry *dentry = ctx->dentry; |
| 2668 | struct rpc_cred *cred = ctx->cred; |
| 2669 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2670 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2671 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2672 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2673 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
| 2675 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2677 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2678 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2680 | goto out_err; |
| 2681 | } |
Anna Schumaker | 334f87d | 2017-01-11 16:17:17 -0500 | [diff] [blame] | 2682 | status = nfs4_client_recover_expired_lease(server->nfs_client); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2683 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2684 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2685 | if (d_really_is_positive(dentry)) |
| 2686 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2687 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2688 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2689 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2690 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2691 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2692 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2693 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2695 | if (label) { |
| 2696 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2697 | if (IS_ERR(olabel)) { |
| 2698 | status = PTR_ERR(olabel); |
| 2699 | goto err_opendata_put; |
| 2700 | } |
| 2701 | } |
| 2702 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2703 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2704 | if (!opendata->f_attr.mdsthreshold) { |
| 2705 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2706 | if (!opendata->f_attr.mdsthreshold) |
| 2707 | goto err_free_label; |
| 2708 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2709 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2710 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2711 | if (d_really_is_positive(dentry)) |
| 2712 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2713 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2714 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2715 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2716 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2717 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2718 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2719 | 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] | 2720 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2721 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2722 | /* |
| 2723 | * send create attributes which was not set by open |
| 2724 | * with an extra setattr. |
| 2725 | */ |
| 2726 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2727 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2728 | status = nfs4_do_setattr(state->inode, cred, |
| 2729 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2730 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2731 | if (status == 0) { |
| 2732 | nfs_setattr_update_inode(state->inode, sattr, |
| 2733 | opendata->o_res.f_attr); |
| 2734 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2735 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2736 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2737 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2738 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2739 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2740 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2741 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2742 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2743 | opendata->f_attr.mdsthreshold = NULL; |
| 2744 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2745 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2746 | nfs4_label_free(olabel); |
| 2747 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2748 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2751 | err_free_label: |
| 2752 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2753 | err_opendata_put: |
| 2754 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2755 | err_put_state_owner: |
| 2756 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | return status; |
| 2759 | } |
| 2760 | |
| 2761 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2762 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2763 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2764 | int flags, |
| 2765 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2766 | struct nfs4_label *label, |
| 2767 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2769 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | struct nfs4_exception exception = { }; |
| 2771 | struct nfs4_state *res; |
| 2772 | int status; |
| 2773 | |
| 2774 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2775 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2776 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2777 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | if (status == 0) |
| 2779 | break; |
| 2780 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2781 | * book-keeping w.r.t. state-changing operations |
| 2782 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2783 | * It is actually a sign of a bug on the client or on the server. |
| 2784 | * |
| 2785 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2786 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | * have unhashed the old state_owner for us, and that we can |
| 2788 | * therefore safely retry using a new one. We should still warn |
| 2789 | * the user though... |
| 2790 | */ |
| 2791 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2792 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2793 | " returned a bad sequence-id error!\n", |
| 2794 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | exception.retry = 1; |
| 2796 | continue; |
| 2797 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2798 | /* |
| 2799 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2800 | * state before it received the OPEN_CONFIRM. |
| 2801 | * Recover by retrying the request as per the discussion |
| 2802 | * on Page 181 of RFC3530. |
| 2803 | */ |
| 2804 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2805 | exception.retry = 1; |
| 2806 | continue; |
| 2807 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2808 | if (status == -EAGAIN) { |
| 2809 | /* We must have found a delegation */ |
| 2810 | exception.retry = 1; |
| 2811 | continue; |
| 2812 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2813 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2814 | continue; |
| 2815 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | status, &exception)); |
| 2817 | } while (exception.retry); |
| 2818 | return res; |
| 2819 | } |
| 2820 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2821 | static int _nfs4_do_setattr(struct inode *inode, |
| 2822 | struct nfs_setattrargs *arg, |
| 2823 | struct nfs_setattrres *res, |
| 2824 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2825 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2826 | { |
| 2827 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2828 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2829 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2830 | .rpc_argp = arg, |
| 2831 | .rpc_resp = res, |
| 2832 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2833 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2834 | struct rpc_cred *delegation_cred = NULL; |
| 2835 | unsigned long timestamp = jiffies; |
| 2836 | fmode_t fmode; |
| 2837 | bool truncate; |
| 2838 | int status; |
| 2839 | |
| 2840 | nfs_fattr_init(res->fattr); |
| 2841 | |
| 2842 | /* Servers should only apply open mode checks for file size changes */ |
| 2843 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2844 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2845 | |
| 2846 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2847 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2848 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2849 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2850 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2851 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2852 | l_ctx = nfs_get_lock_context(ctx); |
| 2853 | if (IS_ERR(l_ctx)) |
| 2854 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2855 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2856 | &arg->stateid, &delegation_cred); |
| 2857 | nfs_put_lock_context(l_ctx); |
| 2858 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2859 | return -EBADF; |
| 2860 | } else |
| 2861 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2862 | if (delegation_cred) |
| 2863 | msg.rpc_cred = delegation_cred; |
| 2864 | |
| 2865 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2866 | |
| 2867 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2868 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2869 | renew_lease(server, timestamp); |
| 2870 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2871 | return status; |
| 2872 | } |
| 2873 | |
| 2874 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2875 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2876 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2877 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2879 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2880 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2881 | struct nfs_setattrargs arg = { |
| 2882 | .fh = NFS_FH(inode), |
| 2883 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | .server = server, |
| 2885 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2886 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2887 | }; |
| 2888 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2890 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2892 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2893 | struct nfs4_exception exception = { |
| 2894 | .state = state, |
| 2895 | .inode = inode, |
| 2896 | .stateid = &arg.stateid, |
| 2897 | }; |
| 2898 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2900 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2901 | if (ilabel) |
| 2902 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2905 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2906 | switch (err) { |
| 2907 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2908 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2909 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2910 | "applying open mode checks to " |
| 2911 | "a SETATTR that is not " |
| 2912 | "changing file size.\n", |
| 2913 | server->nfs_client->cl_hostname); |
| 2914 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2915 | if (state && !(state->state & FMODE_WRITE)) { |
| 2916 | err = -EBADF; |
| 2917 | if (sattr->ia_valid & ATTR_OPEN) |
| 2918 | err = -EACCES; |
| 2919 | goto out; |
| 2920 | } |
| 2921 | } |
| 2922 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2924 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | return err; |
| 2926 | } |
| 2927 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2928 | static bool |
| 2929 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2930 | { |
| 2931 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2932 | return false; |
| 2933 | |
| 2934 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2935 | } |
| 2936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | struct nfs4_closedata { |
| 2938 | struct inode *inode; |
| 2939 | struct nfs4_state *state; |
| 2940 | struct nfs_closeargs arg; |
| 2941 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2942 | struct { |
| 2943 | struct nfs4_layoutreturn_args arg; |
| 2944 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 2945 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2946 | u32 roc_barrier; |
| 2947 | bool roc; |
| 2948 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2949 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2950 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | }; |
| 2952 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2953 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2954 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2955 | struct nfs4_closedata *calldata = data; |
| 2956 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2957 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2958 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2959 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 2960 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 2961 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2962 | nfs4_put_open_state(calldata->state); |
| 2963 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2964 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2965 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2966 | kfree(calldata); |
| 2967 | } |
| 2968 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2969 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2971 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2974 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2976 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2977 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2978 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2979 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2980 | |
| 2981 | /* Handle Layoutreturn errors */ |
| 2982 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 2983 | switch (calldata->res.lr_ret) { |
| 2984 | default: |
| 2985 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 2986 | break; |
| 2987 | case 0: |
| 2988 | calldata->arg.lr_args = NULL; |
| 2989 | calldata->res.lr_res = NULL; |
| 2990 | break; |
| 2991 | case -NFS4ERR_ADMIN_REVOKED: |
| 2992 | case -NFS4ERR_DELEG_REVOKED: |
| 2993 | case -NFS4ERR_EXPIRED: |
| 2994 | case -NFS4ERR_BAD_STATEID: |
| 2995 | case -NFS4ERR_OLD_STATEID: |
| 2996 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 2997 | case -NFS4ERR_WRONG_CRED: |
| 2998 | calldata->arg.lr_args = NULL; |
| 2999 | calldata->res.lr_res = NULL; |
| 3000 | calldata->res.lr_ret = 0; |
| 3001 | rpc_restart_call_prepare(task); |
| 3002 | return; |
| 3003 | } |
| 3004 | } |
| 3005 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3006 | /* 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] | 3007 | * the state_owner. we keep this around to process errors |
| 3008 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | switch (task->tk_status) { |
| 3010 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3011 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3012 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3013 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3014 | case -NFS4ERR_ACCESS: |
| 3015 | if (calldata->arg.bitmask != NULL) { |
| 3016 | calldata->arg.bitmask = NULL; |
| 3017 | calldata->res.fattr = NULL; |
| 3018 | task->tk_status = 0; |
| 3019 | rpc_restart_call_prepare(task); |
| 3020 | goto out_release; |
| 3021 | |
| 3022 | } |
| 3023 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3024 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3026 | case -NFS4ERR_EXPIRED: |
| 3027 | nfs4_free_revoked_stateid(server, |
| 3028 | &calldata->arg.stateid, |
| 3029 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3030 | case -NFS4ERR_OLD_STATEID: |
| 3031 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3032 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3033 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3034 | rpc_restart_call_prepare(task); |
| 3035 | goto out_release; |
| 3036 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3037 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3038 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3040 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3041 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3042 | goto out_release; |
| 3043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3045 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3046 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3047 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3048 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3049 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3050 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3053 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3055 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3056 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3057 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3058 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3059 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3060 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3061 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3062 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3063 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3064 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3065 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3066 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3067 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3068 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3069 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3070 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3071 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3072 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3073 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3074 | if (state->n_rdonly == 0) |
| 3075 | call_close |= is_rdonly; |
| 3076 | else if (is_rdonly) |
| 3077 | calldata->arg.fmode |= FMODE_READ; |
| 3078 | if (state->n_wronly == 0) |
| 3079 | call_close |= is_wronly; |
| 3080 | else if (is_wronly) |
| 3081 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3082 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3083 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3084 | } else if (is_rdwr) |
| 3085 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3086 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3087 | if (!nfs4_valid_open_stateid(state) || |
| 3088 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3089 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3090 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3091 | |
| 3092 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3093 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3094 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3095 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3096 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3097 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3098 | nfs_release_seqid(calldata->arg.seqid); |
| 3099 | goto out_wait; |
| 3100 | } |
| 3101 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3102 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3103 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3104 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3105 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3106 | /* Close-to-open cache consistency revalidation */ |
| 3107 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3108 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3109 | else |
| 3110 | calldata->arg.bitmask = NULL; |
| 3111 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3112 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3113 | calldata->arg.share_access = |
| 3114 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3115 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3116 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3117 | if (calldata->res.fattr == NULL) |
| 3118 | calldata->arg.bitmask = NULL; |
| 3119 | else if (calldata->arg.bitmask == NULL) |
| 3120 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3121 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3122 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3123 | &calldata->arg.seq_args, |
| 3124 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3125 | task) != 0) |
| 3126 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3127 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3128 | return; |
| 3129 | out_no_action: |
| 3130 | task->tk_action = NULL; |
| 3131 | out_wait: |
| 3132 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3135 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3136 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3137 | .rpc_call_done = nfs4_close_done, |
| 3138 | .rpc_release = nfs4_free_closedata, |
| 3139 | }; |
| 3140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | /* |
| 3142 | * It is possible for data to be read/written from a mem-mapped file |
| 3143 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3144 | * This means that we can't safely call nfsv4 close on a file until |
| 3145 | * the inode is cleared. This in turn means that we are not good |
| 3146 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3147 | * share state even when we are done with one of the three share |
| 3148 | * stateid's in the inode. |
| 3149 | * |
| 3150 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3151 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3152 | 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] | 3153 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3154 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3155 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3157 | struct nfs4_state_owner *sp = state->owner; |
| 3158 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3159 | struct rpc_message msg = { |
| 3160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3161 | .rpc_cred = state->owner->so_cred, |
| 3162 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3163 | struct rpc_task_setup task_setup_data = { |
| 3164 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3165 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3166 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3167 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3168 | .flags = RPC_TASK_ASYNC, |
| 3169 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3170 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3172 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3173 | &task_setup_data.rpc_client, &msg); |
| 3174 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3175 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3177 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3178 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3179 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3181 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3183 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3184 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3185 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3186 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3187 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3188 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3189 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3190 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3191 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3192 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3193 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3194 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3195 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3196 | if (calldata->lr.roc) { |
| 3197 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3198 | calldata->res.lr_res = &calldata->lr.res; |
| 3199 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3200 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3201 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3202 | msg.rpc_argp = &calldata->arg; |
| 3203 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3204 | task_setup_data.callback_data = calldata; |
| 3205 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3206 | if (IS_ERR(task)) |
| 3207 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3208 | status = 0; |
| 3209 | if (wait) |
| 3210 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3211 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3212 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3213 | out_free_calldata: |
| 3214 | kfree(calldata); |
| 3215 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3216 | nfs4_put_open_state(state); |
| 3217 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3218 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3221 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3222 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3223 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3226 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3227 | |
| 3228 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3230 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3231 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3232 | |
| 3233 | nfs4_label_release_security(label); |
| 3234 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3235 | if (IS_ERR(state)) |
| 3236 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3237 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3240 | 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] | 3241 | { |
| 3242 | if (ctx->state == NULL) |
| 3243 | return; |
| 3244 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3245 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3246 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3247 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3250 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3251 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3252 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3255 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3256 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3257 | struct nfs4_server_caps_arg args = { |
| 3258 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3259 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3260 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | struct nfs4_server_caps_res res = {}; |
| 3262 | struct rpc_message msg = { |
| 3263 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3264 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | .rpc_resp = &res, |
| 3266 | }; |
| 3267 | int status; |
| 3268 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3269 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3270 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3271 | FATTR4_WORD0_LINK_SUPPORT | |
| 3272 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3273 | FATTR4_WORD0_ACLSUPPORT; |
| 3274 | if (minorversion) |
| 3275 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3276 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3277 | 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] | 3278 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3279 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3280 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3281 | case 0: |
| 3282 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3283 | res.attr_bitmask[2] = 0; |
| 3284 | break; |
| 3285 | case 1: |
| 3286 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3287 | break; |
| 3288 | case 2: |
| 3289 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3292 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3293 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3294 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3295 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3296 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3297 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3298 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3299 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | server->caps |= NFS_CAP_ACLS; |
| 3301 | if (res.has_links != 0) |
| 3302 | server->caps |= NFS_CAP_HARDLINKS; |
| 3303 | if (res.has_symlinks != 0) |
| 3304 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3305 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3306 | server->caps |= NFS_CAP_FILEID; |
| 3307 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3308 | server->caps |= NFS_CAP_MODE; |
| 3309 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3310 | server->caps |= NFS_CAP_NLINK; |
| 3311 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3312 | server->caps |= NFS_CAP_OWNER; |
| 3313 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3314 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3315 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3316 | server->caps |= NFS_CAP_ATIME; |
| 3317 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3318 | server->caps |= NFS_CAP_CTIME; |
| 3319 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3320 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3321 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3322 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3323 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3324 | #endif |
| 3325 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3326 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3327 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3328 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3329 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3330 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3331 | 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] | 3332 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3333 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3334 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3336 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | return status; |
| 3340 | } |
| 3341 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3342 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | { |
| 3344 | struct nfs4_exception exception = { }; |
| 3345 | int err; |
| 3346 | do { |
| 3347 | err = nfs4_handle_exception(server, |
| 3348 | _nfs4_server_capabilities(server, fhandle), |
| 3349 | &exception); |
| 3350 | } while (exception.retry); |
| 3351 | return err; |
| 3352 | } |
| 3353 | |
| 3354 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3355 | struct nfs_fsinfo *info) |
| 3356 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3357 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3359 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | }; |
| 3361 | struct nfs4_lookup_res res = { |
| 3362 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3363 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | .fh = fhandle, |
| 3365 | }; |
| 3366 | struct rpc_message msg = { |
| 3367 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3368 | .rpc_argp = &args, |
| 3369 | .rpc_resp = &res, |
| 3370 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3371 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3372 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3373 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3374 | /* |
| 3375 | * Process the label in the upcoming getfattr |
| 3376 | */ |
| 3377 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3378 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3379 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3380 | 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] | 3381 | } |
| 3382 | |
| 3383 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3384 | struct nfs_fsinfo *info) |
| 3385 | { |
| 3386 | struct nfs4_exception exception = { }; |
| 3387 | int err; |
| 3388 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3389 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3390 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3391 | switch (err) { |
| 3392 | case 0: |
| 3393 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3394 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3395 | default: |
| 3396 | err = nfs4_handle_exception(server, err, &exception); |
| 3397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3399 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | return err; |
| 3401 | } |
| 3402 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3403 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3404 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3405 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3406 | struct rpc_auth_create_args auth_args = { |
| 3407 | .pseudoflavor = flavor, |
| 3408 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3409 | struct rpc_auth *auth; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3410 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3411 | auth = rpcauth_create(&auth_args, server->client); |
Anna Schumaker | 9df1336 | 2017-01-11 16:30:08 -0500 | [diff] [blame] | 3412 | if (IS_ERR(auth)) |
| 3413 | return -EACCES; |
| 3414 | return nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3415 | } |
| 3416 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3417 | /* |
| 3418 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3419 | * |
| 3420 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3421 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3422 | * |
| 3423 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3424 | * negative errno value. |
| 3425 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3426 | 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] | 3427 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3429 | /* Per 3530bis 15.33.5 */ |
| 3430 | static const rpc_authflavor_t flav_array[] = { |
| 3431 | RPC_AUTH_GSS_KRB5P, |
| 3432 | RPC_AUTH_GSS_KRB5I, |
| 3433 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3434 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3435 | RPC_AUTH_NULL, |
| 3436 | }; |
| 3437 | int status = -EPERM; |
| 3438 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3440 | if (server->auth_info.flavor_len > 0) { |
| 3441 | /* try each flavor specified by user */ |
| 3442 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3443 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3444 | server->auth_info.flavors[i]); |
| 3445 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3446 | continue; |
| 3447 | break; |
| 3448 | } |
| 3449 | } else { |
| 3450 | /* no flavors specified by user, try default list */ |
| 3451 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3452 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3453 | flav_array[i]); |
| 3454 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3455 | continue; |
| 3456 | break; |
| 3457 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3458 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3459 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3460 | /* |
| 3461 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3462 | * to access the mount. It could also mean that we tried to mount |
| 3463 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3464 | * existing mount programs don't handle -EACCES very well so it should |
| 3465 | * be mapped to -EPERM instead. |
| 3466 | */ |
| 3467 | if (status == -EACCES) |
| 3468 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3469 | return status; |
| 3470 | } |
| 3471 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3472 | /** |
| 3473 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3474 | * @server: initialized nfs_server handle |
| 3475 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3476 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3477 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3478 | * |
| 3479 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3480 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3481 | 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] | 3482 | struct nfs_fsinfo *info, |
| 3483 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3484 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3485 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3486 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3487 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3488 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3489 | |
| 3490 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3491 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3492 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | if (status == 0) |
| 3495 | status = nfs4_server_capabilities(server, fhandle); |
| 3496 | if (status == 0) |
| 3497 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3498 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3499 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3502 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3503 | struct nfs_fsinfo *info) |
| 3504 | { |
| 3505 | int error; |
| 3506 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3507 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3508 | |
| 3509 | error = nfs4_server_capabilities(server, mntfh); |
| 3510 | if (error < 0) { |
| 3511 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3512 | return error; |
| 3513 | } |
| 3514 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3515 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3516 | if (IS_ERR(label)) |
| 3517 | return PTR_ERR(label); |
| 3518 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3519 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3520 | if (error < 0) { |
| 3521 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3522 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3526 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3527 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3528 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3529 | err_free_label: |
| 3530 | nfs4_label_free(label); |
| 3531 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3532 | return error; |
| 3533 | } |
| 3534 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3535 | /* |
| 3536 | * Get locations and (maybe) other attributes of a referral. |
| 3537 | * Note that we'll actually follow the referral later when |
| 3538 | * we detect fsid mismatch in inode revalidation |
| 3539 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3540 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3541 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3542 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3543 | { |
| 3544 | int status = -ENOMEM; |
| 3545 | struct page *page = NULL; |
| 3546 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3547 | |
| 3548 | page = alloc_page(GFP_KERNEL); |
| 3549 | if (page == NULL) |
| 3550 | goto out; |
| 3551 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3552 | if (locations == NULL) |
| 3553 | goto out; |
| 3554 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3555 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3556 | if (status != 0) |
| 3557 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3558 | |
| 3559 | /* |
| 3560 | * If the fsid didn't change, this is a migration event, not a |
| 3561 | * referral. Cause us to drop into the exception handler, which |
| 3562 | * will kick off migration recovery. |
| 3563 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3564 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3565 | dprintk("%s: server did not return a different fsid for" |
| 3566 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3567 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3568 | goto out; |
| 3569 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3570 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3571 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3572 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3573 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3574 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3575 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3576 | out: |
| 3577 | if (page) |
| 3578 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3579 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3580 | return status; |
| 3581 | } |
| 3582 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3583 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3584 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | { |
| 3586 | struct nfs4_getattr_arg args = { |
| 3587 | .fh = fhandle, |
| 3588 | .bitmask = server->attr_bitmask, |
| 3589 | }; |
| 3590 | struct nfs4_getattr_res res = { |
| 3591 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3592 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | .server = server, |
| 3594 | }; |
| 3595 | struct rpc_message msg = { |
| 3596 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3597 | .rpc_argp = &args, |
| 3598 | .rpc_resp = &res, |
| 3599 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3600 | |
| 3601 | args.bitmask = nfs4_bitmask(server, label); |
| 3602 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3603 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3604 | 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] | 3605 | } |
| 3606 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3607 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3608 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | { |
| 3610 | struct nfs4_exception exception = { }; |
| 3611 | int err; |
| 3612 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3613 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3614 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3615 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | &exception); |
| 3617 | } while (exception.retry); |
| 3618 | return err; |
| 3619 | } |
| 3620 | |
| 3621 | /* |
| 3622 | * The file is not closed if it is opened due to the a request to change |
| 3623 | * the size of the file. The open call will not be needed once the |
| 3624 | * VFS layer lookup-intents are implemented. |
| 3625 | * |
| 3626 | * Close is called when the inode is destroyed. |
| 3627 | * If we haven't opened the file for O_WRONLY, we |
| 3628 | * need to in the size_change case to obtain a stateid. |
| 3629 | * |
| 3630 | * Got race? |
| 3631 | * Because OPEN is always done by name in nfsv4, it is |
| 3632 | * possible that we opened a different file by the same |
| 3633 | * name. We can recognize this race condition, but we |
| 3634 | * can't do anything about it besides returning an error. |
| 3635 | * |
| 3636 | * This will be fixed with VFS changes (lookup-intent). |
| 3637 | */ |
| 3638 | static int |
| 3639 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3640 | struct iattr *sattr) |
| 3641 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3642 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3643 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3644 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3645 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | int status; |
| 3647 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3648 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3649 | sattr->ia_valid & ATTR_SIZE && |
| 3650 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3651 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3652 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3653 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3655 | /* Deal with open(O_TRUNC) */ |
| 3656 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3657 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3658 | |
| 3659 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3660 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3661 | return 0; |
| 3662 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3663 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3664 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3665 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3666 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3667 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3668 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3669 | } |
| 3670 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3671 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3672 | if (IS_ERR(label)) |
| 3673 | return PTR_ERR(label); |
| 3674 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3675 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3676 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3677 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3678 | nfs_setsecurity(inode, fattr, label); |
| 3679 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3680 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | return status; |
| 3682 | } |
| 3683 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3684 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3685 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3686 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3687 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3688 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3689 | int status; |
| 3690 | struct nfs4_lookup_arg args = { |
| 3691 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3692 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3693 | .name = name, |
| 3694 | }; |
| 3695 | struct nfs4_lookup_res res = { |
| 3696 | .server = server, |
| 3697 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3698 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3699 | .fh = fhandle, |
| 3700 | }; |
| 3701 | struct rpc_message msg = { |
| 3702 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3703 | .rpc_argp = &args, |
| 3704 | .rpc_resp = &res, |
| 3705 | }; |
| 3706 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3707 | args.bitmask = nfs4_bitmask(server, label); |
| 3708 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3709 | nfs_fattr_init(fattr); |
| 3710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3712 | 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] | 3713 | dprintk("NFS reply lookup: %d\n", status); |
| 3714 | return status; |
| 3715 | } |
| 3716 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3717 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3718 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3719 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3720 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3721 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3722 | fattr->nlink = 2; |
| 3723 | } |
| 3724 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3725 | 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] | 3726 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3727 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3728 | { |
| 3729 | struct nfs4_exception exception = { }; |
| 3730 | struct rpc_clnt *client = *clnt; |
| 3731 | int err; |
| 3732 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3733 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3734 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3735 | switch (err) { |
| 3736 | case -NFS4ERR_BADNAME: |
| 3737 | err = -ENOENT; |
| 3738 | goto out; |
| 3739 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3740 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3741 | if (err == -NFS4ERR_MOVED) |
| 3742 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3743 | goto out; |
| 3744 | case -NFS4ERR_WRONGSEC: |
| 3745 | err = -EPERM; |
| 3746 | if (client != *clnt) |
| 3747 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3748 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3749 | if (IS_ERR(client)) |
| 3750 | return PTR_ERR(client); |
| 3751 | |
| 3752 | exception.retry = 1; |
| 3753 | break; |
| 3754 | default: |
| 3755 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3756 | } |
| 3757 | } while (exception.retry); |
| 3758 | |
| 3759 | out: |
| 3760 | if (err == 0) |
| 3761 | *clnt = client; |
| 3762 | else if (client != *clnt) |
| 3763 | rpc_shutdown_client(client); |
| 3764 | |
| 3765 | return err; |
| 3766 | } |
| 3767 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3768 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3769 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3770 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3772 | int status; |
| 3773 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3774 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3775 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3776 | if (client != NFS_CLIENT(dir)) { |
| 3777 | rpc_shutdown_client(client); |
| 3778 | nfs_fixup_secinfo_attributes(fattr); |
| 3779 | } |
| 3780 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | } |
| 3782 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3783 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3784 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3785 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3786 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3787 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3788 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3789 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3790 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3791 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3792 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3793 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3794 | } |
| 3795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3797 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3798 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | struct nfs4_accessargs args = { |
| 3800 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3801 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3803 | struct nfs4_accessres res = { |
| 3804 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3805 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | struct rpc_message msg = { |
| 3807 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3808 | .rpc_argp = &args, |
| 3809 | .rpc_resp = &res, |
| 3810 | .rpc_cred = entry->cred, |
| 3811 | }; |
| 3812 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3813 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
| 3815 | /* |
| 3816 | * Determine which access bits we want to ask for... |
| 3817 | */ |
| 3818 | if (mode & MAY_READ) |
| 3819 | args.access |= NFS4_ACCESS_READ; |
| 3820 | if (S_ISDIR(inode->i_mode)) { |
| 3821 | if (mode & MAY_WRITE) |
| 3822 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3823 | if (mode & MAY_EXEC) |
| 3824 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3825 | } else { |
| 3826 | if (mode & MAY_WRITE) |
| 3827 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3828 | if (mode & MAY_EXEC) |
| 3829 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3830 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3831 | |
| 3832 | res.fattr = nfs_alloc_fattr(); |
| 3833 | if (res.fattr == NULL) |
| 3834 | return -ENOMEM; |
| 3835 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3836 | 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] | 3837 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3838 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3839 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3841 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | return status; |
| 3843 | } |
| 3844 | |
| 3845 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3846 | { |
| 3847 | struct nfs4_exception exception = { }; |
| 3848 | int err; |
| 3849 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3850 | err = _nfs4_proc_access(inode, entry); |
| 3851 | trace_nfs4_access(inode, err); |
| 3852 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | &exception); |
| 3854 | } while (exception.retry); |
| 3855 | return err; |
| 3856 | } |
| 3857 | |
| 3858 | /* |
| 3859 | * TODO: For the time being, we don't try to get any attributes |
| 3860 | * along with any of the zero-copy operations READ, READDIR, |
| 3861 | * READLINK, WRITE. |
| 3862 | * |
| 3863 | * In the case of the first three, we want to put the GETATTR |
| 3864 | * after the read-type operation -- this is because it is hard |
| 3865 | * to predict the length of a GETATTR response in v4, and thus |
| 3866 | * align the READ data correctly. This means that the GETATTR |
| 3867 | * may end up partially falling into the page cache, and we should |
| 3868 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3869 | * To do this efficiently, we need to know the total length |
| 3870 | * of data received, which doesn't seem to be available outside |
| 3871 | * of the RPC layer. |
| 3872 | * |
| 3873 | * In the case of WRITE, we also want to put the GETATTR after |
| 3874 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3875 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | * |
| 3877 | * Both of these changes to the XDR layer would in fact be quite |
| 3878 | * minor, but I decided to leave them for a subsequent patch. |
| 3879 | */ |
| 3880 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3881 | unsigned int pgbase, unsigned int pglen) |
| 3882 | { |
| 3883 | struct nfs4_readlink args = { |
| 3884 | .fh = NFS_FH(inode), |
| 3885 | .pgbase = pgbase, |
| 3886 | .pglen = pglen, |
| 3887 | .pages = &page, |
| 3888 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3889 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | struct rpc_message msg = { |
| 3891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3892 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3893 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | }; |
| 3895 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3896 | 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] | 3897 | } |
| 3898 | |
| 3899 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3900 | unsigned int pgbase, unsigned int pglen) |
| 3901 | { |
| 3902 | struct nfs4_exception exception = { }; |
| 3903 | int err; |
| 3904 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3905 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3906 | trace_nfs4_readlink(inode, err); |
| 3907 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | &exception); |
| 3909 | } while (exception.retry); |
| 3910 | return err; |
| 3911 | } |
| 3912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3914 | * 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] | 3915 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | static int |
| 3917 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3918 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3920 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3921 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3922 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | int status = 0; |
| 3925 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3926 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3927 | if (IS_ERR(ctx)) |
| 3928 | return PTR_ERR(ctx); |
| 3929 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3930 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3931 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3932 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 3933 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3934 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | if (IS_ERR(state)) { |
| 3936 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3937 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3940 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3941 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | return status; |
| 3943 | } |
| 3944 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3945 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3947 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3948 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3950 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3952 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3953 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3954 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3957 | .rpc_argp = &args, |
| 3958 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 3960 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3961 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3962 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3963 | 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] | 3964 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 3965 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | return status; |
| 3967 | } |
| 3968 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3969 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | { |
| 3971 | struct nfs4_exception exception = { }; |
| 3972 | int err; |
| 3973 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3974 | err = _nfs4_proc_remove(dir, name); |
| 3975 | trace_nfs4_remove(dir, name, err); |
| 3976 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | &exception); |
| 3978 | } while (exception.retry); |
| 3979 | return err; |
| 3980 | } |
| 3981 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3982 | 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] | 3983 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3984 | struct nfs_server *server = NFS_SERVER(dir); |
| 3985 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3986 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3988 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3990 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3991 | |
| 3992 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3995 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3996 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3997 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3998 | &data->args.seq_args, |
| 3999 | &data->res.seq_res, |
| 4000 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4003 | 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] | 4004 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4005 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4006 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4007 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4008 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4009 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4010 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4011 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4012 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4013 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4014 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4015 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4018 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4019 | { |
| 4020 | struct nfs_server *server = NFS_SERVER(dir); |
| 4021 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4022 | struct nfs_renameres *res = msg->rpc_resp; |
| 4023 | |
| 4024 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4025 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4026 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4027 | } |
| 4028 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4029 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4030 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4031 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4032 | &data->args.seq_args, |
| 4033 | &data->res.seq_res, |
| 4034 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4038 | struct inode *new_dir) |
| 4039 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4040 | struct nfs_renamedata *data = task->tk_calldata; |
| 4041 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4042 | |
| 4043 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4044 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4045 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4046 | return 0; |
| 4047 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4048 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4049 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4050 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4051 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4052 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4053 | return 1; |
| 4054 | } |
| 4055 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4056 | 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] | 4057 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4058 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | struct nfs4_link_arg arg = { |
| 4060 | .fh = NFS_FH(inode), |
| 4061 | .dir_fh = NFS_FH(dir), |
| 4062 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4063 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4065 | struct nfs4_link_res res = { |
| 4066 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4067 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4068 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | struct rpc_message msg = { |
| 4070 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4071 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4072 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4074 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4076 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4077 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4078 | goto out; |
| 4079 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4080 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4081 | if (IS_ERR(res.label)) { |
| 4082 | status = PTR_ERR(res.label); |
| 4083 | goto out; |
| 4084 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4085 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4086 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4087 | 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] | 4088 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4089 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4090 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4091 | if (!status) |
| 4092 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4093 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4094 | |
| 4095 | |
| 4096 | nfs4_label_free(res.label); |
| 4097 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4098 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4099 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | return status; |
| 4101 | } |
| 4102 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4103 | 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] | 4104 | { |
| 4105 | struct nfs4_exception exception = { }; |
| 4106 | int err; |
| 4107 | do { |
| 4108 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4109 | _nfs4_proc_link(inode, dir, name), |
| 4110 | &exception); |
| 4111 | } while (exception.retry); |
| 4112 | return err; |
| 4113 | } |
| 4114 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4115 | struct nfs4_createdata { |
| 4116 | struct rpc_message msg; |
| 4117 | struct nfs4_create_arg arg; |
| 4118 | struct nfs4_create_res res; |
| 4119 | struct nfs_fh fh; |
| 4120 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4121 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4122 | }; |
| 4123 | |
| 4124 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4125 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4126 | { |
| 4127 | struct nfs4_createdata *data; |
| 4128 | |
| 4129 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4130 | if (data != NULL) { |
| 4131 | struct nfs_server *server = NFS_SERVER(dir); |
| 4132 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4133 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4134 | if (IS_ERR(data->label)) |
| 4135 | goto out_free; |
| 4136 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4137 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4138 | data->msg.rpc_argp = &data->arg; |
| 4139 | data->msg.rpc_resp = &data->res; |
| 4140 | data->arg.dir_fh = NFS_FH(dir); |
| 4141 | data->arg.server = server; |
| 4142 | data->arg.name = name; |
| 4143 | data->arg.attrs = sattr; |
| 4144 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4145 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4146 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4147 | data->res.server = server; |
| 4148 | data->res.fh = &data->fh; |
| 4149 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4150 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4151 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4152 | } |
| 4153 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4154 | out_free: |
| 4155 | kfree(data); |
| 4156 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4160 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4161 | 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] | 4162 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4163 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4164 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4165 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4166 | 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] | 4167 | } |
| 4168 | return status; |
| 4169 | } |
| 4170 | |
| 4171 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4172 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4173 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4174 | kfree(data); |
| 4175 | } |
| 4176 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4177 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4178 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4179 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4181 | struct nfs4_createdata *data; |
| 4182 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4184 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4185 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4186 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4187 | status = -ENOMEM; |
| 4188 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4189 | if (data == NULL) |
| 4190 | goto out; |
| 4191 | |
| 4192 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4193 | data->arg.u.symlink.pages = &page; |
| 4194 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4195 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4197 | status = nfs4_do_create(dir, dentry, data); |
| 4198 | |
| 4199 | nfs4_free_createdata(data); |
| 4200 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | return status; |
| 4202 | } |
| 4203 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4204 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4205 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | { |
| 4207 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4208 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4210 | |
| 4211 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4214 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4215 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4216 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | &exception); |
| 4218 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4219 | |
| 4220 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | return err; |
| 4222 | } |
| 4223 | |
| 4224 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4225 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4227 | struct nfs4_createdata *data; |
| 4228 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4230 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4231 | if (data == NULL) |
| 4232 | goto out; |
| 4233 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4234 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4235 | status = nfs4_do_create(dir, dentry, data); |
| 4236 | |
| 4237 | nfs4_free_createdata(data); |
| 4238 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | return status; |
| 4240 | } |
| 4241 | |
| 4242 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4243 | struct iattr *sattr) |
| 4244 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4245 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4247 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4249 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4250 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4251 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4252 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4253 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4255 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4256 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4257 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | &exception); |
| 4259 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4260 | nfs4_label_release_security(label); |
| 4261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | return err; |
| 4263 | } |
| 4264 | |
| 4265 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4266 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4268 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | struct nfs4_readdir_arg args = { |
| 4270 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4271 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | .pgbase = 0, |
| 4273 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4274 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4275 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | }; |
| 4277 | struct nfs4_readdir_res res; |
| 4278 | struct rpc_message msg = { |
| 4279 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4280 | .rpc_argp = &args, |
| 4281 | .rpc_resp = &res, |
| 4282 | .rpc_cred = cred, |
| 4283 | }; |
| 4284 | int status; |
| 4285 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4286 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4287 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4288 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4289 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4291 | 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] | 4292 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4293 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4294 | status += args.pgbase; |
| 4295 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4296 | |
| 4297 | nfs_invalidate_atime(dir); |
| 4298 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4299 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | return status; |
| 4301 | } |
| 4302 | |
| 4303 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4304 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | { |
| 4306 | struct nfs4_exception exception = { }; |
| 4307 | int err; |
| 4308 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4309 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4310 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4311 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4312 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | &exception); |
| 4314 | } while (exception.retry); |
| 4315 | return err; |
| 4316 | } |
| 4317 | |
| 4318 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4319 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4321 | struct nfs4_createdata *data; |
| 4322 | int mode = sattr->ia_mode; |
| 4323 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4325 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4326 | if (data == NULL) |
| 4327 | goto out; |
| 4328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4330 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4332 | data->arg.ftype = NF4BLK; |
| 4333 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4334 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | } |
| 4336 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4337 | data->arg.ftype = NF4CHR; |
| 4338 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4339 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4340 | } else if (!S_ISSOCK(mode)) { |
| 4341 | status = -EINVAL; |
| 4342 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4344 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4345 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4346 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4347 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4348 | nfs4_free_createdata(data); |
| 4349 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | return status; |
| 4351 | } |
| 4352 | |
| 4353 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4354 | struct iattr *sattr, dev_t rdev) |
| 4355 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4356 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4358 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4360 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4361 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4362 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4363 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4364 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4366 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4367 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4368 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | &exception); |
| 4370 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4371 | |
| 4372 | nfs4_label_release_security(label); |
| 4373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | return err; |
| 4375 | } |
| 4376 | |
| 4377 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4378 | struct nfs_fsstat *fsstat) |
| 4379 | { |
| 4380 | struct nfs4_statfs_arg args = { |
| 4381 | .fh = fhandle, |
| 4382 | .bitmask = server->attr_bitmask, |
| 4383 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4384 | struct nfs4_statfs_res res = { |
| 4385 | .fsstat = fsstat, |
| 4386 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | struct rpc_message msg = { |
| 4388 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4389 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4390 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | }; |
| 4392 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4393 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4394 | 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] | 4395 | } |
| 4396 | |
| 4397 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4398 | { |
| 4399 | struct nfs4_exception exception = { }; |
| 4400 | int err; |
| 4401 | do { |
| 4402 | err = nfs4_handle_exception(server, |
| 4403 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4404 | &exception); |
| 4405 | } while (exception.retry); |
| 4406 | return err; |
| 4407 | } |
| 4408 | |
| 4409 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4410 | struct nfs_fsinfo *fsinfo) |
| 4411 | { |
| 4412 | struct nfs4_fsinfo_arg args = { |
| 4413 | .fh = fhandle, |
| 4414 | .bitmask = server->attr_bitmask, |
| 4415 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4416 | struct nfs4_fsinfo_res res = { |
| 4417 | .fsinfo = fsinfo, |
| 4418 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | struct rpc_message msg = { |
| 4420 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4421 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4422 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | }; |
| 4424 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4425 | 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] | 4426 | } |
| 4427 | |
| 4428 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4429 | { |
| 4430 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4431 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | int err; |
| 4433 | |
| 4434 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4435 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4436 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4437 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4438 | nfs4_set_lease_period(server->nfs_client, |
| 4439 | fsinfo->lease_time * HZ, |
| 4440 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4441 | break; |
| 4442 | } |
| 4443 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } while (exception.retry); |
| 4445 | return err; |
| 4446 | } |
| 4447 | |
| 4448 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4449 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4450 | int error; |
| 4451 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4452 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4453 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4454 | if (error == 0) { |
| 4455 | /* block layout checks this! */ |
| 4456 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4457 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4458 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4459 | |
| 4460 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4464 | struct nfs_pathconf *pathconf) |
| 4465 | { |
| 4466 | struct nfs4_pathconf_arg args = { |
| 4467 | .fh = fhandle, |
| 4468 | .bitmask = server->attr_bitmask, |
| 4469 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4470 | struct nfs4_pathconf_res res = { |
| 4471 | .pathconf = pathconf, |
| 4472 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | struct rpc_message msg = { |
| 4474 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4475 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4476 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | }; |
| 4478 | |
| 4479 | /* None of the pathconf attributes are mandatory to implement */ |
| 4480 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4481 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4482 | return 0; |
| 4483 | } |
| 4484 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4485 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4486 | 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] | 4487 | } |
| 4488 | |
| 4489 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4490 | struct nfs_pathconf *pathconf) |
| 4491 | { |
| 4492 | struct nfs4_exception exception = { }; |
| 4493 | int err; |
| 4494 | |
| 4495 | do { |
| 4496 | err = nfs4_handle_exception(server, |
| 4497 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4498 | &exception); |
| 4499 | } while (exception.retry); |
| 4500 | return err; |
| 4501 | } |
| 4502 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4503 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4504 | const struct nfs_open_context *ctx, |
| 4505 | const struct nfs_lock_context *l_ctx, |
| 4506 | fmode_t fmode) |
| 4507 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4508 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4509 | } |
| 4510 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4511 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4512 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4513 | const struct nfs_open_context *ctx, |
| 4514 | const struct nfs_lock_context *l_ctx, |
| 4515 | fmode_t fmode) |
| 4516 | { |
| 4517 | nfs4_stateid current_stateid; |
| 4518 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4519 | /* If the current stateid represents a lost lock, then exit */ |
| 4520 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4521 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4522 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4523 | } |
| 4524 | |
| 4525 | static bool nfs4_error_stateid_expired(int err) |
| 4526 | { |
| 4527 | switch (err) { |
| 4528 | case -NFS4ERR_DELEG_REVOKED: |
| 4529 | case -NFS4ERR_ADMIN_REVOKED: |
| 4530 | case -NFS4ERR_BAD_STATEID: |
| 4531 | case -NFS4ERR_STALE_STATEID: |
| 4532 | case -NFS4ERR_OLD_STATEID: |
| 4533 | case -NFS4ERR_OPENMODE: |
| 4534 | case -NFS4ERR_EXPIRED: |
| 4535 | return true; |
| 4536 | } |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4540 | 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] | 4541 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4542 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4544 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4545 | if (task->tk_status < 0) { |
| 4546 | struct nfs4_exception exception = { |
| 4547 | .inode = hdr->inode, |
| 4548 | .state = hdr->args.context->state, |
| 4549 | .stateid = &hdr->args.stateid, |
| 4550 | }; |
| 4551 | task->tk_status = nfs4_async_handle_exception(task, |
| 4552 | server, task->tk_status, &exception); |
| 4553 | if (exception.retry) { |
| 4554 | rpc_restart_call_prepare(task); |
| 4555 | return -EAGAIN; |
| 4556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4560 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4561 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4564 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4565 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4566 | { |
| 4567 | |
| 4568 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4569 | nfs4_stateid_is_current(&args->stateid, |
| 4570 | args->context, |
| 4571 | args->lock_context, |
| 4572 | FMODE_READ)) |
| 4573 | return false; |
| 4574 | rpc_restart_call_prepare(task); |
| 4575 | return true; |
| 4576 | } |
| 4577 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4578 | 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] | 4579 | { |
| 4580 | |
| 4581 | dprintk("--> %s\n", __func__); |
| 4582 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4583 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4584 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4585 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4586 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4587 | if (task->tk_status > 0) |
| 4588 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4589 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4590 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4593 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4594 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4596 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4597 | if (!hdr->pgio_done_cb) |
| 4598 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4599 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4600 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4603 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4604 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4605 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4606 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4607 | &hdr->args.seq_args, |
| 4608 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4609 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4610 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4611 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4612 | hdr->args.lock_context, |
| 4613 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4614 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4615 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4616 | return -EIO; |
| 4617 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | } |
| 4619 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4620 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4621 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4623 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4624 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4625 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4626 | if (task->tk_status < 0) { |
| 4627 | struct nfs4_exception exception = { |
| 4628 | .inode = hdr->inode, |
| 4629 | .state = hdr->args.context->state, |
| 4630 | .stateid = &hdr->args.stateid, |
| 4631 | }; |
| 4632 | task->tk_status = nfs4_async_handle_exception(task, |
| 4633 | NFS_SERVER(inode), task->tk_status, |
| 4634 | &exception); |
| 4635 | if (exception.retry) { |
| 4636 | rpc_restart_call_prepare(task); |
| 4637 | return -EAGAIN; |
| 4638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4640 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4641 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4642 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4643 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4644 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4647 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4648 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4649 | { |
| 4650 | |
| 4651 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4652 | nfs4_stateid_is_current(&args->stateid, |
| 4653 | args->context, |
| 4654 | args->lock_context, |
| 4655 | FMODE_WRITE)) |
| 4656 | return false; |
| 4657 | rpc_restart_call_prepare(task); |
| 4658 | return true; |
| 4659 | } |
| 4660 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | 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] | 4662 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4663 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4664 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4665 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4666 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4667 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4668 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4671 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4672 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4673 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4674 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4676 | return false; |
| 4677 | /* Otherwise, request attributes if and only if we don't hold |
| 4678 | * a delegation |
| 4679 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4680 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4681 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4682 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4683 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4684 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4686 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4687 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4688 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4689 | hdr->args.bitmask = NULL; |
| 4690 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4691 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4692 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4693 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4694 | if (!hdr->pgio_done_cb) |
| 4695 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4696 | hdr->res.server = server; |
| 4697 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4699 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4700 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4703 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4704 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4705 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4706 | &data->args.seq_args, |
| 4707 | &data->res.seq_res, |
| 4708 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | } |
| 4710 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4711 | 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] | 4712 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4714 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4715 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4716 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4717 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4718 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4719 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4721 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4724 | 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] | 4725 | { |
| 4726 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4727 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4728 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4731 | 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] | 4732 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4733 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4734 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4735 | if (data->commit_done_cb == NULL) |
| 4736 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4737 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4738 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4739 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4742 | struct nfs4_renewdata { |
| 4743 | struct nfs_client *client; |
| 4744 | unsigned long timestamp; |
| 4745 | }; |
| 4746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | /* |
| 4748 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4749 | * standalone procedure for queueing an asynchronous RENEW. |
| 4750 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4751 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4752 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4753 | struct nfs4_renewdata *data = calldata; |
| 4754 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4755 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4756 | if (atomic_read(&clp->cl_count) > 1) |
| 4757 | nfs4_schedule_state_renewal(clp); |
| 4758 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4759 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4762 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4764 | struct nfs4_renewdata *data = calldata; |
| 4765 | struct nfs_client *clp = data->client; |
| 4766 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4768 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4769 | switch (task->tk_status) { |
| 4770 | case 0: |
| 4771 | break; |
| 4772 | case -NFS4ERR_LEASE_MOVED: |
| 4773 | nfs4_schedule_lease_moved_recovery(clp); |
| 4774 | break; |
| 4775 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4776 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4777 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4778 | return; |
| 4779 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4780 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4781 | return; |
| 4782 | } |
| 4783 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4785 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4788 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4789 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4790 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4791 | }; |
| 4792 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4793 | 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] | 4794 | { |
| 4795 | struct rpc_message msg = { |
| 4796 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4797 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4798 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4800 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4802 | if (renew_flags == 0) |
| 4803 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4804 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4805 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4806 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4807 | if (data == NULL) |
| 4808 | return -ENOMEM; |
| 4809 | data->client = clp; |
| 4810 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4811 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4812 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4815 | 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] | 4816 | { |
| 4817 | struct rpc_message msg = { |
| 4818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4819 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4820 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | }; |
| 4822 | unsigned long now = jiffies; |
| 4823 | int status; |
| 4824 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4825 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | if (status < 0) |
| 4827 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4828 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | return 0; |
| 4830 | } |
| 4831 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4832 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4833 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4834 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4837 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4838 | * 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] | 4839 | * the stack. |
| 4840 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4841 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4842 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4843 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4844 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4845 | { |
| 4846 | struct page *newpage, **spages; |
| 4847 | int rc = 0; |
| 4848 | size_t len; |
| 4849 | spages = pages; |
| 4850 | |
| 4851 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4852 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4853 | newpage = alloc_page(GFP_KERNEL); |
| 4854 | |
| 4855 | if (newpage == NULL) |
| 4856 | goto unwind; |
| 4857 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 4858 | buf += len; |
| 4859 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4860 | *pages++ = newpage; |
| 4861 | rc++; |
| 4862 | } while (buflen != 0); |
| 4863 | |
| 4864 | return rc; |
| 4865 | |
| 4866 | unwind: |
| 4867 | for(; rc > 0; rc--) |
| 4868 | __free_page(spages[rc-1]); |
| 4869 | return -ENOMEM; |
| 4870 | } |
| 4871 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4872 | struct nfs4_cached_acl { |
| 4873 | int cached; |
| 4874 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4875 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4876 | }; |
| 4877 | |
| 4878 | 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] | 4879 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4880 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4881 | |
| 4882 | spin_lock(&inode->i_lock); |
| 4883 | kfree(nfsi->nfs4_acl); |
| 4884 | nfsi->nfs4_acl = acl; |
| 4885 | spin_unlock(&inode->i_lock); |
| 4886 | } |
| 4887 | |
| 4888 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4889 | { |
| 4890 | nfs4_set_cached_acl(inode, NULL); |
| 4891 | } |
| 4892 | |
| 4893 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4894 | { |
| 4895 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4896 | struct nfs4_cached_acl *acl; |
| 4897 | int ret = -ENOENT; |
| 4898 | |
| 4899 | spin_lock(&inode->i_lock); |
| 4900 | acl = nfsi->nfs4_acl; |
| 4901 | if (acl == NULL) |
| 4902 | goto out; |
| 4903 | if (buf == NULL) /* user is just asking for length */ |
| 4904 | goto out_len; |
| 4905 | if (acl->cached == 0) |
| 4906 | goto out; |
| 4907 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4908 | if (acl->len > buflen) |
| 4909 | goto out; |
| 4910 | memcpy(buf, acl->data, acl->len); |
| 4911 | out_len: |
| 4912 | ret = acl->len; |
| 4913 | out: |
| 4914 | spin_unlock(&inode->i_lock); |
| 4915 | return ret; |
| 4916 | } |
| 4917 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4918 | 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] | 4919 | { |
| 4920 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4921 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4922 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4923 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4924 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4925 | if (acl == NULL) |
| 4926 | goto out; |
| 4927 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4928 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4929 | } else { |
| 4930 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4931 | if (acl == NULL) |
| 4932 | goto out; |
| 4933 | acl->cached = 0; |
| 4934 | } |
| 4935 | acl->len = acl_len; |
| 4936 | out: |
| 4937 | nfs4_set_cached_acl(inode, acl); |
| 4938 | } |
| 4939 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4940 | /* |
| 4941 | * The getxattr API returns the required buffer length when called with a |
| 4942 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4943 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4944 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4945 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4946 | * the cache. If not so, we throw away the page, and cache the required |
| 4947 | * length. The next getxattr call will then produce another round trip to |
| 4948 | * the server, this time with the input buf of the required size. |
| 4949 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4950 | 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] | 4951 | { |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 4952 | struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4953 | struct nfs_getaclargs args = { |
| 4954 | .fh = NFS_FH(inode), |
| 4955 | .acl_pages = pages, |
| 4956 | .acl_len = buflen, |
| 4957 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4958 | struct nfs_getaclres res = { |
| 4959 | .acl_len = buflen, |
| 4960 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4961 | struct rpc_message msg = { |
| 4962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4963 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4964 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4965 | }; |
Weston Andros Adamson | ed92d8c | 2017-02-23 14:54:21 -0500 | [diff] [blame] | 4966 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4967 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4968 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4969 | if (npages > ARRAY_SIZE(pages)) |
| 4970 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4971 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4972 | for (i = 0; i < npages; i++) { |
| 4973 | pages[i] = alloc_page(GFP_KERNEL); |
| 4974 | if (!pages[i]) |
| 4975 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4976 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4977 | |
| 4978 | /* for decoding across pages */ |
| 4979 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4980 | if (!res.acl_scratch) |
| 4981 | goto out_free; |
| 4982 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4983 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4984 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4985 | 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] | 4986 | __func__, buf, buflen, npages, args.acl_len); |
| 4987 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4988 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4989 | if (ret) |
| 4990 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4991 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4992 | /* Handle the case where the passed-in buffer is too short */ |
| 4993 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4994 | /* Did the user only issue a request for the acl length? */ |
| 4995 | if (buf == NULL) |
| 4996 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4997 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4998 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4999 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5000 | 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] | 5001 | if (buf) { |
| 5002 | if (res.acl_len > buflen) { |
| 5003 | ret = -ERANGE; |
| 5004 | goto out_free; |
| 5005 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5006 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5007 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5008 | out_ok: |
| 5009 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5010 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5011 | for (i = 0; i < npages; i++) |
| 5012 | if (pages[i]) |
| 5013 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5014 | if (res.acl_scratch) |
| 5015 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5016 | return ret; |
| 5017 | } |
| 5018 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5019 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5020 | { |
| 5021 | struct nfs4_exception exception = { }; |
| 5022 | ssize_t ret; |
| 5023 | do { |
| 5024 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5025 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5026 | if (ret >= 0) |
| 5027 | break; |
| 5028 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5029 | } while (exception.retry); |
| 5030 | return ret; |
| 5031 | } |
| 5032 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5033 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5034 | { |
| 5035 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5036 | int ret; |
| 5037 | |
| 5038 | if (!nfs4_server_supports_acls(server)) |
| 5039 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5040 | ret = nfs_revalidate_inode(server, inode); |
| 5041 | if (ret < 0) |
| 5042 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5043 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5044 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5045 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5046 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5047 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5048 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5049 | return ret; |
| 5050 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5053 | 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] | 5054 | { |
| 5055 | struct nfs_server *server = NFS_SERVER(inode); |
| 5056 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5057 | struct nfs_setaclargs arg = { |
| 5058 | .fh = NFS_FH(inode), |
| 5059 | .acl_pages = pages, |
| 5060 | .acl_len = buflen, |
| 5061 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5062 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5063 | struct rpc_message msg = { |
| 5064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5065 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5066 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5067 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5068 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5069 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5070 | |
| 5071 | if (!nfs4_server_supports_acls(server)) |
| 5072 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5073 | if (npages > ARRAY_SIZE(pages)) |
| 5074 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5075 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5076 | if (i < 0) |
| 5077 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5078 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5079 | 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] | 5080 | |
| 5081 | /* |
| 5082 | * Free each page after tx, so the only ref left is |
| 5083 | * held by the network stack |
| 5084 | */ |
| 5085 | for (; i > 0; i--) |
| 5086 | put_page(pages[i-1]); |
| 5087 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5088 | /* |
| 5089 | * Acl update can result in inode attribute update. |
| 5090 | * so mark the attribute cache invalid. |
| 5091 | */ |
| 5092 | spin_lock(&inode->i_lock); |
| 5093 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5094 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5095 | nfs_access_zap_cache(inode); |
| 5096 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5097 | return ret; |
| 5098 | } |
| 5099 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5100 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5101 | { |
| 5102 | struct nfs4_exception exception = { }; |
| 5103 | int err; |
| 5104 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5105 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5106 | trace_nfs4_set_acl(inode, err); |
| 5107 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5108 | &exception); |
| 5109 | } while (exception.retry); |
| 5110 | return err; |
| 5111 | } |
| 5112 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5113 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5114 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5115 | size_t buflen) |
| 5116 | { |
| 5117 | struct nfs_server *server = NFS_SERVER(inode); |
| 5118 | struct nfs_fattr fattr; |
| 5119 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5120 | |
| 5121 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5122 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5123 | .fh = NFS_FH(inode), |
| 5124 | .bitmask = bitmask, |
| 5125 | }; |
| 5126 | struct nfs4_getattr_res res = { |
| 5127 | .fattr = &fattr, |
| 5128 | .label = &label, |
| 5129 | .server = server, |
| 5130 | }; |
| 5131 | struct rpc_message msg = { |
| 5132 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5133 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5134 | .rpc_resp = &res, |
| 5135 | }; |
| 5136 | int ret; |
| 5137 | |
| 5138 | nfs_fattr_init(&fattr); |
| 5139 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5140 | 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] | 5141 | if (ret) |
| 5142 | return ret; |
| 5143 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5144 | return -ENOENT; |
| 5145 | if (buflen < label.len) |
| 5146 | return -ERANGE; |
| 5147 | return 0; |
| 5148 | } |
| 5149 | |
| 5150 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5151 | size_t buflen) |
| 5152 | { |
| 5153 | struct nfs4_exception exception = { }; |
| 5154 | int err; |
| 5155 | |
| 5156 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5157 | return -EOPNOTSUPP; |
| 5158 | |
| 5159 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5160 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5161 | trace_nfs4_get_security_label(inode, err); |
| 5162 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5163 | &exception); |
| 5164 | } while (exception.retry); |
| 5165 | return err; |
| 5166 | } |
| 5167 | |
| 5168 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5169 | struct nfs4_label *ilabel, |
| 5170 | struct nfs_fattr *fattr, |
| 5171 | struct nfs4_label *olabel) |
| 5172 | { |
| 5173 | |
| 5174 | struct iattr sattr = {0}; |
| 5175 | struct nfs_server *server = NFS_SERVER(inode); |
| 5176 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5177 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5178 | .fh = NFS_FH(inode), |
| 5179 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5180 | .server = server, |
| 5181 | .bitmask = bitmask, |
| 5182 | .label = ilabel, |
| 5183 | }; |
| 5184 | struct nfs_setattrres res = { |
| 5185 | .fattr = fattr, |
| 5186 | .label = olabel, |
| 5187 | .server = server, |
| 5188 | }; |
| 5189 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5190 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5191 | .rpc_argp = &arg, |
| 5192 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5193 | }; |
| 5194 | int status; |
| 5195 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5196 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5197 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5198 | 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] | 5199 | if (status) |
| 5200 | dprintk("%s failed: %d\n", __func__, status); |
| 5201 | |
| 5202 | return status; |
| 5203 | } |
| 5204 | |
| 5205 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5206 | struct nfs4_label *ilabel, |
| 5207 | struct nfs_fattr *fattr, |
| 5208 | struct nfs4_label *olabel) |
| 5209 | { |
| 5210 | struct nfs4_exception exception = { }; |
| 5211 | int err; |
| 5212 | |
| 5213 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5214 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5215 | fattr, olabel); |
| 5216 | trace_nfs4_set_security_label(inode, err); |
| 5217 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5218 | &exception); |
| 5219 | } while (exception.retry); |
| 5220 | return err; |
| 5221 | } |
| 5222 | |
| 5223 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5224 | 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] | 5225 | { |
| 5226 | struct nfs4_label ilabel, *olabel = NULL; |
| 5227 | struct nfs_fattr fattr; |
| 5228 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5229 | int status; |
| 5230 | |
| 5231 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5232 | return -EOPNOTSUPP; |
| 5233 | |
| 5234 | nfs_fattr_init(&fattr); |
| 5235 | |
| 5236 | ilabel.pi = 0; |
| 5237 | ilabel.lfs = 0; |
| 5238 | ilabel.label = (char *)buf; |
| 5239 | ilabel.len = buflen; |
| 5240 | |
| 5241 | cred = rpc_lookup_cred(); |
| 5242 | if (IS_ERR(cred)) |
| 5243 | return PTR_ERR(cred); |
| 5244 | |
| 5245 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5246 | if (IS_ERR(olabel)) { |
| 5247 | status = -PTR_ERR(olabel); |
| 5248 | goto out; |
| 5249 | } |
| 5250 | |
| 5251 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5252 | if (status == 0) |
| 5253 | nfs_setsecurity(inode, &fattr, olabel); |
| 5254 | |
| 5255 | nfs4_label_free(olabel); |
| 5256 | out: |
| 5257 | put_rpccred(cred); |
| 5258 | return status; |
| 5259 | } |
| 5260 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5261 | |
| 5262 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5263 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5264 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5265 | { |
| 5266 | __be32 verf[2]; |
| 5267 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5268 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5269 | /* An impossible timestamp guarantees this value |
| 5270 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5271 | verf[0] = cpu_to_be32(U32_MAX); |
| 5272 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5273 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5274 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5275 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5276 | |
| 5277 | verf[0] = cpu_to_be32(ns >> 32); |
| 5278 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5279 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5280 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5281 | } |
| 5282 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5283 | static int |
| 5284 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5285 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5286 | size_t len; |
| 5287 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5288 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5289 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5290 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5291 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5292 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5293 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5294 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5295 | 1 + |
| 5296 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5297 | 1; |
| 5298 | rcu_read_unlock(); |
| 5299 | |
| 5300 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5301 | return -EINVAL; |
| 5302 | |
| 5303 | /* |
| 5304 | * Since this string is allocated at mount time, and held until the |
| 5305 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5306 | * about a memory-reclaim deadlock. |
| 5307 | */ |
| 5308 | str = kmalloc(len, GFP_KERNEL); |
| 5309 | if (!str) |
| 5310 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5311 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5312 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5313 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5314 | clp->cl_ipaddr, |
| 5315 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5316 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5317 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5318 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5319 | clp->cl_owner_id = str; |
| 5320 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5321 | } |
| 5322 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5323 | static int |
| 5324 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5325 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5326 | size_t len; |
| 5327 | char *str; |
| 5328 | |
| 5329 | len = 10 + 10 + 1 + 10 + 1 + |
| 5330 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5331 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5332 | |
| 5333 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5334 | return -EINVAL; |
| 5335 | |
| 5336 | /* |
| 5337 | * Since this string is allocated at mount time, and held until the |
| 5338 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5339 | * about a memory-reclaim deadlock. |
| 5340 | */ |
| 5341 | str = kmalloc(len, GFP_KERNEL); |
| 5342 | if (!str) |
| 5343 | return -ENOMEM; |
| 5344 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5345 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5346 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5347 | nfs4_client_id_uniquifier, |
| 5348 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5349 | clp->cl_owner_id = str; |
| 5350 | return 0; |
| 5351 | } |
| 5352 | |
| 5353 | static int |
| 5354 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5355 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5356 | size_t len; |
| 5357 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5358 | |
| 5359 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5360 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5361 | |
| 5362 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5363 | return nfs4_init_uniquifier_client_string(clp); |
| 5364 | |
| 5365 | len = 10 + 10 + 1 + 10 + 1 + |
| 5366 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5367 | |
| 5368 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5369 | return -EINVAL; |
| 5370 | |
| 5371 | /* |
| 5372 | * Since this string is allocated at mount time, and held until the |
| 5373 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5374 | * about a memory-reclaim deadlock. |
| 5375 | */ |
| 5376 | str = kmalloc(len, GFP_KERNEL); |
| 5377 | if (!str) |
| 5378 | return -ENOMEM; |
| 5379 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5380 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5381 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5382 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5383 | clp->cl_owner_id = str; |
| 5384 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5385 | } |
| 5386 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5387 | /* |
| 5388 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5389 | * services. Advertise one based on the address family of the |
| 5390 | * clientaddr. |
| 5391 | */ |
| 5392 | static unsigned int |
| 5393 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5394 | { |
| 5395 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5396 | return scnprintf(buf, len, "tcp6"); |
| 5397 | else |
| 5398 | return scnprintf(buf, len, "tcp"); |
| 5399 | } |
| 5400 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5401 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5402 | { |
| 5403 | struct nfs4_setclientid *sc = calldata; |
| 5404 | |
| 5405 | if (task->tk_status == 0) |
| 5406 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5407 | } |
| 5408 | |
| 5409 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5410 | .rpc_call_done = nfs4_setclientid_done, |
| 5411 | }; |
| 5412 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5413 | /** |
| 5414 | * nfs4_proc_setclientid - Negotiate client ID |
| 5415 | * @clp: state data structure |
| 5416 | * @program: RPC program for NFSv4 callback service |
| 5417 | * @port: IP port number for NFS4 callback service |
| 5418 | * @cred: RPC credential to use for this call |
| 5419 | * @res: where to place the result |
| 5420 | * |
| 5421 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5422 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5423 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5424 | unsigned short port, struct rpc_cred *cred, |
| 5425 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | { |
| 5427 | nfs4_verifier sc_verifier; |
| 5428 | struct nfs4_setclientid setclientid = { |
| 5429 | .sc_verifier = &sc_verifier, |
| 5430 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5431 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | }; |
| 5433 | struct rpc_message msg = { |
| 5434 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5435 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5436 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5437 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5439 | struct rpc_task *task; |
| 5440 | struct rpc_task_setup task_setup_data = { |
| 5441 | .rpc_client = clp->cl_rpcclient, |
| 5442 | .rpc_message = &msg, |
| 5443 | .callback_ops = &nfs4_setclientid_ops, |
| 5444 | .callback_data = &setclientid, |
| 5445 | .flags = RPC_TASK_TIMEOUT, |
| 5446 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5447 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5449 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5450 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5451 | |
| 5452 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5453 | status = nfs4_init_uniform_client_string(clp); |
| 5454 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5455 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5456 | |
| 5457 | if (status) |
| 5458 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5459 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5460 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5461 | setclientid.sc_netid_len = |
| 5462 | nfs4_init_callback_netid(clp, |
| 5463 | setclientid.sc_netid, |
| 5464 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5465 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5466 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5468 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5469 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5470 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5471 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5472 | task = rpc_run_task(&task_setup_data); |
| 5473 | if (IS_ERR(task)) { |
| 5474 | status = PTR_ERR(task); |
| 5475 | goto out; |
| 5476 | } |
| 5477 | status = task->tk_status; |
| 5478 | if (setclientid.sc_cred) { |
| 5479 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5480 | put_rpccred(setclientid.sc_cred); |
| 5481 | } |
| 5482 | rpc_put_task(task); |
| 5483 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5484 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5485 | dprintk("NFS reply setclientid: %d\n", status); |
| 5486 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5489 | /** |
| 5490 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5491 | * @clp: state data structure |
| 5492 | * @res: result of a previous SETCLIENTID |
| 5493 | * @cred: RPC credential to use for this call |
| 5494 | * |
| 5495 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5496 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5497 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5498 | struct nfs4_setclientid_res *arg, |
| 5499 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | struct rpc_message msg = { |
| 5502 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5503 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5504 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | int status; |
| 5507 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5508 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5509 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5510 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5511 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5512 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5513 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | return status; |
| 5515 | } |
| 5516 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5517 | struct nfs4_delegreturndata { |
| 5518 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5519 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5520 | struct nfs_fh fh; |
| 5521 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5522 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5523 | struct { |
| 5524 | struct nfs4_layoutreturn_args arg; |
| 5525 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5526 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5527 | u32 roc_barrier; |
| 5528 | bool roc; |
| 5529 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5530 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5531 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5532 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5533 | }; |
| 5534 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5535 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5536 | { |
| 5537 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5538 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5539 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5540 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5541 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5542 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5543 | |
| 5544 | /* Handle Layoutreturn errors */ |
| 5545 | if (data->args.lr_args && task->tk_status != 0) { |
| 5546 | switch(data->res.lr_ret) { |
| 5547 | default: |
| 5548 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5549 | break; |
| 5550 | case 0: |
| 5551 | data->args.lr_args = NULL; |
| 5552 | data->res.lr_res = NULL; |
| 5553 | break; |
| 5554 | case -NFS4ERR_ADMIN_REVOKED: |
| 5555 | case -NFS4ERR_DELEG_REVOKED: |
| 5556 | case -NFS4ERR_EXPIRED: |
| 5557 | case -NFS4ERR_BAD_STATEID: |
| 5558 | case -NFS4ERR_OLD_STATEID: |
| 5559 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5560 | case -NFS4ERR_WRONG_CRED: |
| 5561 | data->args.lr_args = NULL; |
| 5562 | data->res.lr_res = NULL; |
| 5563 | data->res.lr_ret = 0; |
| 5564 | rpc_restart_call_prepare(task); |
| 5565 | return; |
| 5566 | } |
| 5567 | } |
| 5568 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5569 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5570 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5571 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5572 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5573 | case -NFS4ERR_ADMIN_REVOKED: |
| 5574 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5575 | case -NFS4ERR_EXPIRED: |
| 5576 | nfs4_free_revoked_stateid(data->res.server, |
| 5577 | data->args.stateid, |
| 5578 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5579 | case -NFS4ERR_BAD_STATEID: |
| 5580 | case -NFS4ERR_OLD_STATEID: |
| 5581 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5582 | task->tk_status = 0; |
| 5583 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5584 | case -NFS4ERR_ACCESS: |
| 5585 | if (data->args.bitmask) { |
| 5586 | data->args.bitmask = NULL; |
| 5587 | data->res.fattr = NULL; |
| 5588 | task->tk_status = 0; |
| 5589 | rpc_restart_call_prepare(task); |
| 5590 | return; |
| 5591 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5592 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5593 | if (nfs4_async_handle_error(task, data->res.server, |
| 5594 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5595 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5596 | return; |
| 5597 | } |
| 5598 | } |
| 5599 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | static void nfs4_delegreturn_release(void *calldata) |
| 5603 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5604 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5605 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5606 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5607 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5608 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5609 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5610 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5611 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5612 | nfs_iput_and_deactive(inode); |
| 5613 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5614 | kfree(calldata); |
| 5615 | } |
| 5616 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5617 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5618 | { |
| 5619 | struct nfs4_delegreturndata *d_data; |
| 5620 | |
| 5621 | d_data = (struct nfs4_delegreturndata *)data; |
| 5622 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5623 | 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] | 5624 | return; |
| 5625 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5626 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5627 | &d_data->args.seq_args, |
| 5628 | &d_data->res.seq_res, |
| 5629 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5630 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5631 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5632 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5633 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5634 | .rpc_call_done = nfs4_delegreturn_done, |
| 5635 | .rpc_release = nfs4_delegreturn_release, |
| 5636 | }; |
| 5637 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5638 | 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] | 5639 | { |
| 5640 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5641 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5642 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5643 | struct rpc_message msg = { |
| 5644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5645 | .rpc_cred = cred, |
| 5646 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5647 | struct rpc_task_setup task_setup_data = { |
| 5648 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5649 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5650 | .callback_ops = &nfs4_delegreturn_ops, |
| 5651 | .flags = RPC_TASK_ASYNC, |
| 5652 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5653 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5654 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5655 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5656 | if (data == NULL) |
| 5657 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5658 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5659 | |
| 5660 | nfs4_state_protect(server->nfs_client, |
| 5661 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5662 | &task_setup_data.rpc_client, &msg); |
| 5663 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5664 | data->args.fhandle = &data->fh; |
| 5665 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5666 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5667 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5668 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5669 | data->res.fattr = &data->fattr; |
| 5670 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5671 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5672 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5673 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5674 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5675 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5676 | 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] | 5677 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5678 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5679 | if (data->lr.roc) { |
| 5680 | data->args.lr_args = &data->lr.arg; |
| 5681 | data->res.lr_res = &data->lr.res; |
| 5682 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5683 | } else if (data->lr.roc) { |
| 5684 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5685 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5686 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5687 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5688 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5689 | msg.rpc_argp = &data->args; |
| 5690 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5691 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5692 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5693 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5694 | if (!issync) |
| 5695 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5696 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5697 | if (status != 0) |
| 5698 | goto out; |
| 5699 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5700 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5701 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5702 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | } |
| 5704 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5705 | 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] | 5706 | { |
| 5707 | struct nfs_server *server = NFS_SERVER(inode); |
| 5708 | struct nfs4_exception exception = { }; |
| 5709 | int err; |
| 5710 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5711 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5712 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | switch (err) { |
| 5714 | case -NFS4ERR_STALE_STATEID: |
| 5715 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | case 0: |
| 5717 | return 0; |
| 5718 | } |
| 5719 | err = nfs4_handle_exception(server, err, &exception); |
| 5720 | } while (exception.retry); |
| 5721 | return err; |
| 5722 | } |
| 5723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5725 | { |
| 5726 | struct inode *inode = state->inode; |
| 5727 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5728 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5729 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5731 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5733 | struct nfs_lockt_res res = { |
| 5734 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | }; |
| 5736 | struct rpc_message msg = { |
| 5737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5738 | .rpc_argp = &arg, |
| 5739 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | .rpc_cred = state->owner->so_cred, |
| 5741 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | struct nfs4_lock_state *lsp; |
| 5743 | int status; |
| 5744 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5745 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5746 | status = nfs4_set_lock_state(state, request); |
| 5747 | if (status != 0) |
| 5748 | goto out; |
| 5749 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5750 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5751 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5752 | 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] | 5753 | switch (status) { |
| 5754 | case 0: |
| 5755 | request->fl_type = F_UNLCK; |
| 5756 | break; |
| 5757 | case -NFS4ERR_DENIED: |
| 5758 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5760 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5761 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5762 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | return status; |
| 5764 | } |
| 5765 | |
| 5766 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5767 | { |
| 5768 | struct nfs4_exception exception = { }; |
| 5769 | int err; |
| 5770 | |
| 5771 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5772 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5773 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5774 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | &exception); |
| 5776 | } while (exception.retry); |
| 5777 | return err; |
| 5778 | } |
| 5779 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5780 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5781 | struct nfs_locku_args arg; |
| 5782 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5783 | struct nfs4_lock_state *lsp; |
| 5784 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5785 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5786 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5787 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5788 | }; |
| 5789 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5790 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5791 | struct nfs_open_context *ctx, |
| 5792 | struct nfs4_lock_state *lsp, |
| 5793 | struct nfs_seqid *seqid) |
| 5794 | { |
| 5795 | struct nfs4_unlockdata *p; |
| 5796 | struct inode *inode = lsp->ls_state->inode; |
| 5797 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5798 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5799 | if (p == NULL) |
| 5800 | return NULL; |
| 5801 | p->arg.fh = NFS_FH(inode); |
| 5802 | p->arg.fl = &p->fl; |
| 5803 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5804 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5805 | p->lsp = lsp; |
| 5806 | atomic_inc(&lsp->ls_count); |
| 5807 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5808 | p->ctx = get_nfs_open_context(ctx); |
| 5809 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5810 | p->server = NFS_SERVER(inode); |
| 5811 | return p; |
| 5812 | } |
| 5813 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5814 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5815 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5816 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5817 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5818 | nfs4_put_lock_state(calldata->lsp); |
| 5819 | put_nfs_open_context(calldata->ctx); |
| 5820 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5821 | } |
| 5822 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5823 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5824 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5825 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5826 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5827 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5828 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5829 | switch (task->tk_status) { |
| 5830 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5831 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5832 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5833 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5834 | &calldata->res.stateid)) |
| 5835 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5836 | case -NFS4ERR_ADMIN_REVOKED: |
| 5837 | case -NFS4ERR_EXPIRED: |
| 5838 | nfs4_free_revoked_stateid(calldata->server, |
| 5839 | &calldata->arg.stateid, |
| 5840 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5841 | case -NFS4ERR_BAD_STATEID: |
| 5842 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5843 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5844 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5845 | &calldata->lsp->ls_stateid)) |
| 5846 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5847 | break; |
| 5848 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5849 | if (nfs4_async_handle_error(task, calldata->server, |
| 5850 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5851 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5852 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5853 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5854 | } |
| 5855 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5856 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5857 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5858 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5860 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5861 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5862 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5863 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5864 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5865 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5866 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5867 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5868 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5869 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5870 | &calldata->res.seq_res, |
| 5871 | task) != 0) |
| 5872 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5873 | return; |
| 5874 | out_no_action: |
| 5875 | task->tk_action = NULL; |
| 5876 | out_wait: |
| 5877 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5878 | } |
| 5879 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5880 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5881 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5882 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5883 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5884 | }; |
| 5885 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5886 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5887 | struct nfs_open_context *ctx, |
| 5888 | struct nfs4_lock_state *lsp, |
| 5889 | struct nfs_seqid *seqid) |
| 5890 | { |
| 5891 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5892 | struct rpc_message msg = { |
| 5893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5894 | .rpc_cred = ctx->cred, |
| 5895 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5896 | struct rpc_task_setup task_setup_data = { |
| 5897 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5898 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5899 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5900 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5901 | .flags = RPC_TASK_ASYNC, |
| 5902 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5903 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5904 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5905 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5906 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5907 | /* Ensure this is an unlock - when canceling a lock, the |
| 5908 | * canceled lock is passed in, and it won't be an unlock. |
| 5909 | */ |
| 5910 | fl->fl_type = F_UNLCK; |
| 5911 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5912 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5913 | if (data == NULL) { |
| 5914 | nfs_free_seqid(seqid); |
| 5915 | return ERR_PTR(-ENOMEM); |
| 5916 | } |
| 5917 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5918 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5919 | msg.rpc_argp = &data->arg; |
| 5920 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5921 | task_setup_data.callback_data = data; |
| 5922 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5923 | } |
| 5924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5926 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5927 | struct inode *inode = state->inode; |
| 5928 | struct nfs4_state_owner *sp = state->owner; |
| 5929 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5930 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5931 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5932 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5933 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5934 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5935 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5937 | status = nfs4_set_lock_state(state, request); |
| 5938 | /* Unlock _before_ we do the RPC call */ |
| 5939 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5940 | /* Exclude nfs_delegation_claim_locks() */ |
| 5941 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5942 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5943 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5944 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5945 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5946 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5947 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5948 | } |
| 5949 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5950 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5951 | if (status != 0) |
| 5952 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5953 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5954 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5955 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5956 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5957 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5958 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5959 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5960 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5961 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5962 | 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] | 5963 | status = PTR_ERR(task); |
| 5964 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5965 | goto out; |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 5966 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5967 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5968 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5969 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5970 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5971 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5972 | } |
| 5973 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5974 | struct nfs4_lockdata { |
| 5975 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5976 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5977 | struct nfs4_lock_state *lsp; |
| 5978 | struct nfs_open_context *ctx; |
| 5979 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5980 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5981 | int rpc_status; |
| 5982 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5983 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5984 | }; |
| 5985 | |
| 5986 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5987 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5988 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5989 | { |
| 5990 | struct nfs4_lockdata *p; |
| 5991 | struct inode *inode = lsp->ls_state->inode; |
| 5992 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5993 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5994 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5995 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5996 | if (p == NULL) |
| 5997 | return NULL; |
| 5998 | |
| 5999 | p->arg.fh = NFS_FH(inode); |
| 6000 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6001 | 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] | 6002 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6003 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6004 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6005 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6006 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6007 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6008 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6009 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6010 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6011 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6012 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6013 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6014 | atomic_inc(&lsp->ls_count); |
| 6015 | p->ctx = get_nfs_open_context(ctx); |
| 6016 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6017 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6018 | out_free_seqid: |
| 6019 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6020 | out_free: |
| 6021 | kfree(p); |
| 6022 | return NULL; |
| 6023 | } |
| 6024 | |
| 6025 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6026 | { |
| 6027 | struct nfs4_lockdata *data = calldata; |
| 6028 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6030 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6031 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6032 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6033 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6034 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6035 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6036 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6037 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6038 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6039 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6040 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6041 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6042 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6043 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6044 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6045 | &data->lsp->ls_stateid); |
| 6046 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6047 | if (!nfs4_valid_open_stateid(state)) { |
| 6048 | data->rpc_status = -EBADF; |
| 6049 | task->tk_action = NULL; |
| 6050 | goto out_release_open_seqid; |
| 6051 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6052 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6053 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6054 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6055 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6056 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6057 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6058 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6059 | nfs_release_seqid(data->arg.open_seqid); |
| 6060 | out_release_lock_seqid: |
| 6061 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6062 | out_wait: |
| 6063 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6064 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6065 | } |
| 6066 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6067 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6068 | { |
| 6069 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6070 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6071 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6072 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6073 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6074 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6075 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6076 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6077 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6078 | switch (task->tk_status) { |
| 6079 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6080 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6081 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6082 | if (data->arg.new_lock) { |
| 6083 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6084 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6085 | rpc_restart_call_prepare(task); |
| 6086 | break; |
| 6087 | } |
| 6088 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6089 | if (data->arg.new_lock_owner != 0) { |
| 6090 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6091 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6092 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6093 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6094 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6095 | break; |
| 6096 | case -NFS4ERR_BAD_STATEID: |
| 6097 | case -NFS4ERR_OLD_STATEID: |
| 6098 | case -NFS4ERR_STALE_STATEID: |
| 6099 | case -NFS4ERR_EXPIRED: |
| 6100 | if (data->arg.new_lock_owner != 0) { |
| 6101 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6102 | &lsp->ls_state->open_stateid)) |
| 6103 | rpc_restart_call_prepare(task); |
| 6104 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6105 | &lsp->ls_stateid)) |
| 6106 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6107 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6108 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | static void nfs4_lock_release(void *calldata) |
| 6112 | { |
| 6113 | struct nfs4_lockdata *data = calldata; |
| 6114 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6115 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6116 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6117 | if (data->cancelled != 0) { |
| 6118 | struct rpc_task *task; |
| 6119 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6120 | data->arg.lock_seqid); |
| 6121 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6122 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6123 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6124 | } else |
| 6125 | nfs_free_seqid(data->arg.lock_seqid); |
| 6126 | nfs4_put_lock_state(data->lsp); |
| 6127 | put_nfs_open_context(data->ctx); |
| 6128 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6129 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6133 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6134 | .rpc_call_done = nfs4_lock_done, |
| 6135 | .rpc_release = nfs4_lock_release, |
| 6136 | }; |
| 6137 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6138 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6139 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6140 | switch (error) { |
| 6141 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6142 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6143 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6144 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6145 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6146 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6147 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6148 | break; |
| 6149 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6150 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6151 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6152 | }; |
| 6153 | } |
| 6154 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6155 | 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] | 6156 | { |
| 6157 | struct nfs4_lockdata *data; |
| 6158 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6159 | struct rpc_message msg = { |
| 6160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6161 | .rpc_cred = state->owner->so_cred, |
| 6162 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6163 | struct rpc_task_setup task_setup_data = { |
| 6164 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6165 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6166 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6167 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6168 | .flags = RPC_TASK_ASYNC, |
| 6169 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6170 | int ret; |
| 6171 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6172 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6173 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6174 | fl->fl_u.nfs4_fl.owner, |
| 6175 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6176 | if (data == NULL) |
| 6177 | return -ENOMEM; |
| 6178 | if (IS_SETLKW(cmd)) |
| 6179 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6180 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6181 | msg.rpc_argp = &data->arg; |
| 6182 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6183 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6184 | if (recovery_type > NFS_LOCK_NEW) { |
| 6185 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6186 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6187 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6188 | } else |
| 6189 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6190 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6191 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6192 | return PTR_ERR(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 6193 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6194 | if (ret == 0) { |
| 6195 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6196 | if (ret) |
| 6197 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6198 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6199 | } else |
| 6200 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6201 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6202 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6203 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6204 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6208 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6209 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6210 | struct nfs4_exception exception = { |
| 6211 | .inode = state->inode, |
| 6212 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6213 | int err; |
| 6214 | |
| 6215 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6216 | /* Cache the lock if possible... */ |
| 6217 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6218 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6219 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6220 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6221 | break; |
| 6222 | nfs4_handle_exception(server, err, &exception); |
| 6223 | } while (exception.retry); |
| 6224 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6228 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6229 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6230 | struct nfs4_exception exception = { |
| 6231 | .inode = state->inode, |
| 6232 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6233 | int err; |
| 6234 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6235 | err = nfs4_set_lock_state(state, request); |
| 6236 | if (err != 0) |
| 6237 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6238 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6239 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6240 | return 0; |
| 6241 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6242 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6243 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6244 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6245 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6246 | switch (err) { |
| 6247 | default: |
| 6248 | goto out; |
| 6249 | case -NFS4ERR_GRACE: |
| 6250 | case -NFS4ERR_DELAY: |
| 6251 | nfs4_handle_exception(server, err, &exception); |
| 6252 | err = 0; |
| 6253 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6254 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6255 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6256 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | } |
| 6258 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6259 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6260 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6261 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6262 | struct nfs4_lock_state *lsp; |
| 6263 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6264 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6265 | status = nfs4_set_lock_state(state, request); |
| 6266 | if (status != 0) |
| 6267 | return status; |
| 6268 | lsp = request->fl_u.nfs4_fl.owner; |
| 6269 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6270 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6271 | return 0; |
Anna Schumaker | 81b68de | 2017-01-11 16:41:34 -0500 | [diff] [blame] | 6272 | return nfs4_lock_expired(state, request); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6273 | } |
| 6274 | #endif |
| 6275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6276 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6277 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6278 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6279 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6280 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6281 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6282 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6283 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6284 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6285 | if (status < 0) |
| 6286 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6287 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6288 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6289 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6290 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6291 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6292 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6293 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6294 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6295 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6296 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6297 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6298 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6299 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6300 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6301 | out: |
| 6302 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | return status; |
| 6304 | } |
| 6305 | |
| 6306 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6307 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6308 | struct nfs4_exception exception = { |
| 6309 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6310 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6311 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6312 | int err; |
| 6313 | |
| 6314 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6315 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6316 | if (err == -NFS4ERR_DENIED) |
| 6317 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6319 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6320 | } while (exception.retry); |
| 6321 | return err; |
| 6322 | } |
| 6323 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6324 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6325 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6326 | |
| 6327 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6328 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6329 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6330 | { |
| 6331 | int status = -ERESTARTSYS; |
| 6332 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6333 | |
| 6334 | while(!signalled()) { |
| 6335 | status = nfs4_proc_setlk(state, cmd, request); |
| 6336 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6337 | break; |
| 6338 | freezable_schedule_timeout_interruptible(timeout); |
| 6339 | timeout *= 2; |
| 6340 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6341 | status = -ERESTARTSYS; |
| 6342 | } |
| 6343 | return status; |
| 6344 | } |
| 6345 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6346 | #ifdef CONFIG_NFS_V4_1 |
| 6347 | struct nfs4_lock_waiter { |
| 6348 | struct task_struct *task; |
| 6349 | struct inode *inode; |
| 6350 | struct nfs_lowner *owner; |
| 6351 | bool notified; |
| 6352 | }; |
| 6353 | |
| 6354 | static int |
| 6355 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6356 | { |
| 6357 | int ret; |
| 6358 | struct cb_notify_lock_args *cbnl = key; |
| 6359 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6360 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6361 | *wowner = waiter->owner; |
| 6362 | |
| 6363 | /* Only wake if the callback was for the same owner */ |
| 6364 | if (lowner->clientid != wowner->clientid || |
| 6365 | lowner->id != wowner->id || |
| 6366 | lowner->s_dev != wowner->s_dev) |
| 6367 | return 0; |
| 6368 | |
| 6369 | /* Make sure it's for the right inode */ |
| 6370 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6371 | return 0; |
| 6372 | |
| 6373 | waiter->notified = true; |
| 6374 | |
| 6375 | /* override "private" so we can use default_wake_function */ |
| 6376 | wait->private = waiter->task; |
| 6377 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6378 | wait->private = waiter; |
| 6379 | return ret; |
| 6380 | } |
| 6381 | |
| 6382 | static int |
| 6383 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6384 | { |
| 6385 | int status = -ERESTARTSYS; |
| 6386 | unsigned long flags; |
| 6387 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6388 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6389 | struct nfs_client *clp = server->nfs_client; |
| 6390 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6391 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6392 | .id = lsp->ls_seqid.owner_id, |
| 6393 | .s_dev = server->s_dev }; |
| 6394 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6395 | .inode = state->inode, |
| 6396 | .owner = &owner, |
| 6397 | .notified = false }; |
| 6398 | wait_queue_t wait; |
| 6399 | |
| 6400 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6401 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6402 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6403 | |
| 6404 | init_wait(&wait); |
| 6405 | wait.private = &waiter; |
| 6406 | wait.func = nfs4_wake_lock_waiter; |
| 6407 | add_wait_queue(q, &wait); |
| 6408 | |
| 6409 | while(!signalled()) { |
| 6410 | status = nfs4_proc_setlk(state, cmd, request); |
| 6411 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6412 | break; |
| 6413 | |
| 6414 | status = -ERESTARTSYS; |
| 6415 | spin_lock_irqsave(&q->lock, flags); |
| 6416 | if (waiter.notified) { |
| 6417 | spin_unlock_irqrestore(&q->lock, flags); |
| 6418 | continue; |
| 6419 | } |
| 6420 | set_current_state(TASK_INTERRUPTIBLE); |
| 6421 | spin_unlock_irqrestore(&q->lock, flags); |
| 6422 | |
| 6423 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6424 | } |
| 6425 | |
| 6426 | finish_wait(q, &wait); |
| 6427 | return status; |
| 6428 | } |
| 6429 | #else /* !CONFIG_NFS_V4_1 */ |
| 6430 | static inline int |
| 6431 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6432 | { |
| 6433 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6434 | } |
| 6435 | #endif |
| 6436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | static int |
| 6438 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6439 | { |
| 6440 | struct nfs_open_context *ctx; |
| 6441 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | int status; |
| 6443 | |
| 6444 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6445 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | state = ctx->state; |
| 6447 | |
| 6448 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6449 | return -EINVAL; |
| 6450 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6451 | if (IS_GETLK(cmd)) { |
| 6452 | if (state != NULL) |
| 6453 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6454 | return 0; |
| 6455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6456 | |
| 6457 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6458 | return -EINVAL; |
| 6459 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6460 | if (request->fl_type == F_UNLCK) { |
| 6461 | if (state != NULL) |
| 6462 | return nfs4_proc_unlck(state, cmd, request); |
| 6463 | return 0; |
| 6464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6466 | if (state == NULL) |
| 6467 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6468 | |
| 6469 | if ((request->fl_flags & FL_POSIX) && |
| 6470 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6471 | return -ENOLCK; |
| 6472 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6473 | /* |
| 6474 | * Don't rely on the VFS having checked the file open mode, |
| 6475 | * since it won't do this for flock() locks. |
| 6476 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6477 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6478 | case F_RDLCK: |
| 6479 | if (!(filp->f_mode & FMODE_READ)) |
| 6480 | return -EBADF; |
| 6481 | break; |
| 6482 | case F_WRLCK: |
| 6483 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6484 | return -EBADF; |
| 6485 | } |
| 6486 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6487 | status = nfs4_set_lock_state(state, request); |
| 6488 | if (status != 0) |
| 6489 | return status; |
| 6490 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6491 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | } |
| 6493 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6494 | 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] | 6495 | { |
| 6496 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6497 | int err; |
| 6498 | |
| 6499 | err = nfs4_set_lock_state(state, fl); |
| 6500 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6501 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6502 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6503 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6504 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6505 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6506 | struct nfs_release_lockowner_data { |
| 6507 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6508 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6509 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6510 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6511 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6512 | }; |
| 6513 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6514 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6515 | { |
| 6516 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6517 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6518 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6519 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6520 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6521 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6522 | } |
| 6523 | |
| 6524 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6525 | { |
| 6526 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6527 | struct nfs_server *server = data->server; |
| 6528 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6529 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6530 | |
| 6531 | switch (task->tk_status) { |
| 6532 | case 0: |
| 6533 | renew_lease(server, data->timestamp); |
| 6534 | break; |
| 6535 | case -NFS4ERR_STALE_CLIENTID: |
| 6536 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6537 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6538 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6539 | case -NFS4ERR_LEASE_MOVED: |
| 6540 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6541 | if (nfs4_async_handle_error(task, server, |
| 6542 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6543 | rpc_restart_call_prepare(task); |
| 6544 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6545 | } |
| 6546 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6547 | static void nfs4_release_lockowner_release(void *calldata) |
| 6548 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6549 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6550 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6551 | kfree(calldata); |
| 6552 | } |
| 6553 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6554 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6555 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6556 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6557 | .rpc_release = nfs4_release_lockowner_release, |
| 6558 | }; |
| 6559 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6560 | static void |
| 6561 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6562 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6563 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6564 | struct rpc_message msg = { |
| 6565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6566 | }; |
| 6567 | |
| 6568 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6569 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6570 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6571 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6572 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6573 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6574 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6575 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6576 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6577 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6578 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6579 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6580 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6581 | msg.rpc_resp = &data->res; |
| 6582 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6583 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6584 | } |
| 6585 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6586 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6587 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6588 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6589 | struct dentry *unused, struct inode *inode, |
| 6590 | const char *key, const void *buf, |
| 6591 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6592 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6593 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6594 | } |
| 6595 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6596 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6597 | struct dentry *unused, struct inode *inode, |
| 6598 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6599 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6600 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6601 | } |
| 6602 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6603 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6604 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6605 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6606 | } |
| 6607 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6608 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6609 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6610 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6611 | struct dentry *unused, struct inode *inode, |
| 6612 | const char *key, const void *buf, |
| 6613 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6614 | { |
| 6615 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6616 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6617 | |
| 6618 | return -EOPNOTSUPP; |
| 6619 | } |
| 6620 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6621 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6622 | struct dentry *unused, struct inode *inode, |
| 6623 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6624 | { |
| 6625 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6626 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6627 | return -EOPNOTSUPP; |
| 6628 | } |
| 6629 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6630 | static ssize_t |
| 6631 | 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] | 6632 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6633 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6634 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6635 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6636 | len = security_inode_listsecurity(inode, list, list_len); |
| 6637 | if (list_len && len > list_len) |
| 6638 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6639 | } |
| 6640 | return len; |
| 6641 | } |
| 6642 | |
| 6643 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6644 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6645 | .get = nfs4_xattr_get_nfs4_label, |
| 6646 | .set = nfs4_xattr_set_nfs4_label, |
| 6647 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6648 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6649 | #else |
| 6650 | |
| 6651 | static ssize_t |
| 6652 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6653 | { |
| 6654 | return 0; |
| 6655 | } |
| 6656 | |
| 6657 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6658 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6659 | /* |
| 6660 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6661 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6662 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6663 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6664 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6665 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6666 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6667 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6668 | return; |
| 6669 | |
| 6670 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6671 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6672 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6673 | fattr->nlink = 2; |
| 6674 | } |
| 6675 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6676 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6677 | const struct qstr *name, |
| 6678 | struct nfs4_fs_locations *fs_locations, |
| 6679 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6680 | { |
| 6681 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6682 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6683 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6684 | }; |
| 6685 | struct nfs4_fs_locations_arg args = { |
| 6686 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6687 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6688 | .page = page, |
| 6689 | .bitmask = bitmask, |
| 6690 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6691 | struct nfs4_fs_locations_res res = { |
| 6692 | .fs_locations = fs_locations, |
| 6693 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6694 | struct rpc_message msg = { |
| 6695 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6696 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6697 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6698 | }; |
| 6699 | int status; |
| 6700 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6701 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6702 | |
| 6703 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6704 | * is not supported */ |
| 6705 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6706 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6707 | else |
| 6708 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6709 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6710 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6711 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6712 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6713 | 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] | 6714 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6715 | return status; |
| 6716 | } |
| 6717 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6718 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6719 | const struct qstr *name, |
| 6720 | struct nfs4_fs_locations *fs_locations, |
| 6721 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6722 | { |
| 6723 | struct nfs4_exception exception = { }; |
| 6724 | int err; |
| 6725 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6726 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6727 | fs_locations, page); |
| 6728 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6729 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6730 | &exception); |
| 6731 | } while (exception.retry); |
| 6732 | return err; |
| 6733 | } |
| 6734 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6735 | /* |
| 6736 | * This operation also signals the server that this client is |
| 6737 | * performing migration recovery. The server can stop returning |
| 6738 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6739 | * appended to this compound to identify the client ID which is |
| 6740 | * performing recovery. |
| 6741 | */ |
| 6742 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6743 | struct nfs4_fs_locations *locations, |
| 6744 | struct page *page, struct rpc_cred *cred) |
| 6745 | { |
| 6746 | struct nfs_server *server = NFS_SERVER(inode); |
| 6747 | struct rpc_clnt *clnt = server->client; |
| 6748 | u32 bitmask[2] = { |
| 6749 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6750 | }; |
| 6751 | struct nfs4_fs_locations_arg args = { |
| 6752 | .clientid = server->nfs_client->cl_clientid, |
| 6753 | .fh = NFS_FH(inode), |
| 6754 | .page = page, |
| 6755 | .bitmask = bitmask, |
| 6756 | .migration = 1, /* skip LOOKUP */ |
| 6757 | .renew = 1, /* append RENEW */ |
| 6758 | }; |
| 6759 | struct nfs4_fs_locations_res res = { |
| 6760 | .fs_locations = locations, |
| 6761 | .migration = 1, |
| 6762 | .renew = 1, |
| 6763 | }; |
| 6764 | struct rpc_message msg = { |
| 6765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6766 | .rpc_argp = &args, |
| 6767 | .rpc_resp = &res, |
| 6768 | .rpc_cred = cred, |
| 6769 | }; |
| 6770 | unsigned long now = jiffies; |
| 6771 | int status; |
| 6772 | |
| 6773 | nfs_fattr_init(&locations->fattr); |
| 6774 | locations->server = server; |
| 6775 | locations->nlocations = 0; |
| 6776 | |
| 6777 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6778 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6779 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6780 | &args.seq_args, &res.seq_res); |
| 6781 | if (status) |
| 6782 | return status; |
| 6783 | |
| 6784 | renew_lease(server, now); |
| 6785 | return 0; |
| 6786 | } |
| 6787 | |
| 6788 | #ifdef CONFIG_NFS_V4_1 |
| 6789 | |
| 6790 | /* |
| 6791 | * This operation also signals the server that this client is |
| 6792 | * performing migration recovery. The server can stop asserting |
| 6793 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6794 | * performing this operation is identified in the SEQUENCE |
| 6795 | * operation in this compound. |
| 6796 | * |
| 6797 | * When the client supports GETATTR(fs_locations_info), it can |
| 6798 | * be plumbed in here. |
| 6799 | */ |
| 6800 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6801 | struct nfs4_fs_locations *locations, |
| 6802 | struct page *page, struct rpc_cred *cred) |
| 6803 | { |
| 6804 | struct nfs_server *server = NFS_SERVER(inode); |
| 6805 | struct rpc_clnt *clnt = server->client; |
| 6806 | u32 bitmask[2] = { |
| 6807 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6808 | }; |
| 6809 | struct nfs4_fs_locations_arg args = { |
| 6810 | .fh = NFS_FH(inode), |
| 6811 | .page = page, |
| 6812 | .bitmask = bitmask, |
| 6813 | .migration = 1, /* skip LOOKUP */ |
| 6814 | }; |
| 6815 | struct nfs4_fs_locations_res res = { |
| 6816 | .fs_locations = locations, |
| 6817 | .migration = 1, |
| 6818 | }; |
| 6819 | struct rpc_message msg = { |
| 6820 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6821 | .rpc_argp = &args, |
| 6822 | .rpc_resp = &res, |
| 6823 | .rpc_cred = cred, |
| 6824 | }; |
| 6825 | int status; |
| 6826 | |
| 6827 | nfs_fattr_init(&locations->fattr); |
| 6828 | locations->server = server; |
| 6829 | locations->nlocations = 0; |
| 6830 | |
| 6831 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6832 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6833 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6834 | &args.seq_args, &res.seq_res); |
| 6835 | if (status == NFS4_OK && |
| 6836 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6837 | status = -NFS4ERR_LEASE_MOVED; |
| 6838 | return status; |
| 6839 | } |
| 6840 | |
| 6841 | #endif /* CONFIG_NFS_V4_1 */ |
| 6842 | |
| 6843 | /** |
| 6844 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6845 | * @inode: inode on FSID that is migrating |
| 6846 | * @locations: result of query |
| 6847 | * @page: buffer |
| 6848 | * @cred: credential to use for this operation |
| 6849 | * |
| 6850 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6851 | * operation failed, or a negative errno if a local error occurred. |
| 6852 | * |
| 6853 | * On success, "locations" is filled in, but if the server has |
| 6854 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6855 | * asserted. |
| 6856 | * |
| 6857 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6858 | * from this client that require migration recovery. |
| 6859 | */ |
| 6860 | int nfs4_proc_get_locations(struct inode *inode, |
| 6861 | struct nfs4_fs_locations *locations, |
| 6862 | struct page *page, struct rpc_cred *cred) |
| 6863 | { |
| 6864 | struct nfs_server *server = NFS_SERVER(inode); |
| 6865 | struct nfs_client *clp = server->nfs_client; |
| 6866 | const struct nfs4_mig_recovery_ops *ops = |
| 6867 | clp->cl_mvops->mig_recovery_ops; |
| 6868 | struct nfs4_exception exception = { }; |
| 6869 | int status; |
| 6870 | |
| 6871 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6872 | (unsigned long long)server->fsid.major, |
| 6873 | (unsigned long long)server->fsid.minor, |
| 6874 | clp->cl_hostname); |
| 6875 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6876 | |
| 6877 | do { |
| 6878 | status = ops->get_locations(inode, locations, page, cred); |
| 6879 | if (status != -NFS4ERR_DELAY) |
| 6880 | break; |
| 6881 | nfs4_handle_exception(server, status, &exception); |
| 6882 | } while (exception.retry); |
| 6883 | return status; |
| 6884 | } |
| 6885 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6886 | /* |
| 6887 | * This operation also signals the server that this client is |
| 6888 | * performing "lease moved" recovery. The server can stop |
| 6889 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6890 | * is appended to this compound to identify the client ID which is |
| 6891 | * performing recovery. |
| 6892 | */ |
| 6893 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6894 | { |
| 6895 | struct nfs_server *server = NFS_SERVER(inode); |
| 6896 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6897 | struct rpc_clnt *clnt = server->client; |
| 6898 | struct nfs4_fsid_present_arg args = { |
| 6899 | .fh = NFS_FH(inode), |
| 6900 | .clientid = clp->cl_clientid, |
| 6901 | .renew = 1, /* append RENEW */ |
| 6902 | }; |
| 6903 | struct nfs4_fsid_present_res res = { |
| 6904 | .renew = 1, |
| 6905 | }; |
| 6906 | struct rpc_message msg = { |
| 6907 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6908 | .rpc_argp = &args, |
| 6909 | .rpc_resp = &res, |
| 6910 | .rpc_cred = cred, |
| 6911 | }; |
| 6912 | unsigned long now = jiffies; |
| 6913 | int status; |
| 6914 | |
| 6915 | res.fh = nfs_alloc_fhandle(); |
| 6916 | if (res.fh == NULL) |
| 6917 | return -ENOMEM; |
| 6918 | |
| 6919 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6920 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6921 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6922 | &args.seq_args, &res.seq_res); |
| 6923 | nfs_free_fhandle(res.fh); |
| 6924 | if (status) |
| 6925 | return status; |
| 6926 | |
| 6927 | do_renew_lease(clp, now); |
| 6928 | return 0; |
| 6929 | } |
| 6930 | |
| 6931 | #ifdef CONFIG_NFS_V4_1 |
| 6932 | |
| 6933 | /* |
| 6934 | * This operation also signals the server that this client is |
| 6935 | * performing "lease moved" recovery. The server can stop asserting |
| 6936 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6937 | * this operation is identified in the SEQUENCE operation in this |
| 6938 | * compound. |
| 6939 | */ |
| 6940 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6941 | { |
| 6942 | struct nfs_server *server = NFS_SERVER(inode); |
| 6943 | struct rpc_clnt *clnt = server->client; |
| 6944 | struct nfs4_fsid_present_arg args = { |
| 6945 | .fh = NFS_FH(inode), |
| 6946 | }; |
| 6947 | struct nfs4_fsid_present_res res = { |
| 6948 | }; |
| 6949 | struct rpc_message msg = { |
| 6950 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6951 | .rpc_argp = &args, |
| 6952 | .rpc_resp = &res, |
| 6953 | .rpc_cred = cred, |
| 6954 | }; |
| 6955 | int status; |
| 6956 | |
| 6957 | res.fh = nfs_alloc_fhandle(); |
| 6958 | if (res.fh == NULL) |
| 6959 | return -ENOMEM; |
| 6960 | |
| 6961 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6962 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6963 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6964 | &args.seq_args, &res.seq_res); |
| 6965 | nfs_free_fhandle(res.fh); |
| 6966 | if (status == NFS4_OK && |
| 6967 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6968 | status = -NFS4ERR_LEASE_MOVED; |
| 6969 | return status; |
| 6970 | } |
| 6971 | |
| 6972 | #endif /* CONFIG_NFS_V4_1 */ |
| 6973 | |
| 6974 | /** |
| 6975 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6976 | * @inode: inode on FSID to check |
| 6977 | * @cred: credential to use for this operation |
| 6978 | * |
| 6979 | * Server indicates whether the FSID is present, moved, or not |
| 6980 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6981 | * condition for this client ID. |
| 6982 | * |
| 6983 | * Returns NFS4_OK if the FSID is present on this server, |
| 6984 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6985 | * NFS4ERR code if some error occurred on the server, or a |
| 6986 | * negative errno if a local failure occurred. |
| 6987 | */ |
| 6988 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6989 | { |
| 6990 | struct nfs_server *server = NFS_SERVER(inode); |
| 6991 | struct nfs_client *clp = server->nfs_client; |
| 6992 | const struct nfs4_mig_recovery_ops *ops = |
| 6993 | clp->cl_mvops->mig_recovery_ops; |
| 6994 | struct nfs4_exception exception = { }; |
| 6995 | int status; |
| 6996 | |
| 6997 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6998 | (unsigned long long)server->fsid.major, |
| 6999 | (unsigned long long)server->fsid.minor, |
| 7000 | clp->cl_hostname); |
| 7001 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7002 | |
| 7003 | do { |
| 7004 | status = ops->fsid_present(inode, cred); |
| 7005 | if (status != -NFS4ERR_DELAY) |
| 7006 | break; |
| 7007 | nfs4_handle_exception(server, status, &exception); |
| 7008 | } while (exception.retry); |
| 7009 | return status; |
| 7010 | } |
| 7011 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7012 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7013 | * If 'use_integrity' is true and the state managment nfs_client |
| 7014 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7015 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7016 | * Considerations sections. Otherwise, just use the user cred with the |
| 7017 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7018 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7019 | 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] | 7020 | { |
| 7021 | int status; |
| 7022 | struct nfs4_secinfo_arg args = { |
| 7023 | .dir_fh = NFS_FH(dir), |
| 7024 | .name = name, |
| 7025 | }; |
| 7026 | struct nfs4_secinfo_res res = { |
| 7027 | .flavors = flavors, |
| 7028 | }; |
| 7029 | struct rpc_message msg = { |
| 7030 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7031 | .rpc_argp = &args, |
| 7032 | .rpc_resp = &res, |
| 7033 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7034 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7035 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7036 | |
| 7037 | if (use_integrity) { |
| 7038 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7039 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7040 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7041 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7042 | |
| 7043 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7044 | |
| 7045 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7046 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7047 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7048 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7049 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7050 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7051 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7052 | if (cred) |
| 7053 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7054 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7055 | return status; |
| 7056 | } |
| 7057 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7058 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7059 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7060 | { |
| 7061 | struct nfs4_exception exception = { }; |
| 7062 | int err; |
| 7063 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7064 | err = -NFS4ERR_WRONGSEC; |
| 7065 | |
| 7066 | /* try to use integrity protection with machine cred */ |
| 7067 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7068 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7069 | |
| 7070 | /* |
| 7071 | * if unable to use integrity protection, or SECINFO with |
| 7072 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7073 | * disallowed by spec, but exists in deployed servers) use |
| 7074 | * the current filesystem's rpc_client and the user cred. |
| 7075 | */ |
| 7076 | if (err == -NFS4ERR_WRONGSEC) |
| 7077 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7078 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7079 | trace_nfs4_secinfo(dir, name, err); |
| 7080 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7081 | &exception); |
| 7082 | } while (exception.retry); |
| 7083 | return err; |
| 7084 | } |
| 7085 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7086 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7087 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7088 | * Check the exchange flags returned by the server for invalid flags, having |
| 7089 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7090 | * DS flags set. |
| 7091 | */ |
| 7092 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7093 | { |
| 7094 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7095 | goto out_inval; |
| 7096 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7097 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7098 | goto out_inval; |
| 7099 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7100 | goto out_inval; |
| 7101 | return NFS_OK; |
| 7102 | out_inval: |
| 7103 | return -NFS4ERR_INVAL; |
| 7104 | } |
| 7105 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7106 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7107 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7108 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7109 | { |
Anna Schumaker | 49ad014 | 2017-01-11 16:51:59 -0500 | [diff] [blame] | 7110 | if (a->server_scope_sz != b->server_scope_sz) |
| 7111 | return false; |
| 7112 | 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] | 7113 | } |
| 7114 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7115 | static void |
| 7116 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7117 | { |
| 7118 | } |
| 7119 | |
| 7120 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7121 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7122 | }; |
| 7123 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7124 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7125 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7126 | * |
| 7127 | * The 4.1 client currently uses the same TCP connection for the |
| 7128 | * fore and backchannel. |
| 7129 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7130 | static |
| 7131 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7132 | struct rpc_xprt *xprt, |
| 7133 | struct nfs_client *clp, |
| 7134 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7135 | { |
| 7136 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7137 | struct nfs41_bind_conn_to_session_args args = { |
| 7138 | .client = clp, |
| 7139 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7140 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7141 | struct nfs41_bind_conn_to_session_res res; |
| 7142 | struct rpc_message msg = { |
| 7143 | .rpc_proc = |
| 7144 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7145 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7146 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7147 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7148 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7149 | struct rpc_task_setup task_setup_data = { |
| 7150 | .rpc_client = clnt, |
| 7151 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7152 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7153 | .rpc_message = &msg, |
| 7154 | .flags = RPC_TASK_TIMEOUT, |
| 7155 | }; |
| 7156 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7157 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7158 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7159 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7160 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7161 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7162 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7163 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7164 | args.dir = NFS4_CDFC4_FORE; |
| 7165 | |
| 7166 | task = rpc_run_task(&task_setup_data); |
| 7167 | if (!IS_ERR(task)) { |
| 7168 | status = task->tk_status; |
| 7169 | rpc_put_task(task); |
| 7170 | } else |
| 7171 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7172 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7173 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7174 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7175 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7176 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame^] | 7177 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7178 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7179 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7180 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7181 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame^] | 7182 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7183 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7184 | 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] | 7185 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7186 | __func__); |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame^] | 7187 | return -EIO; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7188 | } |
| 7189 | } |
Anna Schumaker | c7ae763 | 2017-04-07 14:15:21 -0400 | [diff] [blame^] | 7190 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7191 | return status; |
| 7192 | } |
| 7193 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7194 | struct rpc_bind_conn_calldata { |
| 7195 | struct nfs_client *clp; |
| 7196 | struct rpc_cred *cred; |
| 7197 | }; |
| 7198 | |
| 7199 | static int |
| 7200 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7201 | struct rpc_xprt *xprt, |
| 7202 | void *calldata) |
| 7203 | { |
| 7204 | struct rpc_bind_conn_calldata *p = calldata; |
| 7205 | |
| 7206 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7207 | } |
| 7208 | |
| 7209 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7210 | { |
| 7211 | struct rpc_bind_conn_calldata data = { |
| 7212 | .clp = clp, |
| 7213 | .cred = cred, |
| 7214 | }; |
| 7215 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7216 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7217 | } |
| 7218 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7219 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7220 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7221 | * 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] | 7222 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7223 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7224 | .how = SP4_MACH_CRED, |
| 7225 | .enforce.u.words = { |
| 7226 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7227 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7228 | 1 << (OP_CREATE_SESSION - 32) | |
| 7229 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7230 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7231 | }, |
| 7232 | .allow.u.words = { |
| 7233 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7234 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7235 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7236 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7237 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7238 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7239 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7240 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7241 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7242 | 1 << (OP_FREE_STATEID - 32) | |
| 7243 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7244 | } |
| 7245 | }; |
| 7246 | |
| 7247 | /* |
| 7248 | * Select the state protection mode for client `clp' given the server results |
| 7249 | * from exchange_id in `sp'. |
| 7250 | * |
| 7251 | * Returns 0 on success, negative errno otherwise. |
| 7252 | */ |
| 7253 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7254 | struct nfs41_state_protection *sp) |
| 7255 | { |
| 7256 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7257 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7258 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7259 | 1 << (OP_CREATE_SESSION - 32) | |
| 7260 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7261 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7262 | }; |
| 7263 | unsigned int i; |
| 7264 | |
| 7265 | if (sp->how == SP4_MACH_CRED) { |
| 7266 | /* Print state protect result */ |
| 7267 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7268 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7269 | if (test_bit(i, sp->enforce.u.longs)) |
| 7270 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7271 | if (test_bit(i, sp->allow.u.longs)) |
| 7272 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7273 | } |
| 7274 | |
| 7275 | /* make sure nothing is on enforce list that isn't supported */ |
| 7276 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7277 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7278 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7279 | return -EINVAL; |
| 7280 | } |
| 7281 | } |
| 7282 | |
| 7283 | /* |
| 7284 | * Minimal mode - state operations are allowed to use machine |
| 7285 | * credential. Note this already happens by default, so the |
| 7286 | * client doesn't have to do anything more than the negotiation. |
| 7287 | * |
| 7288 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7289 | * we're already using the machine cred for exchange_id |
| 7290 | * and will never use a different cred. |
| 7291 | */ |
| 7292 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7293 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7294 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7295 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7296 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7297 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7298 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7299 | } else { |
| 7300 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7301 | return -EINVAL; |
| 7302 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7303 | |
| 7304 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7305 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7306 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7307 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7308 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7309 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7310 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7311 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7312 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7313 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7314 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7315 | &clp->cl_sp4_flags); |
| 7316 | } |
| 7317 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7318 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7319 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7320 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7321 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7322 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7323 | |
| 7324 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7325 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7326 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7327 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7328 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7329 | |
| 7330 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7331 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7332 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7333 | } |
| 7334 | |
| 7335 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7336 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7337 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7338 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | return 0; |
| 7342 | } |
| 7343 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7344 | struct nfs41_exchange_id_data { |
| 7345 | struct nfs41_exchange_id_res res; |
| 7346 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7347 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7348 | int rpc_status; |
| 7349 | }; |
| 7350 | |
| 7351 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7352 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7353 | struct nfs41_exchange_id_data *cdata = |
| 7354 | (struct nfs41_exchange_id_data *)data; |
| 7355 | struct nfs_client *clp = cdata->args.client; |
| 7356 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7357 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7358 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7359 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7360 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7361 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7362 | |
| 7363 | if (cdata->xprt && status == 0) { |
| 7364 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7365 | cdata->xprt); |
| 7366 | goto out; |
| 7367 | } |
| 7368 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7369 | if (status == 0) |
| 7370 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7371 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7372 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7373 | clp->cl_clientid = cdata->res.clientid; |
| 7374 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7375 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7376 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7377 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7378 | &clp->cl_session->session_state); |
| 7379 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7380 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7381 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7382 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7383 | clp->cl_serverowner = cdata->res.server_owner; |
| 7384 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7385 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7386 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7387 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7388 | clp->cl_implid = cdata->res.impl_id; |
| 7389 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7390 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7391 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7392 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7393 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7394 | dprintk("%s: server_scope mismatch detected\n", |
| 7395 | __func__); |
| 7396 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7397 | kfree(clp->cl_serverscope); |
| 7398 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7399 | } |
| 7400 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7401 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7402 | clp->cl_serverscope = cdata->res.server_scope; |
| 7403 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7404 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7405 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7406 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7407 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7408 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7409 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7410 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7411 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | static void nfs4_exchange_id_release(void *data) |
| 7415 | { |
| 7416 | struct nfs41_exchange_id_data *cdata = |
| 7417 | (struct nfs41_exchange_id_data *)data; |
| 7418 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7419 | if (cdata->xprt) { |
| 7420 | xprt_put(cdata->xprt); |
| 7421 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7422 | } |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7423 | nfs_put_client(cdata->args.client); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7424 | kfree(cdata->res.impl_id); |
| 7425 | kfree(cdata->res.server_scope); |
| 7426 | kfree(cdata->res.server_owner); |
| 7427 | kfree(cdata); |
| 7428 | } |
| 7429 | |
| 7430 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7431 | .rpc_call_done = nfs4_exchange_id_done, |
| 7432 | .rpc_release = nfs4_exchange_id_release, |
| 7433 | }; |
| 7434 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7435 | /* |
| 7436 | * _nfs4_proc_exchange_id() |
| 7437 | * |
| 7438 | * Wrapper for EXCHANGE_ID operation. |
| 7439 | */ |
| 7440 | 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] | 7441 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7442 | { |
| 7443 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7444 | struct rpc_message msg = { |
| 7445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7446 | .rpc_cred = cred, |
| 7447 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7448 | struct rpc_task_setup task_setup_data = { |
| 7449 | .rpc_client = clp->cl_rpcclient, |
| 7450 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7451 | .rpc_message = &msg, |
| 7452 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7453 | }; |
| 7454 | struct nfs41_exchange_id_data *calldata; |
| 7455 | struct rpc_task *task; |
| 7456 | int status = -EIO; |
| 7457 | |
| 7458 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7459 | goto out; |
| 7460 | |
| 7461 | status = -ENOMEM; |
| 7462 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7463 | if (!calldata) |
| 7464 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7465 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7466 | if (!xprt) |
| 7467 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7468 | |
| 7469 | status = nfs4_init_uniform_client_string(clp); |
| 7470 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7471 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7472 | |
| 7473 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7474 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7475 | clp->cl_owner_id); |
| 7476 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7477 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7478 | GFP_NOFS); |
| 7479 | status = -ENOMEM; |
| 7480 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7481 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7482 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7483 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7484 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7485 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7486 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7487 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7488 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7489 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7490 | goto out_server_scope; |
| 7491 | |
| 7492 | switch (sp4_how) { |
| 7493 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7494 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7495 | break; |
| 7496 | |
| 7497 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7498 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7499 | break; |
| 7500 | |
| 7501 | default: |
| 7502 | /* unsupported! */ |
| 7503 | WARN_ON_ONCE(1); |
| 7504 | status = -EINVAL; |
| 7505 | goto out_impl_id; |
| 7506 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7507 | if (xprt) { |
| 7508 | calldata->xprt = xprt; |
| 7509 | task_setup_data.rpc_xprt = xprt; |
| 7510 | task_setup_data.flags = |
| 7511 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7512 | calldata->args.verifier = &clp->cl_confirm; |
| 7513 | } else { |
| 7514 | calldata->args.verifier = &verifier; |
| 7515 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7516 | calldata->args.client = clp; |
| 7517 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7518 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7519 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7520 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7521 | #else |
| 7522 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7523 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7524 | #endif |
| 7525 | msg.rpc_argp = &calldata->args; |
| 7526 | msg.rpc_resp = &calldata->res; |
| 7527 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7528 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7529 | task = rpc_run_task(&task_setup_data); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7530 | if (IS_ERR(task)) |
| 7531 | return PTR_ERR(task); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7532 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7533 | if (!xprt) { |
| 7534 | status = rpc_wait_for_completion_task(task); |
| 7535 | if (!status) |
| 7536 | status = calldata->rpc_status; |
| 7537 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7538 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7539 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7540 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7541 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7542 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7543 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7544 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7545 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7546 | clp->cl_implid->date.seconds, |
| 7547 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7548 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7549 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7550 | |
| 7551 | out_impl_id: |
| 7552 | kfree(calldata->res.impl_id); |
| 7553 | out_server_scope: |
| 7554 | kfree(calldata->res.server_scope); |
| 7555 | out_server_owner: |
| 7556 | kfree(calldata->res.server_owner); |
| 7557 | out_calldata: |
| 7558 | kfree(calldata); |
Olga Kornievskaia | 6351323 | 2017-03-13 10:36:19 -0400 | [diff] [blame] | 7559 | nfs_put_client(clp); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7560 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7561 | } |
| 7562 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7563 | /* |
| 7564 | * nfs4_proc_exchange_id() |
| 7565 | * |
| 7566 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7567 | * |
| 7568 | * Since the clientid has expired, all compounds using sessions |
| 7569 | * associated with the stale clientid will be returning |
| 7570 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7571 | * be in some phase of session reset. |
| 7572 | * |
| 7573 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7574 | */ |
| 7575 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7576 | { |
| 7577 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7578 | int status; |
| 7579 | |
| 7580 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7581 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7582 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7583 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7584 | if (!status) |
| 7585 | return 0; |
| 7586 | } |
| 7587 | |
| 7588 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7589 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7590 | } |
| 7591 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7592 | /** |
| 7593 | * nfs4_test_session_trunk |
| 7594 | * |
| 7595 | * This is an add_xprt_test() test function called from |
| 7596 | * rpc_clnt_setup_test_and_add_xprt. |
| 7597 | * |
| 7598 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7599 | * and is dereferrenced in nfs4_exchange_id_release |
| 7600 | * |
| 7601 | * Upon success, add the new transport to the rpc_clnt |
| 7602 | * |
| 7603 | * @clnt: struct rpc_clnt to get new transport |
| 7604 | * @xprt: the rpc_xprt to test |
| 7605 | * @data: call data for _nfs4_proc_exchange_id. |
| 7606 | */ |
| 7607 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7608 | void *data) |
| 7609 | { |
| 7610 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7611 | u32 sp4_how; |
| 7612 | |
| 7613 | dprintk("--> %s try %s\n", __func__, |
| 7614 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7615 | |
| 7616 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7617 | |
| 7618 | /* Test connection for session trunking. Async exchange_id call */ |
| 7619 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7620 | } |
| 7621 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7622 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7623 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7624 | struct rpc_cred *cred) |
| 7625 | { |
| 7626 | struct rpc_message msg = { |
| 7627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7628 | .rpc_argp = clp, |
| 7629 | .rpc_cred = cred, |
| 7630 | }; |
| 7631 | int status; |
| 7632 | |
| 7633 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7634 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7635 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7636 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7637 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7638 | return status; |
| 7639 | } |
| 7640 | |
| 7641 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7642 | struct rpc_cred *cred) |
| 7643 | { |
| 7644 | unsigned int loop; |
| 7645 | int ret; |
| 7646 | |
| 7647 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7648 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7649 | switch (ret) { |
| 7650 | case -NFS4ERR_DELAY: |
| 7651 | case -NFS4ERR_CLIENTID_BUSY: |
| 7652 | ssleep(1); |
| 7653 | break; |
| 7654 | default: |
| 7655 | return ret; |
| 7656 | } |
| 7657 | } |
| 7658 | return 0; |
| 7659 | } |
| 7660 | |
| 7661 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7662 | { |
| 7663 | struct rpc_cred *cred; |
| 7664 | int ret = 0; |
| 7665 | |
| 7666 | if (clp->cl_mvops->minor_version < 1) |
| 7667 | goto out; |
| 7668 | if (clp->cl_exchange_flags == 0) |
| 7669 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7670 | if (clp->cl_preserve_clid) |
| 7671 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7672 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7673 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7674 | if (cred) |
| 7675 | put_rpccred(cred); |
| 7676 | switch (ret) { |
| 7677 | case 0: |
| 7678 | case -NFS4ERR_STALE_CLIENTID: |
| 7679 | clp->cl_exchange_flags = 0; |
| 7680 | } |
| 7681 | out: |
| 7682 | return ret; |
| 7683 | } |
| 7684 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7685 | struct nfs4_get_lease_time_data { |
| 7686 | struct nfs4_get_lease_time_args *args; |
| 7687 | struct nfs4_get_lease_time_res *res; |
| 7688 | struct nfs_client *clp; |
| 7689 | }; |
| 7690 | |
| 7691 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7692 | void *calldata) |
| 7693 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7694 | struct nfs4_get_lease_time_data *data = |
| 7695 | (struct nfs4_get_lease_time_data *)calldata; |
| 7696 | |
| 7697 | dprintk("--> %s\n", __func__); |
| 7698 | /* just setup sequence, do not trigger session recovery |
| 7699 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7700 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7701 | &data->args->la_seq_args, |
| 7702 | &data->res->lr_seq_res, |
| 7703 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7704 | dprintk("<-- %s\n", __func__); |
| 7705 | } |
| 7706 | |
| 7707 | /* |
| 7708 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7709 | * from sequence operation or clientid errors. |
| 7710 | */ |
| 7711 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7712 | { |
| 7713 | struct nfs4_get_lease_time_data *data = |
| 7714 | (struct nfs4_get_lease_time_data *)calldata; |
| 7715 | |
| 7716 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7717 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7718 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7719 | switch (task->tk_status) { |
| 7720 | case -NFS4ERR_DELAY: |
| 7721 | case -NFS4ERR_GRACE: |
| 7722 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7723 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7724 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7725 | /* fall through */ |
| 7726 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7727 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7728 | return; |
| 7729 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7730 | dprintk("<-- %s\n", __func__); |
| 7731 | } |
| 7732 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7733 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7734 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7735 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7736 | }; |
| 7737 | |
| 7738 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7739 | { |
| 7740 | struct rpc_task *task; |
| 7741 | struct nfs4_get_lease_time_args args; |
| 7742 | struct nfs4_get_lease_time_res res = { |
| 7743 | .lr_fsinfo = fsinfo, |
| 7744 | }; |
| 7745 | struct nfs4_get_lease_time_data data = { |
| 7746 | .args = &args, |
| 7747 | .res = &res, |
| 7748 | .clp = clp, |
| 7749 | }; |
| 7750 | struct rpc_message msg = { |
| 7751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7752 | .rpc_argp = &args, |
| 7753 | .rpc_resp = &res, |
| 7754 | }; |
| 7755 | struct rpc_task_setup task_setup = { |
| 7756 | .rpc_client = clp->cl_rpcclient, |
| 7757 | .rpc_message = &msg, |
| 7758 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7759 | .callback_data = &data, |
| 7760 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7761 | }; |
| 7762 | int status; |
| 7763 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7764 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7765 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7766 | dprintk("--> %s\n", __func__); |
| 7767 | task = rpc_run_task(&task_setup); |
| 7768 | |
| 7769 | if (IS_ERR(task)) |
| 7770 | status = PTR_ERR(task); |
| 7771 | else { |
| 7772 | status = task->tk_status; |
| 7773 | rpc_put_task(task); |
| 7774 | } |
| 7775 | dprintk("<-- %s return %d\n", __func__, status); |
| 7776 | |
| 7777 | return status; |
| 7778 | } |
| 7779 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7780 | /* |
| 7781 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7782 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7783 | * use them. |
| 7784 | * |
| 7785 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7786 | * always set csa_cachethis to FALSE because the current implementation |
| 7787 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7788 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7789 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7790 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7791 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7792 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7793 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7794 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7795 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7796 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7797 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7798 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7799 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7800 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7801 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7802 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7803 | |
| 7804 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7805 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7806 | __func__, |
| 7807 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7808 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7809 | |
| 7810 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7811 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7812 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7813 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7814 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7815 | 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] | 7816 | |
| 7817 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7818 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7819 | __func__, |
| 7820 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7821 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7822 | args->bc_attrs.max_reqs); |
| 7823 | } |
| 7824 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7825 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7826 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7827 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7828 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7829 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7830 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7831 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7832 | return -EINVAL; |
| 7833 | /* |
| 7834 | * Our requested max_ops is the minimum we need; we're not |
| 7835 | * prepared to break up compounds into smaller pieces than that. |
| 7836 | * So, no point even trying to continue if the server won't |
| 7837 | * cooperate: |
| 7838 | */ |
| 7839 | if (rcvd->max_ops < sent->max_ops) |
| 7840 | return -EINVAL; |
| 7841 | if (rcvd->max_reqs == 0) |
| 7842 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7843 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7844 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7845 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7846 | } |
| 7847 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7848 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7849 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7850 | { |
| 7851 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7852 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7853 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7854 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7855 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7856 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7857 | return -EINVAL; |
| 7858 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7859 | return -EINVAL; |
| 7860 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7861 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7862 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7863 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7864 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7865 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7866 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7867 | return 0; |
| 7868 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7869 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7870 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7871 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7872 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7873 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7874 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7875 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7876 | if (ret) |
| 7877 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7878 | return nfs4_verify_back_channel_attrs(args, res); |
| 7879 | } |
| 7880 | |
| 7881 | static void nfs4_update_session(struct nfs4_session *session, |
| 7882 | struct nfs41_create_session_res *res) |
| 7883 | { |
| 7884 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7885 | /* Mark client id and session as being confirmed */ |
| 7886 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7887 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7888 | session->flags = res->flags; |
| 7889 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7890 | if (res->flags & SESSION4_BACK_CHAN) |
| 7891 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7892 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7893 | } |
| 7894 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7895 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7896 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7897 | { |
| 7898 | struct nfs4_session *session = clp->cl_session; |
| 7899 | struct nfs41_create_session_args args = { |
| 7900 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7901 | .clientid = clp->cl_clientid, |
| 7902 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7903 | .cb_program = NFS4_CALLBACK, |
| 7904 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7905 | struct nfs41_create_session_res res; |
| 7906 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7907 | struct rpc_message msg = { |
| 7908 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7909 | .rpc_argp = &args, |
| 7910 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7911 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7912 | }; |
| 7913 | int status; |
| 7914 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7915 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7916 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7917 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7918 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7919 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7920 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7921 | switch (status) { |
| 7922 | case -NFS4ERR_STALE_CLIENTID: |
| 7923 | case -NFS4ERR_DELAY: |
| 7924 | case -ETIMEDOUT: |
| 7925 | case -EACCES: |
| 7926 | case -EAGAIN: |
| 7927 | goto out; |
| 7928 | }; |
| 7929 | |
| 7930 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7931 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7932 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7933 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7934 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7935 | if (status) |
| 7936 | goto out; |
| 7937 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7938 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7939 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7940 | return status; |
| 7941 | } |
| 7942 | |
| 7943 | /* |
| 7944 | * Issues a CREATE_SESSION operation to the server. |
| 7945 | * It is the responsibility of the caller to verify the session is |
| 7946 | * expired before calling this routine. |
| 7947 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7948 | 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] | 7949 | { |
| 7950 | int status; |
| 7951 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7952 | struct nfs4_session *session = clp->cl_session; |
| 7953 | |
| 7954 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7955 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7956 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7957 | if (status) |
| 7958 | goto out; |
| 7959 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7960 | /* Init or reset the session slot tables */ |
| 7961 | status = nfs4_setup_session_slot_tables(session); |
| 7962 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7963 | if (status) |
| 7964 | goto out; |
| 7965 | |
| 7966 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7967 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7968 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7969 | out: |
| 7970 | dprintk("<-- %s\n", __func__); |
| 7971 | return status; |
| 7972 | } |
| 7973 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7974 | /* |
| 7975 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7976 | * The caller must serialize access to this routine. |
| 7977 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7978 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7979 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7980 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7981 | struct rpc_message msg = { |
| 7982 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7983 | .rpc_argp = session, |
| 7984 | .rpc_cred = cred, |
| 7985 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7986 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7987 | |
| 7988 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7989 | |
| 7990 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7991 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7992 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7993 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7994 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7995 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7996 | |
| 7997 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7998 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7999 | "Session has been destroyed regardless...\n", status); |
| 8000 | |
| 8001 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8002 | return status; |
| 8003 | } |
| 8004 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8005 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8006 | * Renew the cl_session lease. |
| 8007 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8008 | struct nfs4_sequence_data { |
| 8009 | struct nfs_client *clp; |
| 8010 | struct nfs4_sequence_args args; |
| 8011 | struct nfs4_sequence_res res; |
| 8012 | }; |
| 8013 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8014 | static void nfs41_sequence_release(void *data) |
| 8015 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8016 | struct nfs4_sequence_data *calldata = data; |
| 8017 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8018 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8019 | if (atomic_read(&clp->cl_count) > 1) |
| 8020 | nfs4_schedule_state_renewal(clp); |
| 8021 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8022 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8023 | } |
| 8024 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8025 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8026 | { |
| 8027 | switch(task->tk_status) { |
| 8028 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8029 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8030 | return -EAGAIN; |
| 8031 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8032 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8033 | } |
| 8034 | return 0; |
| 8035 | } |
| 8036 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8037 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8038 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8039 | struct nfs4_sequence_data *calldata = data; |
| 8040 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8041 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8042 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8043 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8044 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8045 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8046 | if (task->tk_status < 0) { |
| 8047 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8048 | if (atomic_read(&clp->cl_count) == 1) |
| 8049 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8050 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8051 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8052 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8053 | return; |
| 8054 | } |
| 8055 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8056 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8057 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8058 | dprintk("<-- %s\n", __func__); |
| 8059 | } |
| 8060 | |
| 8061 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8062 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8063 | struct nfs4_sequence_data *calldata = data; |
| 8064 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8065 | struct nfs4_sequence_args *args; |
| 8066 | struct nfs4_sequence_res *res; |
| 8067 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8068 | args = task->tk_msg.rpc_argp; |
| 8069 | res = task->tk_msg.rpc_resp; |
| 8070 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8071 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8072 | } |
| 8073 | |
| 8074 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8075 | .rpc_call_done = nfs41_sequence_call_done, |
| 8076 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8077 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8078 | }; |
| 8079 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8080 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8081 | struct rpc_cred *cred, |
| 8082 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8083 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8084 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8085 | struct rpc_message msg = { |
| 8086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8087 | .rpc_cred = cred, |
| 8088 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8089 | struct rpc_task_setup task_setup_data = { |
| 8090 | .rpc_client = clp->cl_rpcclient, |
| 8091 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8092 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8093 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8094 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8095 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8096 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8097 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8098 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8099 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8100 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8101 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8102 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8103 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8104 | if (is_privileged) |
| 8105 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8106 | msg.rpc_argp = &calldata->args; |
| 8107 | msg.rpc_resp = &calldata->res; |
| 8108 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8109 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8110 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8111 | return rpc_run_task(&task_setup_data); |
| 8112 | } |
| 8113 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8114 | 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] | 8115 | { |
| 8116 | struct rpc_task *task; |
| 8117 | int ret = 0; |
| 8118 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8119 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8120 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8121 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8122 | if (IS_ERR(task)) |
| 8123 | ret = PTR_ERR(task); |
| 8124 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8125 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8126 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8127 | return ret; |
| 8128 | } |
| 8129 | |
| 8130 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8131 | { |
| 8132 | struct rpc_task *task; |
| 8133 | int ret; |
| 8134 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8135 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8136 | if (IS_ERR(task)) { |
| 8137 | ret = PTR_ERR(task); |
| 8138 | goto out; |
| 8139 | } |
| 8140 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8141 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8142 | ret = task->tk_status; |
| 8143 | rpc_put_task(task); |
| 8144 | out: |
| 8145 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8146 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8147 | } |
| 8148 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8149 | struct nfs4_reclaim_complete_data { |
| 8150 | struct nfs_client *clp; |
| 8151 | struct nfs41_reclaim_complete_args arg; |
| 8152 | struct nfs41_reclaim_complete_res res; |
| 8153 | }; |
| 8154 | |
| 8155 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8156 | { |
| 8157 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8158 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8159 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8160 | &calldata->arg.seq_args, |
| 8161 | &calldata->res.seq_res, |
| 8162 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8163 | } |
| 8164 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8165 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8166 | { |
| 8167 | switch(task->tk_status) { |
| 8168 | case 0: |
| 8169 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8170 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8171 | break; |
| 8172 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8173 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8174 | /* fall through */ |
| 8175 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8176 | return -EAGAIN; |
| 8177 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8178 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8179 | } |
| 8180 | return 0; |
| 8181 | } |
| 8182 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8183 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8184 | { |
| 8185 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8186 | struct nfs_client *clp = calldata->clp; |
| 8187 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8188 | |
| 8189 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8190 | if (!nfs41_sequence_done(task, res)) |
| 8191 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8192 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8193 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8194 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8195 | rpc_restart_call_prepare(task); |
| 8196 | return; |
| 8197 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8198 | dprintk("<-- %s\n", __func__); |
| 8199 | } |
| 8200 | |
| 8201 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8202 | { |
| 8203 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8204 | |
| 8205 | kfree(calldata); |
| 8206 | } |
| 8207 | |
| 8208 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8209 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8210 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8211 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8212 | }; |
| 8213 | |
| 8214 | /* |
| 8215 | * Issue a global reclaim complete. |
| 8216 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8217 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8218 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8219 | { |
| 8220 | struct nfs4_reclaim_complete_data *calldata; |
| 8221 | struct rpc_task *task; |
| 8222 | struct rpc_message msg = { |
| 8223 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8224 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8225 | }; |
| 8226 | struct rpc_task_setup task_setup_data = { |
| 8227 | .rpc_client = clp->cl_rpcclient, |
| 8228 | .rpc_message = &msg, |
| 8229 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8230 | .flags = RPC_TASK_ASYNC, |
| 8231 | }; |
| 8232 | int status = -ENOMEM; |
| 8233 | |
| 8234 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8235 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8236 | if (calldata == NULL) |
| 8237 | goto out; |
| 8238 | calldata->clp = clp; |
| 8239 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8240 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8241 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8242 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8243 | msg.rpc_argp = &calldata->arg; |
| 8244 | msg.rpc_resp = &calldata->res; |
| 8245 | task_setup_data.callback_data = calldata; |
| 8246 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8247 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8248 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8249 | goto out; |
| 8250 | } |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8251 | status = rpc_wait_for_completion_task(task); |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8252 | if (status == 0) |
| 8253 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8254 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8255 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8256 | out: |
| 8257 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8258 | return status; |
| 8259 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8260 | |
| 8261 | static void |
| 8262 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8263 | { |
| 8264 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8265 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8266 | |
| 8267 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8268 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8269 | &lgp->res.seq_res, task); |
| 8270 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8271 | } |
| 8272 | |
| 8273 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8274 | { |
| 8275 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8276 | |
| 8277 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8278 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8279 | dprintk("<-- %s\n", __func__); |
| 8280 | } |
| 8281 | |
| 8282 | static int |
| 8283 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8284 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8285 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8286 | struct inode *inode = lgp->args.inode; |
| 8287 | struct nfs_server *server = NFS_SERVER(inode); |
| 8288 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8289 | int nfs4err = task->tk_status; |
| 8290 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8291 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8292 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8293 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8294 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8295 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8296 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8297 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8298 | |
| 8299 | /* |
| 8300 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8301 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8302 | * retry go inband. |
| 8303 | */ |
| 8304 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8305 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8306 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8307 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8308 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8309 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8310 | */ |
| 8311 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8312 | status = -EOVERFLOW; |
| 8313 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8314 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8315 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8316 | * (or clients) writing to the same RAID stripe except when |
| 8317 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8318 | * |
| 8319 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8320 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8321 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8322 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8323 | if (lgp->args.minlength == 0) { |
| 8324 | status = -EOVERFLOW; |
| 8325 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8326 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8327 | status = -EBUSY; |
| 8328 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8329 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8330 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8331 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8332 | case -NFS4ERR_DELEG_REVOKED: |
| 8333 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8334 | case -NFS4ERR_EXPIRED: |
| 8335 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8336 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8337 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8338 | lo = NFS_I(inode)->layout; |
| 8339 | /* If the open stateid was bad, then recover it. */ |
| 8340 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8341 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8342 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8343 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8344 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8345 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8346 | break; |
| 8347 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8348 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8349 | /* |
| 8350 | * Mark the bad layout state as invalid, then retry |
| 8351 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8352 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8353 | spin_unlock(&inode->i_lock); |
| 8354 | pnfs_free_lseg_list(&head); |
| 8355 | status = -EAGAIN; |
| 8356 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8357 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8358 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8359 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8360 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8361 | if (!status) { |
| 8362 | if (exception->retry) |
| 8363 | status = -EAGAIN; |
| 8364 | else |
| 8365 | status = err; |
| 8366 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8367 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8368 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8369 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8370 | } |
| 8371 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8372 | static size_t max_response_pages(struct nfs_server *server) |
| 8373 | { |
| 8374 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8375 | return nfs_page_array_len(0, max_resp_sz); |
| 8376 | } |
| 8377 | |
| 8378 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8379 | { |
| 8380 | int i; |
| 8381 | |
| 8382 | if (!pages) |
| 8383 | return; |
| 8384 | |
| 8385 | for (i = 0; i < size; i++) { |
| 8386 | if (!pages[i]) |
| 8387 | break; |
| 8388 | __free_page(pages[i]); |
| 8389 | } |
| 8390 | kfree(pages); |
| 8391 | } |
| 8392 | |
| 8393 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8394 | { |
| 8395 | struct page **pages; |
| 8396 | int i; |
| 8397 | |
| 8398 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8399 | if (!pages) { |
| 8400 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8401 | return NULL; |
| 8402 | } |
| 8403 | |
| 8404 | for (i = 0; i < size; i++) { |
| 8405 | pages[i] = alloc_page(gfp_flags); |
| 8406 | if (!pages[i]) { |
| 8407 | dprintk("%s: failed to allocate page\n", __func__); |
| 8408 | nfs4_free_pages(pages, size); |
| 8409 | return NULL; |
| 8410 | } |
| 8411 | } |
| 8412 | |
| 8413 | return pages; |
| 8414 | } |
| 8415 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8416 | static void nfs4_layoutget_release(void *calldata) |
| 8417 | { |
| 8418 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8419 | struct inode *inode = lgp->args.inode; |
| 8420 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8421 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8422 | |
| 8423 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8424 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8425 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8426 | put_nfs_open_context(lgp->args.ctx); |
| 8427 | kfree(calldata); |
| 8428 | dprintk("<-- %s\n", __func__); |
| 8429 | } |
| 8430 | |
| 8431 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8432 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8433 | .rpc_call_done = nfs4_layoutget_done, |
| 8434 | .rpc_release = nfs4_layoutget_release, |
| 8435 | }; |
| 8436 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8437 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8438 | 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] | 8439 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8440 | struct inode *inode = lgp->args.inode; |
| 8441 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8442 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8443 | struct rpc_task *task; |
| 8444 | struct rpc_message msg = { |
| 8445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8446 | .rpc_argp = &lgp->args, |
| 8447 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8448 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8449 | }; |
| 8450 | struct rpc_task_setup task_setup_data = { |
| 8451 | .rpc_client = server->client, |
| 8452 | .rpc_message = &msg, |
| 8453 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8454 | .callback_data = lgp, |
| 8455 | .flags = RPC_TASK_ASYNC, |
| 8456 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8457 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8458 | struct nfs4_exception exception = { |
| 8459 | .inode = inode, |
| 8460 | .timeout = *timeout, |
| 8461 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8462 | int status = 0; |
| 8463 | |
| 8464 | dprintk("--> %s\n", __func__); |
| 8465 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8466 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8467 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8468 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8469 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8470 | if (!lgp->args.layout.pages) { |
| 8471 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8472 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8473 | } |
| 8474 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8475 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8476 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8477 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8478 | 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] | 8479 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8480 | task = rpc_run_task(&task_setup_data); |
| 8481 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8482 | return ERR_CAST(task); |
Anna Schumaker | 820bf85 | 2017-01-11 15:01:43 -0500 | [diff] [blame] | 8483 | status = rpc_wait_for_completion_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8484 | if (status == 0) { |
| 8485 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8486 | *timeout = exception.timeout; |
| 8487 | } |
| 8488 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8489 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8490 | &lgp->args.range, |
| 8491 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8492 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8493 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8494 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8495 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8496 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8497 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8498 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8499 | rpc_put_task(task); |
| 8500 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8501 | if (status) |
| 8502 | return ERR_PTR(status); |
| 8503 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8504 | } |
| 8505 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8506 | static void |
| 8507 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8508 | { |
| 8509 | struct nfs4_layoutreturn *lrp = calldata; |
| 8510 | |
| 8511 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8512 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8513 | &lrp->args.seq_args, |
| 8514 | &lrp->res.seq_res, |
| 8515 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8516 | } |
| 8517 | |
| 8518 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8519 | { |
| 8520 | struct nfs4_layoutreturn *lrp = calldata; |
| 8521 | struct nfs_server *server; |
| 8522 | |
| 8523 | dprintk("--> %s\n", __func__); |
| 8524 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8525 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8526 | return; |
| 8527 | |
| 8528 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8529 | switch (task->tk_status) { |
| 8530 | default: |
| 8531 | task->tk_status = 0; |
| 8532 | case 0: |
| 8533 | break; |
| 8534 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8535 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8536 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8537 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8538 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8539 | return; |
| 8540 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8541 | dprintk("<-- %s\n", __func__); |
| 8542 | } |
| 8543 | |
| 8544 | static void nfs4_layoutreturn_release(void *calldata) |
| 8545 | { |
| 8546 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8547 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8548 | |
| 8549 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8550 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8551 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8552 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8553 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8554 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8555 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8556 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8557 | kfree(calldata); |
| 8558 | dprintk("<-- %s\n", __func__); |
| 8559 | } |
| 8560 | |
| 8561 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8562 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8563 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8564 | .rpc_release = nfs4_layoutreturn_release, |
| 8565 | }; |
| 8566 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8567 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8568 | { |
| 8569 | struct rpc_task *task; |
| 8570 | struct rpc_message msg = { |
| 8571 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8572 | .rpc_argp = &lrp->args, |
| 8573 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8574 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8575 | }; |
| 8576 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8577 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8578 | .rpc_message = &msg, |
| 8579 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8580 | .callback_data = lrp, |
| 8581 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8582 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8583 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8584 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8585 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8586 | &task_setup_data.rpc_client, &msg); |
| 8587 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8588 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8589 | if (!sync) { |
| 8590 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8591 | if (!lrp->inode) { |
| 8592 | nfs4_layoutreturn_release(lrp); |
| 8593 | return -EAGAIN; |
| 8594 | } |
| 8595 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8596 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8597 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8598 | task = rpc_run_task(&task_setup_data); |
| 8599 | if (IS_ERR(task)) |
| 8600 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8601 | if (sync) |
| 8602 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8603 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8604 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8605 | rpc_put_task(task); |
| 8606 | return status; |
| 8607 | } |
| 8608 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8609 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8610 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8611 | struct pnfs_device *pdev, |
| 8612 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8613 | { |
| 8614 | struct nfs4_getdeviceinfo_args args = { |
| 8615 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8616 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8617 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8618 | }; |
| 8619 | struct nfs4_getdeviceinfo_res res = { |
| 8620 | .pdev = pdev, |
| 8621 | }; |
| 8622 | struct rpc_message msg = { |
| 8623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8624 | .rpc_argp = &args, |
| 8625 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8626 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8627 | }; |
| 8628 | int status; |
| 8629 | |
| 8630 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8631 | 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] | 8632 | if (res.notification & ~args.notify_types) |
| 8633 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8634 | if (res.notification != args.notify_types) |
| 8635 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8636 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8637 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8638 | |
| 8639 | return status; |
| 8640 | } |
| 8641 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8642 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8643 | struct pnfs_device *pdev, |
| 8644 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8645 | { |
| 8646 | struct nfs4_exception exception = { }; |
| 8647 | int err; |
| 8648 | |
| 8649 | do { |
| 8650 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8651 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8652 | &exception); |
| 8653 | } while (exception.retry); |
| 8654 | return err; |
| 8655 | } |
| 8656 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8657 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8658 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8659 | { |
| 8660 | struct nfs4_layoutcommit_data *data = calldata; |
| 8661 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8662 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8663 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8664 | &data->args.seq_args, |
| 8665 | &data->res.seq_res, |
| 8666 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | static void |
| 8670 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8671 | { |
| 8672 | struct nfs4_layoutcommit_data *data = calldata; |
| 8673 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8674 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8675 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8676 | return; |
| 8677 | |
| 8678 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8679 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8680 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8681 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8682 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8683 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8684 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8685 | break; |
| 8686 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8687 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8688 | rpc_restart_call_prepare(task); |
| 8689 | return; |
| 8690 | } |
| 8691 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8692 | } |
| 8693 | |
| 8694 | static void nfs4_layoutcommit_release(void *calldata) |
| 8695 | { |
| 8696 | struct nfs4_layoutcommit_data *data = calldata; |
| 8697 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8698 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8699 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8700 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8701 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8702 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8703 | kfree(data); |
| 8704 | } |
| 8705 | |
| 8706 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8707 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8708 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8709 | .rpc_release = nfs4_layoutcommit_release, |
| 8710 | }; |
| 8711 | |
| 8712 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8713 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8714 | { |
| 8715 | struct rpc_message msg = { |
| 8716 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8717 | .rpc_argp = &data->args, |
| 8718 | .rpc_resp = &data->res, |
| 8719 | .rpc_cred = data->cred, |
| 8720 | }; |
| 8721 | struct rpc_task_setup task_setup_data = { |
| 8722 | .task = &data->task, |
| 8723 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8724 | .rpc_message = &msg, |
| 8725 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8726 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8727 | }; |
| 8728 | struct rpc_task *task; |
| 8729 | int status = 0; |
| 8730 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8731 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8732 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8733 | data->args.lastbytewritten, |
| 8734 | data->args.inode->i_ino); |
| 8735 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8736 | if (!sync) { |
| 8737 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8738 | if (data->inode == NULL) { |
| 8739 | nfs4_layoutcommit_release(data); |
| 8740 | return -EAGAIN; |
| 8741 | } |
| 8742 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8743 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8744 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8745 | task = rpc_run_task(&task_setup_data); |
| 8746 | if (IS_ERR(task)) |
| 8747 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8748 | if (sync) |
| 8749 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8750 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8751 | dprintk("%s: status %d\n", __func__, status); |
| 8752 | rpc_put_task(task); |
| 8753 | return status; |
| 8754 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8755 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8756 | /** |
| 8757 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8758 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8759 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8760 | static int |
| 8761 | _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] | 8762 | struct nfs_fsinfo *info, |
| 8763 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8764 | { |
| 8765 | struct nfs41_secinfo_no_name_args args = { |
| 8766 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8767 | }; |
| 8768 | struct nfs4_secinfo_res res = { |
| 8769 | .flavors = flavors, |
| 8770 | }; |
| 8771 | struct rpc_message msg = { |
| 8772 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8773 | .rpc_argp = &args, |
| 8774 | .rpc_resp = &res, |
| 8775 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8776 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8777 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8778 | int status; |
| 8779 | |
| 8780 | if (use_integrity) { |
| 8781 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8782 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8783 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8784 | } |
| 8785 | |
| 8786 | dprintk("--> %s\n", __func__); |
| 8787 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8788 | &res.seq_res, 0); |
| 8789 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8790 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8791 | if (cred) |
| 8792 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8793 | |
| 8794 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8795 | } |
| 8796 | |
| 8797 | static int |
| 8798 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8799 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8800 | { |
| 8801 | struct nfs4_exception exception = { }; |
| 8802 | int err; |
| 8803 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8804 | /* first try using integrity protection */ |
| 8805 | err = -NFS4ERR_WRONGSEC; |
| 8806 | |
| 8807 | /* try to use integrity protection with machine cred */ |
| 8808 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8809 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8810 | flavors, true); |
| 8811 | |
| 8812 | /* |
| 8813 | * if unable to use integrity protection, or SECINFO with |
| 8814 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8815 | * disallowed by spec, but exists in deployed servers) use |
| 8816 | * the current filesystem's rpc_client and the user cred. |
| 8817 | */ |
| 8818 | if (err == -NFS4ERR_WRONGSEC) |
| 8819 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8820 | flavors, false); |
| 8821 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8822 | switch (err) { |
| 8823 | case 0: |
| 8824 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8825 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8826 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8827 | default: |
| 8828 | err = nfs4_handle_exception(server, err, &exception); |
| 8829 | } |
| 8830 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8831 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8832 | return err; |
| 8833 | } |
| 8834 | |
| 8835 | static int |
| 8836 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8837 | struct nfs_fsinfo *info) |
| 8838 | { |
| 8839 | int err; |
| 8840 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8841 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8842 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8843 | struct nfs4_secinfo4 *secinfo; |
| 8844 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8845 | |
| 8846 | page = alloc_page(GFP_KERNEL); |
| 8847 | if (!page) { |
| 8848 | err = -ENOMEM; |
| 8849 | goto out; |
| 8850 | } |
| 8851 | |
| 8852 | flavors = page_address(page); |
| 8853 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8854 | |
| 8855 | /* |
| 8856 | * Fall back on "guess and check" method if |
| 8857 | * the server doesn't support SECINFO_NO_NAME |
| 8858 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8859 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8860 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8861 | goto out_freepage; |
| 8862 | } |
| 8863 | if (err) |
| 8864 | goto out_freepage; |
| 8865 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8866 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8867 | secinfo = &flavors->flavors[i]; |
| 8868 | |
| 8869 | switch (secinfo->flavor) { |
| 8870 | case RPC_AUTH_NULL: |
| 8871 | case RPC_AUTH_UNIX: |
| 8872 | case RPC_AUTH_GSS: |
| 8873 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8874 | &secinfo->flavor_info); |
| 8875 | break; |
| 8876 | default: |
| 8877 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8878 | break; |
| 8879 | } |
| 8880 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8881 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8882 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8883 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8884 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8885 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8886 | info, flavor); |
| 8887 | if (!err) |
| 8888 | break; |
| 8889 | } |
| 8890 | } |
| 8891 | |
| 8892 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8893 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8894 | |
| 8895 | out_freepage: |
| 8896 | put_page(page); |
| 8897 | if (err == -EACCES) |
| 8898 | return -EPERM; |
| 8899 | out: |
| 8900 | return err; |
| 8901 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8902 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8903 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8904 | nfs4_stateid *stateid, |
| 8905 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8906 | { |
| 8907 | int status; |
| 8908 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8909 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8910 | }; |
| 8911 | struct nfs41_test_stateid_res res; |
| 8912 | struct rpc_message msg = { |
| 8913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8914 | .rpc_argp = &args, |
| 8915 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8916 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8917 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8918 | struct rpc_clnt *rpc_client = server->client; |
| 8919 | |
| 8920 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8921 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8922 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8923 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8924 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8925 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8926 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8927 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8928 | if (status != NFS_OK) { |
| 8929 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8930 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8931 | } |
| 8932 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8933 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8934 | } |
| 8935 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8936 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8937 | int err, struct nfs4_exception *exception) |
| 8938 | { |
| 8939 | exception->retry = 0; |
| 8940 | switch(err) { |
| 8941 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8942 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8943 | nfs4_handle_exception(server, err, exception); |
| 8944 | break; |
| 8945 | case -NFS4ERR_BADSESSION: |
| 8946 | case -NFS4ERR_BADSLOT: |
| 8947 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8948 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8949 | case -NFS4ERR_DEADSESSION: |
| 8950 | nfs4_do_handle_exception(server, err, exception); |
| 8951 | } |
| 8952 | } |
| 8953 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8954 | /** |
| 8955 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8956 | * |
| 8957 | * @server: server / transport on which to perform the operation |
| 8958 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8959 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8960 | * |
| 8961 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8962 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8963 | * failed or the state ID is not currently valid. |
| 8964 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8965 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8966 | nfs4_stateid *stateid, |
| 8967 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8968 | { |
| 8969 | struct nfs4_exception exception = { }; |
| 8970 | int err; |
| 8971 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8972 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8973 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8974 | } while (exception.retry); |
| 8975 | return err; |
| 8976 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8977 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8978 | struct nfs_free_stateid_data { |
| 8979 | struct nfs_server *server; |
| 8980 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8981 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8982 | }; |
| 8983 | |
| 8984 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8985 | { |
| 8986 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8987 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8988 | &data->args.seq_args, |
| 8989 | &data->res.seq_res, |
| 8990 | task); |
| 8991 | } |
| 8992 | |
| 8993 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8994 | { |
| 8995 | struct nfs_free_stateid_data *data = calldata; |
| 8996 | |
| 8997 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8998 | |
| 8999 | switch (task->tk_status) { |
| 9000 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9001 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9002 | rpc_restart_call_prepare(task); |
| 9003 | } |
| 9004 | } |
| 9005 | |
| 9006 | static void nfs41_free_stateid_release(void *calldata) |
| 9007 | { |
| 9008 | kfree(calldata); |
| 9009 | } |
| 9010 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9011 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9012 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9013 | .rpc_call_done = nfs41_free_stateid_done, |
| 9014 | .rpc_release = nfs41_free_stateid_release, |
| 9015 | }; |
| 9016 | |
| 9017 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9018 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9019 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9020 | bool privileged) |
| 9021 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9022 | struct rpc_message msg = { |
| 9023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9024 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9025 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9026 | struct rpc_task_setup task_setup = { |
| 9027 | .rpc_client = server->client, |
| 9028 | .rpc_message = &msg, |
| 9029 | .callback_ops = &nfs41_free_stateid_ops, |
| 9030 | .flags = RPC_TASK_ASYNC, |
| 9031 | }; |
| 9032 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9033 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9034 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9035 | &task_setup.rpc_client, &msg); |
| 9036 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9037 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9038 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9039 | if (!data) |
| 9040 | return ERR_PTR(-ENOMEM); |
| 9041 | data->server = server; |
| 9042 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9043 | |
| 9044 | task_setup.callback_data = data; |
| 9045 | |
| 9046 | msg.rpc_argp = &data->args; |
| 9047 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9048 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9049 | if (privileged) |
| 9050 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9051 | |
| 9052 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9053 | } |
| 9054 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9055 | /** |
| 9056 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9057 | * |
| 9058 | * @server: server / transport on which to perform the operation |
| 9059 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9060 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9061 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9062 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9063 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9064 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9065 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9066 | const nfs4_stateid *stateid, |
| 9067 | struct rpc_cred *cred, |
| 9068 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9069 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9070 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9071 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9072 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9073 | if (IS_ERR(task)) |
| 9074 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9075 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9076 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9077 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9078 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9079 | static void |
| 9080 | 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] | 9081 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9082 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9083 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9084 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9085 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9086 | } |
| 9087 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9088 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9089 | const nfs4_stateid *s2) |
| 9090 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9091 | if (s1->type != s2->type) |
| 9092 | return false; |
| 9093 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9094 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9095 | return false; |
| 9096 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9097 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9098 | return true; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9099 | |
Anna Schumaker | 045c551 | 2017-01-11 16:59:48 -0500 | [diff] [blame] | 9100 | return s1->seqid == 0 || s2->seqid == 0; |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9101 | } |
| 9102 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9103 | #endif /* CONFIG_NFS_V4_1 */ |
| 9104 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9105 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9106 | const nfs4_stateid *s2) |
| 9107 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9108 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9109 | } |
| 9110 | |
| 9111 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9112 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9113 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9114 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9115 | .recover_open = nfs4_open_reclaim, |
| 9116 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9117 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9118 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9119 | }; |
| 9120 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9121 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9122 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9123 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9124 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9125 | .recover_open = nfs4_open_reclaim, |
| 9126 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9127 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9128 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9129 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9130 | }; |
| 9131 | #endif /* CONFIG_NFS_V4_1 */ |
| 9132 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9133 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9134 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9135 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9136 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9137 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9138 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9139 | }; |
| 9140 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9141 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9142 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9143 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9144 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9145 | .recover_open = nfs41_open_expired, |
| 9146 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9147 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9148 | }; |
| 9149 | #endif /* CONFIG_NFS_V4_1 */ |
| 9150 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9151 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9152 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9153 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9154 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9155 | }; |
| 9156 | |
| 9157 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9158 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9159 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9160 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9161 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9162 | }; |
| 9163 | #endif |
| 9164 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9165 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9166 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9167 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9168 | }; |
| 9169 | |
| 9170 | #if defined(CONFIG_NFS_V4_1) |
| 9171 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9172 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9173 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9174 | }; |
| 9175 | #endif /* CONFIG_NFS_V4_1 */ |
| 9176 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9177 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9178 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9179 | .init_caps = NFS_CAP_READDIRPLUS |
| 9180 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9181 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9182 | .init_client = nfs40_init_client, |
| 9183 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9184 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9185 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9186 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9187 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9188 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9189 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9190 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9191 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9192 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9193 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9194 | }; |
| 9195 | |
| 9196 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9197 | static struct nfs_seqid * |
| 9198 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9199 | { |
| 9200 | return NULL; |
| 9201 | } |
| 9202 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9203 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9204 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9205 | .init_caps = NFS_CAP_READDIRPLUS |
| 9206 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9207 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9208 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9209 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9210 | .init_client = nfs41_init_client, |
| 9211 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9212 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9213 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9214 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9215 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9216 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9217 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9218 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9219 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9220 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9221 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9222 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9223 | }; |
| 9224 | #endif |
| 9225 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9226 | #if defined(CONFIG_NFS_V4_2) |
| 9227 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9228 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9229 | .init_caps = NFS_CAP_READDIRPLUS |
| 9230 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9231 | | NFS_CAP_POSIX_LOCK |
| 9232 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9233 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9234 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9235 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9236 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9237 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9238 | | NFS_CAP_LAYOUTSTATS |
| 9239 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9240 | .init_client = nfs41_init_client, |
| 9241 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9242 | .match_stateid = nfs41_match_stateid, |
| 9243 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9244 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9245 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9246 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9247 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9248 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9249 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9250 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9251 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9252 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9253 | }; |
| 9254 | #endif |
| 9255 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9256 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9257 | [0] = &nfs_v4_0_minor_ops, |
| 9258 | #if defined(CONFIG_NFS_V4_1) |
| 9259 | [1] = &nfs_v4_1_minor_ops, |
| 9260 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9261 | #if defined(CONFIG_NFS_V4_2) |
| 9262 | [2] = &nfs_v4_2_minor_ops, |
| 9263 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9264 | }; |
| 9265 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9266 | 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] | 9267 | { |
| 9268 | ssize_t error, error2; |
| 9269 | |
| 9270 | error = generic_listxattr(dentry, list, size); |
| 9271 | if (error < 0) |
| 9272 | return error; |
| 9273 | if (list) { |
| 9274 | list += error; |
| 9275 | size -= error; |
| 9276 | } |
| 9277 | |
| 9278 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9279 | if (error2 < 0) |
| 9280 | return error2; |
| 9281 | return error + error2; |
| 9282 | } |
| 9283 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9284 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9285 | .create = nfs_create, |
| 9286 | .lookup = nfs_lookup, |
| 9287 | .atomic_open = nfs_atomic_open, |
| 9288 | .link = nfs_link, |
| 9289 | .unlink = nfs_unlink, |
| 9290 | .symlink = nfs_symlink, |
| 9291 | .mkdir = nfs_mkdir, |
| 9292 | .rmdir = nfs_rmdir, |
| 9293 | .mknod = nfs_mknod, |
| 9294 | .rename = nfs_rename, |
| 9295 | .permission = nfs_permission, |
| 9296 | .getattr = nfs_getattr, |
| 9297 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9298 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9299 | }; |
| 9300 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9301 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9302 | .permission = nfs_permission, |
| 9303 | .getattr = nfs_getattr, |
| 9304 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9305 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9306 | }; |
| 9307 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9308 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9309 | .version = 4, /* protocol version */ |
| 9310 | .dentry_ops = &nfs4_dentry_operations, |
| 9311 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9312 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9313 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9314 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9315 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9316 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9317 | .getattr = nfs4_proc_getattr, |
| 9318 | .setattr = nfs4_proc_setattr, |
| 9319 | .lookup = nfs4_proc_lookup, |
| 9320 | .access = nfs4_proc_access, |
| 9321 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9322 | .create = nfs4_proc_create, |
| 9323 | .remove = nfs4_proc_remove, |
| 9324 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9325 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9326 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9327 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9328 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9329 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9330 | .link = nfs4_proc_link, |
| 9331 | .symlink = nfs4_proc_symlink, |
| 9332 | .mkdir = nfs4_proc_mkdir, |
| 9333 | .rmdir = nfs4_proc_remove, |
| 9334 | .readdir = nfs4_proc_readdir, |
| 9335 | .mknod = nfs4_proc_mknod, |
| 9336 | .statfs = nfs4_proc_statfs, |
| 9337 | .fsinfo = nfs4_proc_fsinfo, |
| 9338 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9339 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9340 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9341 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9342 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9343 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9344 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9345 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9346 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9347 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9348 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9349 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9350 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9351 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9352 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9353 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9354 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9355 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9356 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9357 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9358 | .create_server = nfs4_create_server, |
| 9359 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9360 | }; |
| 9361 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9362 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9363 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9364 | .list = nfs4_xattr_list_nfs4_acl, |
| 9365 | .get = nfs4_xattr_get_nfs4_acl, |
| 9366 | .set = nfs4_xattr_set_nfs4_acl, |
| 9367 | }; |
| 9368 | |
| 9369 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9370 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9371 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9372 | &nfs4_xattr_nfs4_label_handler, |
| 9373 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9374 | NULL |
| 9375 | }; |
| 9376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9377 | /* |
| 9378 | * Local variables: |
| 9379 | * c-basic-offset: 8 |
| 9380 | * End: |
| 9381 | */ |