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 | 2cf10cd | 2016-12-04 19:26:40 -0500 | [diff] [blame] | 771 | case -NFS4ERR_DEADSESSION: |
| 772 | case -NFS4ERR_BADSESSION: |
| 773 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 774 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 775 | default: |
| 776 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 777 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 778 | } |
| 779 | out: |
| 780 | /* The session may be reset by one of the error handlers. */ |
| 781 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 782 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 783 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 784 | retry_nowait: |
| 785 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 786 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 787 | task->tk_status = 0; |
| 788 | ret = 0; |
| 789 | } |
| 790 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 791 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 792 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 793 | goto out; |
| 794 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 795 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 796 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 797 | |
| 798 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 799 | { |
| 800 | if (!nfs41_sequence_process(task, res)) |
| 801 | return 0; |
| 802 | if (res->sr_slot != NULL) |
| 803 | nfs41_sequence_free_slot(res); |
| 804 | return 1; |
| 805 | |
| 806 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 807 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 808 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 809 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 810 | { |
| 811 | if (res->sr_slot == NULL) |
| 812 | return 1; |
| 813 | if (res->sr_slot->table->session != NULL) |
| 814 | return nfs41_sequence_process(task, res); |
| 815 | return nfs40_sequence_done(task, res); |
| 816 | } |
| 817 | |
| 818 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 819 | { |
| 820 | if (res->sr_slot != NULL) { |
| 821 | if (res->sr_slot->table->session != NULL) |
| 822 | nfs41_sequence_free_slot(res); |
| 823 | else |
| 824 | nfs40_sequence_free_slot(res); |
| 825 | } |
| 826 | } |
| 827 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 828 | 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] | 829 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 830 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 831 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 832 | if (!res->sr_slot->table->session) |
| 833 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 834 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 835 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 836 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 837 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 838 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 839 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 840 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 841 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 843 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 844 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 845 | data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 848 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 849 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 850 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 851 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 852 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 855 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 856 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 857 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 858 | }; |
| 859 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 860 | #else /* !CONFIG_NFS_V4_1 */ |
| 861 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 862 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 863 | { |
| 864 | return nfs40_sequence_done(task, res); |
| 865 | } |
| 866 | |
| 867 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 868 | { |
| 869 | if (res->sr_slot != NULL) |
| 870 | nfs40_sequence_free_slot(res); |
| 871 | } |
| 872 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 873 | int nfs4_sequence_done(struct rpc_task *task, |
| 874 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 875 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 876 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 877 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 878 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 879 | |
| 880 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 881 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 882 | int nfs4_setup_sequence(const struct nfs_client *client, |
| 883 | struct nfs4_sequence_args *args, |
| 884 | struct nfs4_sequence_res *res, |
| 885 | struct rpc_task *task) |
| 886 | { |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 887 | struct nfs4_session *session = nfs4_get_session(client); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 888 | struct nfs4_slot_table *tbl = client->cl_slot_tbl; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 889 | struct nfs4_slot *slot; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 890 | |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 891 | /* slot already allocated? */ |
| 892 | if (res->sr_slot != NULL) |
| 893 | goto out_start; |
| 894 | |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 895 | if (session) { |
| 896 | tbl = &session->fc_slot_table; |
| 897 | task->tk_timeout = 0; |
| 898 | } |
| 899 | |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 900 | spin_lock(&tbl->slot_tbl_lock); |
Anna Schumaker | 76ee035 | 2017-01-10 16:49:31 -0500 | [diff] [blame] | 901 | /* The state manager will wait until the slot table is empty */ |
| 902 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 903 | goto out_sleep; |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 904 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 905 | slot = nfs4_alloc_slot(tbl); |
| 906 | if (IS_ERR(slot)) { |
| 907 | /* Try again in 1/4 second */ |
| 908 | if (slot == ERR_PTR(-ENOMEM)) |
| 909 | task->tk_timeout = HZ >> 2; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 910 | goto out_sleep; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 911 | } |
Anna Schumaker | 6994cdd | 2017-01-10 16:13:27 -0500 | [diff] [blame] | 912 | spin_unlock(&tbl->slot_tbl_lock); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 913 | |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 914 | slot->privileged = args->sa_privileged ? 1 : 0; |
| 915 | args->sa_slot = slot; |
| 916 | |
| 917 | res->sr_slot = slot; |
| 918 | if (session) { |
| 919 | res->sr_timestamp = jiffies; |
| 920 | res->sr_status_flags = 0; |
| 921 | res->sr_status = 1; |
Anna Schumaker | 3d35808 | 2017-01-11 10:54:04 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Anna Schumaker | ad05cc0 | 2017-01-11 13:37:06 -0500 | [diff] [blame] | 924 | trace_nfs4_setup_sequence(session, args); |
Anna Schumaker | 9dd9107 | 2017-01-10 12:01:46 -0500 | [diff] [blame] | 925 | out_start: |
| 926 | rpc_call_start(task); |
| 927 | return 0; |
Anna Schumaker | 0dcee8b | 2017-01-10 16:29:54 -0500 | [diff] [blame] | 928 | |
| 929 | out_sleep: |
| 930 | if (args->sa_privileged) |
| 931 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 932 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 933 | else |
| 934 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 935 | spin_unlock(&tbl->slot_tbl_lock); |
| 936 | return -EAGAIN; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 937 | } |
| 938 | EXPORT_SYMBOL_GPL(nfs4_setup_sequence); |
| 939 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 940 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 941 | { |
| 942 | struct nfs4_call_sync_data *data = calldata; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 943 | nfs4_setup_sequence(data->seq_server->nfs_client, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 944 | data->seq_args, data->seq_res, task); |
| 945 | } |
| 946 | |
| 947 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 948 | { |
| 949 | struct nfs4_call_sync_data *data = calldata; |
| 950 | nfs4_sequence_done(task, data->seq_res); |
| 951 | } |
| 952 | |
| 953 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 954 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 955 | .rpc_call_done = nfs40_call_sync_done, |
| 956 | }; |
| 957 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 958 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 959 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 960 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 961 | struct nfs4_sequence_args *args, |
| 962 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 963 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 964 | int ret; |
| 965 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 966 | struct nfs_client *clp = server->nfs_client; |
| 967 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 968 | .seq_server = server, |
| 969 | .seq_args = args, |
| 970 | .seq_res = res, |
| 971 | }; |
| 972 | struct rpc_task_setup task_setup = { |
| 973 | .rpc_client = clnt, |
| 974 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 975 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 976 | .callback_data = &data |
| 977 | }; |
| 978 | |
| 979 | task = rpc_run_task(&task_setup); |
| 980 | if (IS_ERR(task)) |
| 981 | ret = PTR_ERR(task); |
| 982 | else { |
| 983 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 984 | rpc_put_task(task); |
| 985 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 986 | return ret; |
| 987 | } |
| 988 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 989 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 990 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 991 | struct rpc_message *msg, |
| 992 | struct nfs4_sequence_args *args, |
| 993 | struct nfs4_sequence_res *res, |
| 994 | int cache_reply) |
| 995 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 996 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 997 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1000 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
| 1001 | unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
| 1003 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1004 | |
| 1005 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1006 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1007 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1008 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1009 | nfsi->attrtimeo_timestamp = jiffies; |
| 1010 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1012 | if (cinfo->before != dir->i_version) |
| 1013 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1014 | NFS_INO_INVALID_ACL; |
| 1015 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1016 | dir->i_version = cinfo->after; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 1017 | nfsi->read_cache_jiffies = timestamp; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1018 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1019 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | spin_unlock(&dir->i_lock); |
| 1021 | } |
| 1022 | |
| 1023 | struct nfs4_opendata { |
| 1024 | struct kref kref; |
| 1025 | struct nfs_openargs o_arg; |
| 1026 | struct nfs_openres o_res; |
| 1027 | struct nfs_open_confirmargs c_arg; |
| 1028 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1029 | struct nfs4_string owner_name; |
| 1030 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1031 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1033 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1035 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | struct nfs4_state_owner *owner; |
| 1037 | struct nfs4_state *state; |
| 1038 | struct iattr attrs; |
| 1039 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1040 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1041 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1042 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1043 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | int cancelled; |
| 1045 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1046 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1047 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1048 | int err, struct nfs4_exception *exception) |
| 1049 | { |
| 1050 | if (err != -EINVAL) |
| 1051 | return false; |
| 1052 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1053 | return false; |
| 1054 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1055 | exception->retry = 1; |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1059 | static u32 |
| 1060 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1061 | fmode_t fmode, int openflags) |
| 1062 | { |
| 1063 | u32 res = 0; |
| 1064 | |
| 1065 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1066 | case FMODE_READ: |
| 1067 | res = NFS4_SHARE_ACCESS_READ; |
| 1068 | break; |
| 1069 | case FMODE_WRITE: |
| 1070 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1071 | break; |
| 1072 | case FMODE_READ|FMODE_WRITE: |
| 1073 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1074 | } |
| 1075 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1076 | goto out; |
| 1077 | /* Want no delegation if we're using O_DIRECT */ |
| 1078 | if (openflags & O_DIRECT) |
| 1079 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1080 | out: |
| 1081 | return res; |
| 1082 | } |
| 1083 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1084 | static enum open_claim_type4 |
| 1085 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1086 | enum open_claim_type4 claim) |
| 1087 | { |
| 1088 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1089 | return claim; |
| 1090 | switch (claim) { |
| 1091 | default: |
| 1092 | return claim; |
| 1093 | case NFS4_OPEN_CLAIM_FH: |
| 1094 | return NFS4_OPEN_CLAIM_NULL; |
| 1095 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1096 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1097 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1098 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1099 | } |
| 1100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1103 | { |
| 1104 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1105 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1106 | p->o_res.seqid = p->o_arg.seqid; |
| 1107 | p->c_res.seqid = p->c_arg.seqid; |
| 1108 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1109 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1110 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1111 | 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] | 1112 | } |
| 1113 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1114 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1115 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1116 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1117 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1118 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1119 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1120 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1121 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1122 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1123 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1124 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1125 | struct nfs4_opendata *p; |
| 1126 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1127 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1128 | if (p == NULL) |
| 1129 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1130 | |
| 1131 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1132 | if (IS_ERR(p->f_label)) |
| 1133 | goto err_free_p; |
| 1134 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1135 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1136 | if (IS_ERR(p->a_label)) |
| 1137 | goto err_free_f; |
| 1138 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1139 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1140 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1141 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1142 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1143 | nfs_sb_active(dentry->d_sb); |
| 1144 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1145 | p->dir = parent; |
| 1146 | p->owner = sp; |
| 1147 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1148 | p->o_arg.open_flags = flags; |
| 1149 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1150 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1151 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1152 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1153 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1154 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1155 | * will return permission denied for all bits until close */ |
| 1156 | if (!(flags & O_EXCL)) { |
| 1157 | /* ask server to check for all possible rights as results |
| 1158 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1159 | switch (p->o_arg.claim) { |
| 1160 | default: |
| 1161 | break; |
| 1162 | case NFS4_OPEN_CLAIM_NULL: |
| 1163 | case NFS4_OPEN_CLAIM_FH: |
| 1164 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1165 | NFS4_ACCESS_MODIFY | |
| 1166 | NFS4_ACCESS_EXTEND | |
| 1167 | NFS4_ACCESS_EXECUTE; |
| 1168 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1169 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1170 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1171 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1172 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1173 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1174 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1175 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1176 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1177 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1178 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1179 | case NFS4_OPEN_CLAIM_NULL: |
| 1180 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1181 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1182 | p->o_arg.fh = NFS_FH(dir); |
| 1183 | break; |
| 1184 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1185 | case NFS4_OPEN_CLAIM_FH: |
| 1186 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1187 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1188 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1189 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1190 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1191 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1192 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | p->o_arg.u.attrs = &p->attrs; |
| 1194 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1195 | |
| 1196 | verf[0] = jiffies; |
| 1197 | verf[1] = current->pid; |
| 1198 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1199 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1201 | p->c_arg.fh = &p->o_res.fh; |
| 1202 | p->c_arg.stateid = &p->o_res.stateid; |
| 1203 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1204 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1205 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1206 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1209 | nfs4_label_free(p->a_label); |
| 1210 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1211 | nfs4_label_free(p->f_label); |
| 1212 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1213 | kfree(p); |
| 1214 | err: |
| 1215 | dput(parent); |
| 1216 | return NULL; |
| 1217 | } |
| 1218 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1219 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1221 | struct nfs4_opendata *p = container_of(kref, |
| 1222 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1223 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1224 | |
| 1225 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1226 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1227 | if (p->state != NULL) |
| 1228 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1229 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1230 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1231 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1232 | nfs4_label_free(p->f_label); |
| 1233 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1234 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1235 | dput(p->dentry); |
| 1236 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1237 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1238 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1239 | kfree(p); |
| 1240 | } |
| 1241 | |
| 1242 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1243 | { |
| 1244 | if (p != NULL) |
| 1245 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1248 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1249 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1250 | int ret; |
| 1251 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1252 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1253 | return ret; |
| 1254 | } |
| 1255 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1256 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1257 | fmode_t fmode) |
| 1258 | { |
| 1259 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1260 | case FMODE_READ|FMODE_WRITE: |
| 1261 | return state->n_rdwr != 0; |
| 1262 | case FMODE_WRITE: |
| 1263 | return state->n_wronly != 0; |
| 1264 | case FMODE_READ: |
| 1265 | return state->n_rdonly != 0; |
| 1266 | } |
| 1267 | WARN_ON_ONCE(1); |
| 1268 | return false; |
| 1269 | } |
| 1270 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1271 | 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] | 1272 | { |
| 1273 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1274 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1275 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1276 | goto out; |
| 1277 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1278 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1279 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1280 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1281 | break; |
| 1282 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1283 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1284 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1285 | break; |
| 1286 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1287 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1288 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1289 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1290 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1291 | return ret; |
| 1292 | } |
| 1293 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1294 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1295 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1296 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1297 | if (delegation == NULL) |
| 1298 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1299 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1300 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1301 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1302 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1303 | switch (claim) { |
| 1304 | case NFS4_OPEN_CLAIM_NULL: |
| 1305 | case NFS4_OPEN_CLAIM_FH: |
| 1306 | break; |
| 1307 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1308 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1309 | break; |
| 1310 | default: |
| 1311 | return 0; |
| 1312 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1313 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1314 | return 1; |
| 1315 | } |
| 1316 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1317 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1318 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1319 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1320 | case FMODE_WRITE: |
| 1321 | state->n_wronly++; |
| 1322 | break; |
| 1323 | case FMODE_READ: |
| 1324 | state->n_rdonly++; |
| 1325 | break; |
| 1326 | case FMODE_READ|FMODE_WRITE: |
| 1327 | state->n_rdwr++; |
| 1328 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1329 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1332 | #ifdef CONFIG_NFS_V4_1 |
| 1333 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1334 | { |
| 1335 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1336 | return true; |
| 1337 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1338 | return true; |
| 1339 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1340 | return true; |
| 1341 | return false; |
| 1342 | } |
| 1343 | #endif /* CONFIG_NFS_V4_1 */ |
| 1344 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1345 | 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] | 1346 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1347 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1348 | bool need_recover = false; |
| 1349 | |
| 1350 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1351 | need_recover = true; |
| 1352 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1353 | need_recover = true; |
| 1354 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1355 | need_recover = true; |
| 1356 | if (need_recover) |
| 1357 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1358 | } |
| 1359 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1360 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1361 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1362 | { |
| 1363 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1364 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1365 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1366 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1367 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1368 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1369 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1370 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1371 | return true; |
| 1372 | return false; |
| 1373 | } |
| 1374 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1375 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1376 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1377 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1378 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1379 | if (state->n_wronly) |
| 1380 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1381 | if (state->n_rdonly) |
| 1382 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1383 | if (state->n_rdwr) |
| 1384 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1385 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1386 | } |
| 1387 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1388 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1389 | nfs4_stateid *stateid, fmode_t fmode) |
| 1390 | { |
| 1391 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1392 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1393 | case FMODE_WRITE: |
| 1394 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1395 | break; |
| 1396 | case FMODE_READ: |
| 1397 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1398 | break; |
| 1399 | case 0: |
| 1400 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1401 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1402 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1403 | } |
| 1404 | if (stateid == NULL) |
| 1405 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1406 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1407 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1408 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1409 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1410 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1411 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1412 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1413 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1414 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1415 | } |
| 1416 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1417 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1418 | nfs4_stateid *arg_stateid, |
| 1419 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1420 | { |
| 1421 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1422 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1423 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1424 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1425 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1426 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1427 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1428 | } |
| 1429 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1430 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1431 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1432 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1433 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1434 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1435 | case FMODE_READ: |
| 1436 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1437 | break; |
| 1438 | case FMODE_WRITE: |
| 1439 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1440 | break; |
| 1441 | case FMODE_READ|FMODE_WRITE: |
| 1442 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1443 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1444 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1445 | return; |
| 1446 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1447 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1448 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1451 | static void __update_open_stateid(struct nfs4_state *state, |
| 1452 | const nfs4_stateid *open_stateid, |
| 1453 | const nfs4_stateid *deleg_stateid, |
| 1454 | fmode_t fmode, |
| 1455 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1457 | /* |
| 1458 | * Protect the call to nfs4_state_set_mode_locked and |
| 1459 | * serialise the stateid update |
| 1460 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1461 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1462 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1463 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1464 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1465 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1466 | } |
| 1467 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1468 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1469 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1470 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1471 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1474 | static int update_open_stateid(struct nfs4_state *state, |
| 1475 | const nfs4_stateid *open_stateid, |
| 1476 | const nfs4_stateid *delegation, |
| 1477 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1478 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1479 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1480 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1481 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1482 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1483 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1484 | int ret = 0; |
| 1485 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1486 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1487 | |
| 1488 | rcu_read_lock(); |
| 1489 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1490 | if (deleg_cur == NULL) |
| 1491 | goto no_delegation; |
| 1492 | |
| 1493 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1494 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1495 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1496 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1497 | goto no_delegation_unlock; |
| 1498 | |
| 1499 | if (delegation == NULL) |
| 1500 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1501 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1502 | goto no_delegation_unlock; |
| 1503 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1504 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1505 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1506 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1507 | ret = 1; |
| 1508 | no_delegation_unlock: |
| 1509 | spin_unlock(&deleg_cur->lock); |
| 1510 | no_delegation: |
| 1511 | rcu_read_unlock(); |
| 1512 | |
| 1513 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1514 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1515 | ret = 1; |
| 1516 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1517 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1518 | nfs4_schedule_state_manager(clp); |
| 1519 | if (freeme.type != 0) |
| 1520 | nfs4_test_and_free_stateid(server, &freeme, |
| 1521 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1522 | |
| 1523 | return ret; |
| 1524 | } |
| 1525 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1526 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1527 | const nfs4_stateid *stateid) |
| 1528 | { |
| 1529 | struct nfs4_state *state = lsp->ls_state; |
| 1530 | bool ret = false; |
| 1531 | |
| 1532 | spin_lock(&state->state_lock); |
| 1533 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1534 | goto out_noupdate; |
| 1535 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1536 | goto out_noupdate; |
| 1537 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1538 | ret = true; |
| 1539 | out_noupdate: |
| 1540 | spin_unlock(&state->state_lock); |
| 1541 | return ret; |
| 1542 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1543 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1544 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1545 | { |
| 1546 | struct nfs_delegation *delegation; |
| 1547 | |
| 1548 | rcu_read_lock(); |
| 1549 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1550 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1551 | rcu_read_unlock(); |
| 1552 | return; |
| 1553 | } |
| 1554 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1555 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1556 | } |
| 1557 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1558 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1559 | { |
| 1560 | struct nfs4_state *state = opendata->state; |
| 1561 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1562 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1563 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1564 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1565 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1566 | nfs4_stateid stateid; |
| 1567 | int ret = -EAGAIN; |
| 1568 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1569 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1570 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1571 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1572 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1573 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1574 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1575 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1576 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1577 | rcu_read_lock(); |
| 1578 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1579 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1580 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1581 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1582 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1583 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1584 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1585 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1586 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1587 | if (!opendata->is_recover) { |
| 1588 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1589 | if (ret != 0) |
| 1590 | goto out; |
| 1591 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1592 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1593 | |
| 1594 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1595 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1596 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1597 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1598 | out: |
| 1599 | return ERR_PTR(ret); |
| 1600 | out_return_state: |
| 1601 | atomic_inc(&state->count); |
| 1602 | return state; |
| 1603 | } |
| 1604 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1605 | static void |
| 1606 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1607 | { |
| 1608 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1609 | struct nfs_delegation *delegation; |
| 1610 | int delegation_flags = 0; |
| 1611 | |
| 1612 | rcu_read_lock(); |
| 1613 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1614 | if (delegation) |
| 1615 | delegation_flags = delegation->flags; |
| 1616 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1617 | switch (data->o_arg.claim) { |
| 1618 | default: |
| 1619 | break; |
| 1620 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1621 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1622 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1623 | "returning a delegation for " |
| 1624 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1625 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1626 | return; |
| 1627 | } |
| 1628 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1629 | nfs_inode_set_delegation(state->inode, |
| 1630 | data->owner->so_cred, |
| 1631 | &data->o_res); |
| 1632 | else |
| 1633 | nfs_inode_reclaim_delegation(state->inode, |
| 1634 | data->owner->so_cred, |
| 1635 | &data->o_res); |
| 1636 | } |
| 1637 | |
| 1638 | /* |
| 1639 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1640 | * and update the nfs4_state. |
| 1641 | */ |
| 1642 | static struct nfs4_state * |
| 1643 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1644 | { |
| 1645 | struct inode *inode = data->state->inode; |
| 1646 | struct nfs4_state *state = data->state; |
| 1647 | int ret; |
| 1648 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1649 | if (!data->rpc_done) { |
| 1650 | if (data->rpc_status) { |
| 1651 | ret = data->rpc_status; |
| 1652 | goto err; |
| 1653 | } |
| 1654 | /* cached opens have already been processed */ |
| 1655 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1658 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1659 | if (ret) |
| 1660 | goto err; |
| 1661 | |
| 1662 | if (data->o_res.delegation_type != 0) |
| 1663 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1664 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1665 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1666 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1667 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1668 | |
| 1669 | return state; |
| 1670 | err: |
| 1671 | return ERR_PTR(ret); |
| 1672 | |
| 1673 | } |
| 1674 | |
| 1675 | static struct nfs4_state * |
| 1676 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1677 | { |
| 1678 | struct inode *inode; |
| 1679 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1680 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1681 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1683 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1684 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1685 | goto out; |
| 1686 | } |
| 1687 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1688 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1689 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1690 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1691 | 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] | 1692 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1693 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1694 | goto err; |
| 1695 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1696 | state = nfs4_get_open_state(inode, data->owner); |
| 1697 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1698 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1699 | if (data->o_res.delegation_type != 0) |
| 1700 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1701 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1702 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1704 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1705 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1706 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1707 | err_put_inode: |
| 1708 | iput(inode); |
| 1709 | err: |
| 1710 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1711 | } |
| 1712 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1713 | static struct nfs4_state * |
| 1714 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1715 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1716 | struct nfs4_state *ret; |
| 1717 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1718 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1719 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1720 | else |
| 1721 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1722 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1723 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1724 | } |
| 1725 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1726 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1727 | { |
| 1728 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1729 | struct nfs_open_context *ctx; |
| 1730 | |
| 1731 | spin_lock(&state->inode->i_lock); |
| 1732 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1733 | if (ctx->state != state) |
| 1734 | continue; |
| 1735 | get_nfs_open_context(ctx); |
| 1736 | spin_unlock(&state->inode->i_lock); |
| 1737 | return ctx; |
| 1738 | } |
| 1739 | spin_unlock(&state->inode->i_lock); |
| 1740 | return ERR_PTR(-ENOENT); |
| 1741 | } |
| 1742 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1743 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1744 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1745 | { |
| 1746 | struct nfs4_opendata *opendata; |
| 1747 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1748 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1749 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1750 | if (opendata == NULL) |
| 1751 | return ERR_PTR(-ENOMEM); |
| 1752 | opendata->state = state; |
| 1753 | atomic_inc(&state->count); |
| 1754 | return opendata; |
| 1755 | } |
| 1756 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1757 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1758 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1759 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1760 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1761 | int ret; |
| 1762 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1763 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1764 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1765 | opendata->o_arg.open_flags = 0; |
| 1766 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1767 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1768 | NFS_SB(opendata->dentry->d_sb), |
| 1769 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1770 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1771 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1772 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1773 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1774 | if (ret != 0) |
| 1775 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1776 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1777 | if (IS_ERR(newstate)) |
| 1778 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1779 | if (newstate != opendata->state) |
| 1780 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1781 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1782 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1786 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1787 | int ret; |
| 1788 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1789 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1790 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1791 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1792 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1793 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1794 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1795 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1796 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1797 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1798 | if (ret != 0) |
| 1799 | return ret; |
| 1800 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1801 | if (ret != 0) |
| 1802 | return ret; |
| 1803 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1804 | if (ret != 0) |
| 1805 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1806 | /* |
| 1807 | * We may have performed cached opens for all three recoveries. |
| 1808 | * Check if we need to update the current stateid. |
| 1809 | */ |
| 1810 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1811 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1812 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1813 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1814 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1815 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1816 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1817 | return 0; |
| 1818 | } |
| 1819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | /* |
| 1821 | * OPEN_RECLAIM: |
| 1822 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1824 | 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] | 1825 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1826 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1827 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1828 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | int status; |
| 1830 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1831 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1832 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1833 | if (IS_ERR(opendata)) |
| 1834 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1835 | rcu_read_lock(); |
| 1836 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1837 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1838 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1839 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1840 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1841 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1842 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | return status; |
| 1844 | } |
| 1845 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1846 | 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] | 1847 | { |
| 1848 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1849 | struct nfs4_exception exception = { }; |
| 1850 | int err; |
| 1851 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1852 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1853 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1854 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1855 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1856 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1857 | break; |
| 1858 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | } while (exception.retry); |
| 1860 | return err; |
| 1861 | } |
| 1862 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1863 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1864 | { |
| 1865 | struct nfs_open_context *ctx; |
| 1866 | int ret; |
| 1867 | |
| 1868 | ctx = nfs4_state_find_open_context(state); |
| 1869 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1870 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1871 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1872 | put_nfs_open_context(ctx); |
| 1873 | return ret; |
| 1874 | } |
| 1875 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1876 | 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] | 1877 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1878 | switch (err) { |
| 1879 | default: |
| 1880 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1881 | "%d.\n", __func__, err); |
| 1882 | case 0: |
| 1883 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1884 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1885 | case -ESTALE: |
| 1886 | break; |
| 1887 | case -NFS4ERR_BADSESSION: |
| 1888 | case -NFS4ERR_BADSLOT: |
| 1889 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1890 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1891 | case -NFS4ERR_DEADSESSION: |
| 1892 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1893 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1894 | return -EAGAIN; |
| 1895 | case -NFS4ERR_STALE_CLIENTID: |
| 1896 | case -NFS4ERR_STALE_STATEID: |
| 1897 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1898 | /* Don't recall a delegation if it was lost */ |
| 1899 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1900 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1901 | case -NFS4ERR_MOVED: |
| 1902 | nfs4_schedule_migration_recovery(server); |
| 1903 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1904 | case -NFS4ERR_LEASE_MOVED: |
| 1905 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1906 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1907 | case -NFS4ERR_DELEG_REVOKED: |
| 1908 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1909 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1910 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1911 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1912 | nfs_inode_find_state_and_recover(state->inode, |
| 1913 | stateid); |
| 1914 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1915 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1916 | case -NFS4ERR_DELAY: |
| 1917 | case -NFS4ERR_GRACE: |
| 1918 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1919 | ssleep(1); |
| 1920 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1921 | case -ENOMEM: |
| 1922 | case -NFS4ERR_DENIED: |
| 1923 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1924 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | return err; |
| 1927 | } |
| 1928 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1929 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1930 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1931 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1932 | { |
| 1933 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1934 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1935 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1936 | |
| 1937 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1938 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1939 | if (IS_ERR(opendata)) |
| 1940 | return PTR_ERR(opendata); |
| 1941 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1942 | write_seqlock(&state->seqlock); |
| 1943 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1944 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1945 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1946 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1947 | case FMODE_READ|FMODE_WRITE: |
| 1948 | case FMODE_WRITE: |
| 1949 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1950 | if (err) |
| 1951 | break; |
| 1952 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1953 | if (err) |
| 1954 | break; |
| 1955 | case FMODE_READ: |
| 1956 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1957 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1958 | nfs4_opendata_put(opendata); |
| 1959 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1960 | } |
| 1961 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1962 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1963 | { |
| 1964 | struct nfs4_opendata *data = calldata; |
| 1965 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 1966 | nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1967 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1968 | } |
| 1969 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1970 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1971 | { |
| 1972 | struct nfs4_opendata *data = calldata; |
| 1973 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1974 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1975 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1976 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1977 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1978 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1979 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1980 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1981 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1982 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | static void nfs4_open_confirm_release(void *calldata) |
| 1986 | { |
| 1987 | struct nfs4_opendata *data = calldata; |
| 1988 | struct nfs4_state *state = NULL; |
| 1989 | |
| 1990 | /* If this request hasn't been cancelled, do nothing */ |
| 1991 | if (data->cancelled == 0) |
| 1992 | goto out_free; |
| 1993 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1994 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1995 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1996 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1997 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1998 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1999 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2000 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2004 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2005 | .rpc_call_done = nfs4_open_confirm_done, |
| 2006 | .rpc_release = nfs4_open_confirm_release, |
| 2007 | }; |
| 2008 | |
| 2009 | /* |
| 2010 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2011 | */ |
| 2012 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2013 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2014 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2015 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2016 | struct rpc_message msg = { |
| 2017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2018 | .rpc_argp = &data->c_arg, |
| 2019 | .rpc_resp = &data->c_res, |
| 2020 | .rpc_cred = data->owner->so_cred, |
| 2021 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | struct rpc_task_setup task_setup_data = { |
| 2023 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2024 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .callback_ops = &nfs4_open_confirm_ops, |
| 2026 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2027 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2028 | .flags = RPC_TASK_ASYNC, |
| 2029 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | int status; |
| 2031 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2032 | 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] | 2033 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2034 | data->rpc_done = 0; |
| 2035 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2036 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2037 | if (data->is_recover) |
| 2038 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2039 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2040 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2041 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2042 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2043 | if (status != 0) { |
| 2044 | data->cancelled = 1; |
| 2045 | smp_wmb(); |
| 2046 | } else |
| 2047 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2048 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | return status; |
| 2050 | } |
| 2051 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2052 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2054 | struct nfs4_opendata *data = calldata; |
| 2055 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2056 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2057 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2058 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2059 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2060 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2061 | /* |
| 2062 | * Check if we still need to send an OPEN call, or if we can use |
| 2063 | * a delegation instead. |
| 2064 | */ |
| 2065 | if (data->state != NULL) { |
| 2066 | struct nfs_delegation *delegation; |
| 2067 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2068 | 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] | 2069 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2070 | rcu_read_lock(); |
| 2071 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2072 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2073 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2074 | rcu_read_unlock(); |
| 2075 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2076 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2077 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2078 | switch (claim) { |
| 2079 | default: |
| 2080 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2081 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2082 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2083 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2084 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2085 | case NFS4_OPEN_CLAIM_FH: |
| 2086 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2087 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2088 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2089 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 2090 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2091 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2092 | &data->o_res.seq_res, |
| 2093 | task) != 0) |
| 2094 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2095 | |
| 2096 | /* Set the create mode (note dependency on the session type) */ |
| 2097 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2098 | if (data->o_arg.open_flags & O_EXCL) { |
| 2099 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2100 | if (nfs4_has_persistent_session(clp)) |
| 2101 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2102 | else if (clp->cl_mvops->minor_version > 0) |
| 2103 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2104 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2105 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2106 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2107 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2108 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2109 | out_no_action: |
| 2110 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2111 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2112 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2115 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2116 | { |
| 2117 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2119 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2120 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2121 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2122 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2123 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2124 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2125 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2126 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2127 | case S_IFREG: |
| 2128 | break; |
| 2129 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2130 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2133 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2134 | break; |
| 2135 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2136 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2137 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2138 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2139 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2140 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2141 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2142 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2143 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2144 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2145 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2146 | static void nfs4_open_release(void *calldata) |
| 2147 | { |
| 2148 | struct nfs4_opendata *data = calldata; |
| 2149 | struct nfs4_state *state = NULL; |
| 2150 | |
| 2151 | /* If this request hasn't been cancelled, do nothing */ |
| 2152 | if (data->cancelled == 0) |
| 2153 | goto out_free; |
| 2154 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2155 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2156 | goto out_free; |
| 2157 | /* In case we need an open_confirm, no cleanup! */ |
| 2158 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2159 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2161 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2162 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2163 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2164 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2168 | .rpc_call_prepare = nfs4_open_prepare, |
| 2169 | .rpc_call_done = nfs4_open_done, |
| 2170 | .rpc_release = nfs4_open_release, |
| 2171 | }; |
| 2172 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2173 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2174 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2175 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2176 | struct nfs_server *server = NFS_SERVER(dir); |
| 2177 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2178 | struct nfs_openres *o_res = &data->o_res; |
| 2179 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2180 | struct rpc_message msg = { |
| 2181 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2182 | .rpc_argp = o_arg, |
| 2183 | .rpc_resp = o_res, |
| 2184 | .rpc_cred = data->owner->so_cred, |
| 2185 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2186 | struct rpc_task_setup task_setup_data = { |
| 2187 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2188 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | .callback_ops = &nfs4_open_ops, |
| 2190 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2191 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2192 | .flags = RPC_TASK_ASYNC, |
| 2193 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2194 | int status; |
| 2195 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2196 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2197 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2198 | data->rpc_done = 0; |
| 2199 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2200 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2201 | data->is_recover = 0; |
| 2202 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2203 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2204 | data->is_recover = 1; |
| 2205 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2206 | task = rpc_run_task(&task_setup_data); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2207 | if (IS_ERR(task)) |
| 2208 | return PTR_ERR(task); |
| 2209 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2210 | if (status != 0) { |
| 2211 | data->cancelled = 1; |
| 2212 | smp_wmb(); |
| 2213 | } else |
| 2214 | status = data->rpc_status; |
| 2215 | rpc_put_task(task); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2216 | |
| 2217 | return status; |
| 2218 | } |
| 2219 | |
| 2220 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2221 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2222 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2223 | struct nfs_openres *o_res = &data->o_res; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2224 | int status; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2225 | |
| 2226 | status = nfs4_run_open_task(data, 1); |
| 2227 | if (status != 0 || !data->rpc_done) |
| 2228 | return status; |
| 2229 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2230 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2231 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2232 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2233 | status = _nfs4_proc_open_confirm(data); |
| 2234 | if (status != 0) |
| 2235 | return status; |
| 2236 | } |
| 2237 | |
| 2238 | return status; |
| 2239 | } |
| 2240 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2241 | /* |
| 2242 | * Additional permission checks in order to distinguish between an |
| 2243 | * open for read, and an open for execute. This works around the |
| 2244 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2245 | * the same. |
| 2246 | * Note that in the non-execute case, we want to turn off permission |
| 2247 | * checking if we just created a new file (POSIX open() semantics). |
| 2248 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2249 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2250 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2251 | struct nfs4_state *state, fmode_t fmode, |
| 2252 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2253 | { |
| 2254 | struct nfs_access_entry cache; |
| 2255 | u32 mask; |
| 2256 | |
| 2257 | /* access call failed or for some reason the server doesn't |
| 2258 | * support any access modes -- defer access call until later */ |
| 2259 | if (opendata->o_res.access_supported == 0) |
| 2260 | return 0; |
| 2261 | |
| 2262 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2263 | /* |
| 2264 | * Use openflags to check for exec, because fmode won't |
| 2265 | * always have FMODE_EXEC set when file open for exec. |
| 2266 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2267 | if (openflags & __FMODE_EXEC) { |
| 2268 | /* ONLY check for exec rights */ |
| 2269 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2270 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2271 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2272 | |
| 2273 | cache.cred = cred; |
| 2274 | cache.jiffies = jiffies; |
| 2275 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2276 | nfs_access_add_cache(state->inode, &cache); |
| 2277 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2278 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2279 | return 0; |
| 2280 | |
| 2281 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2282 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2283 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2284 | } |
| 2285 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2286 | /* |
| 2287 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2288 | */ |
| 2289 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2290 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2291 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2292 | struct nfs_server *server = NFS_SERVER(dir); |
| 2293 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2294 | struct nfs_openres *o_res = &data->o_res; |
| 2295 | int status; |
| 2296 | |
| 2297 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2298 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2299 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2300 | if (status != 0) { |
| 2301 | if (status == -NFS4ERR_BADNAME && |
| 2302 | !(o_arg->open_flags & O_CREAT)) |
| 2303 | return -ENOENT; |
| 2304 | return status; |
| 2305 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2306 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2307 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2308 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2309 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2310 | if (o_arg->open_flags & O_EXCL) |
| 2311 | data->file_created = 1; |
| 2312 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2313 | data->file_created = 1; |
Trond Myklebust | 2dfc617 | 2017-01-11 08:47:00 -0500 | [diff] [blame] | 2314 | if (data->file_created || dir->i_version != o_res->cinfo.after) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 2315 | update_changeattr(dir, &o_res->cinfo, |
| 2316 | o_res->f_attr->time_start); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2317 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2318 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2319 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2321 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2323 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | } |
| 2325 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2326 | 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] | 2327 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2330 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2331 | { |
| 2332 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2333 | } |
| 2334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | /* |
| 2336 | * OPEN_EXPIRED: |
| 2337 | * reclaim state on the server after a network partition. |
| 2338 | * Assumes caller holds the appropriate lock |
| 2339 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2340 | 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] | 2341 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2342 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2343 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2345 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2346 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2347 | if (IS_ERR(opendata)) |
| 2348 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2349 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2350 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2351 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2352 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2353 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2356 | 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] | 2357 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2358 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2359 | struct nfs4_exception exception = { }; |
| 2360 | int err; |
| 2361 | |
| 2362 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2363 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2364 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2365 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2366 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2367 | switch (err) { |
| 2368 | default: |
| 2369 | goto out; |
| 2370 | case -NFS4ERR_GRACE: |
| 2371 | case -NFS4ERR_DELAY: |
| 2372 | nfs4_handle_exception(server, err, &exception); |
| 2373 | err = 0; |
| 2374 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2375 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2376 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2377 | return err; |
| 2378 | } |
| 2379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2381 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2383 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2385 | ctx = nfs4_state_find_open_context(state); |
| 2386 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2387 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2388 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2389 | put_nfs_open_context(ctx); |
| 2390 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2393 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2394 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2395 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2396 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2397 | write_seqlock(&state->seqlock); |
| 2398 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2399 | write_sequnlock(&state->seqlock); |
| 2400 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2401 | } |
| 2402 | |
| 2403 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2404 | { |
| 2405 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2406 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2410 | { |
| 2411 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2412 | nfs40_clear_delegation_stateid(state); |
| 2413 | return nfs4_open_expired(sp, state); |
| 2414 | } |
| 2415 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2416 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2417 | nfs4_stateid *stateid, |
| 2418 | struct rpc_cred *cred) |
| 2419 | { |
| 2420 | return -NFS4ERR_BAD_STATEID; |
| 2421 | } |
| 2422 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2423 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2424 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2425 | nfs4_stateid *stateid, |
| 2426 | struct rpc_cred *cred) |
| 2427 | { |
| 2428 | int status; |
| 2429 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2430 | switch (stateid->type) { |
| 2431 | default: |
| 2432 | break; |
| 2433 | case NFS4_INVALID_STATEID_TYPE: |
| 2434 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2435 | return -NFS4ERR_BAD_STATEID; |
| 2436 | case NFS4_REVOKED_STATEID_TYPE: |
| 2437 | goto out_free; |
| 2438 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2439 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2440 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2441 | switch (status) { |
| 2442 | case -NFS4ERR_EXPIRED: |
| 2443 | case -NFS4ERR_ADMIN_REVOKED: |
| 2444 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2445 | break; |
| 2446 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2447 | return status; |
| 2448 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2449 | out_free: |
| 2450 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2451 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2452 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2453 | } |
| 2454 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2455 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2456 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2457 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2458 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2459 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2460 | struct rpc_cred *cred; |
| 2461 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2462 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2463 | /* Get the delegation credential for use by test/free_stateid */ |
| 2464 | rcu_read_lock(); |
| 2465 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2466 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2467 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2468 | return; |
| 2469 | } |
| 2470 | |
| 2471 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2472 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2473 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2474 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2475 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2476 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2477 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2478 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2479 | rcu_read_unlock(); |
| 2480 | return; |
| 2481 | } |
| 2482 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2483 | cred = get_rpccred(delegation->cred); |
| 2484 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2485 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2486 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2487 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2488 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2489 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2490 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2494 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2495 | * |
| 2496 | * @state: NFSv4 state for an inode |
| 2497 | * |
| 2498 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2499 | * Otherwise a negative NFS4ERR value is returned. |
| 2500 | */ |
| 2501 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2502 | { |
| 2503 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2504 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2505 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2506 | |
| 2507 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2508 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2509 | |
| 2510 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2511 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2512 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2513 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2514 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2515 | atomic_inc(&lsp->ls_count); |
| 2516 | spin_unlock(&state->state_lock); |
| 2517 | |
| 2518 | nfs4_put_lock_state(prev); |
| 2519 | prev = lsp; |
| 2520 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2521 | status = nfs41_test_and_free_expired_stateid(server, |
| 2522 | &lsp->ls_stateid, |
| 2523 | cred); |
| 2524 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2525 | if (status == -NFS4ERR_EXPIRED || |
| 2526 | status == -NFS4ERR_BAD_STATEID) { |
| 2527 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2528 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2529 | if (!recover_lost_locks) |
| 2530 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2531 | } else if (status != NFS_OK) { |
| 2532 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2533 | nfs4_put_lock_state(prev); |
| 2534 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2535 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2536 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2537 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2538 | } |
| 2539 | spin_unlock(&state->state_lock); |
| 2540 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2541 | out: |
| 2542 | return ret; |
| 2543 | } |
| 2544 | |
| 2545 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2546 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2547 | * |
| 2548 | * @state: NFSv4 state for an inode |
| 2549 | * |
| 2550 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2551 | * Otherwise a negative NFS4ERR value is returned. |
| 2552 | */ |
| 2553 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2554 | { |
| 2555 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2556 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2557 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2558 | int status; |
| 2559 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2560 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2561 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2562 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2563 | return NFS_OK; |
| 2564 | return -NFS4ERR_OPENMODE; |
| 2565 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2566 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2567 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2568 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2569 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2570 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2571 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2572 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2573 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2574 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2575 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2576 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2577 | if (status != NFS_OK) |
| 2578 | return status; |
| 2579 | if (nfs_open_stateid_recover_openmode(state)) |
| 2580 | return -NFS4ERR_OPENMODE; |
| 2581 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2585 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2586 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2587 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2588 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2589 | status = nfs41_check_expired_locks(state); |
| 2590 | if (status != NFS_OK) |
| 2591 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2592 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2593 | if (status != NFS_OK) |
| 2594 | status = nfs4_open_expired(sp, state); |
| 2595 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2596 | } |
| 2597 | #endif |
| 2598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2600 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2601 | * fields corresponding to attributes that were used to store the verifier. |
| 2602 | * Make sure we clobber those fields in the later setattr call |
| 2603 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2604 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2605 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2606 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2607 | const u32 *attrset = opendata->o_res.attrset; |
| 2608 | |
| 2609 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2610 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2611 | sattr->ia_valid |= ATTR_ATIME; |
| 2612 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2613 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2614 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2615 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2616 | |
| 2617 | /* Except MODE, it seems harmless of setting twice. */ |
Benjamin Coddington | a430607 | 2017-01-24 11:34:20 -0500 | [diff] [blame] | 2618 | if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && |
| 2619 | attrset[1] & FATTR4_WORD1_MODE) |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2620 | sattr->ia_valid &= ~ATTR_MODE; |
| 2621 | |
| 2622 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2623 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2624 | } |
| 2625 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2626 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2627 | fmode_t fmode, |
| 2628 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2629 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2630 | { |
| 2631 | struct nfs4_state_owner *sp = opendata->owner; |
| 2632 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2633 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2634 | struct nfs4_state *state; |
| 2635 | unsigned int seq; |
| 2636 | int ret; |
| 2637 | |
| 2638 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2639 | |
| 2640 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2641 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2642 | goto out; |
| 2643 | |
| 2644 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2645 | ret = PTR_ERR(state); |
| 2646 | if (IS_ERR(state)) |
| 2647 | goto out; |
| 2648 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2649 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2650 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2651 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2652 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2653 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2654 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2655 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2656 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2657 | alias = d_exact_alias(dentry, state->inode); |
| 2658 | if (!alias) |
| 2659 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2660 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2661 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2662 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2663 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2664 | } |
| 2665 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2666 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2667 | } |
| 2668 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2669 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2670 | if (ret != 0) |
| 2671 | goto out; |
| 2672 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2673 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2674 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2675 | nfs_inode_attach_open_context(ctx); |
| 2676 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2677 | nfs4_schedule_stateid_recovery(server, state); |
| 2678 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2679 | out: |
| 2680 | return ret; |
| 2681 | } |
| 2682 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2683 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2684 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2686 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2687 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2688 | int flags, |
| 2689 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2690 | struct nfs4_label *label, |
| 2691 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | { |
| 2693 | struct nfs4_state_owner *sp; |
| 2694 | struct nfs4_state *state = NULL; |
| 2695 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2696 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2697 | struct dentry *dentry = ctx->dentry; |
| 2698 | struct rpc_cred *cred = ctx->cred; |
| 2699 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2700 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2701 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2702 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2703 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
| 2705 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2707 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2708 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2710 | goto out_err; |
| 2711 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2712 | status = nfs4_recover_expired_lease(server); |
| 2713 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2714 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2715 | if (d_really_is_positive(dentry)) |
| 2716 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2717 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2718 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2719 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2720 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2721 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2722 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2723 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2725 | if (label) { |
| 2726 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2727 | if (IS_ERR(olabel)) { |
| 2728 | status = PTR_ERR(olabel); |
| 2729 | goto err_opendata_put; |
| 2730 | } |
| 2731 | } |
| 2732 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2733 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2734 | if (!opendata->f_attr.mdsthreshold) { |
| 2735 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2736 | if (!opendata->f_attr.mdsthreshold) |
| 2737 | goto err_free_label; |
| 2738 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2739 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2740 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2741 | if (d_really_is_positive(dentry)) |
| 2742 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2743 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2744 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2745 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2746 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2747 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2748 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2749 | 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] | 2750 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2751 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2752 | /* |
| 2753 | * send create attributes which was not set by open |
| 2754 | * with an extra setattr. |
| 2755 | */ |
| 2756 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2757 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2758 | status = nfs4_do_setattr(state->inode, cred, |
| 2759 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2760 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2761 | if (status == 0) { |
| 2762 | nfs_setattr_update_inode(state->inode, sattr, |
| 2763 | opendata->o_res.f_attr); |
| 2764 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2765 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2766 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2767 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2768 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2769 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2770 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2771 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2772 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2773 | opendata->f_attr.mdsthreshold = NULL; |
| 2774 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2775 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2776 | nfs4_label_free(olabel); |
| 2777 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2778 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2781 | err_free_label: |
| 2782 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2783 | err_opendata_put: |
| 2784 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2785 | err_put_state_owner: |
| 2786 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | return status; |
| 2789 | } |
| 2790 | |
| 2791 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2792 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2793 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2794 | int flags, |
| 2795 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2796 | struct nfs4_label *label, |
| 2797 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2799 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | struct nfs4_exception exception = { }; |
| 2801 | struct nfs4_state *res; |
| 2802 | int status; |
| 2803 | |
| 2804 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2805 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2806 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2807 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | if (status == 0) |
| 2809 | break; |
| 2810 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2811 | * book-keeping w.r.t. state-changing operations |
| 2812 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2813 | * It is actually a sign of a bug on the client or on the server. |
| 2814 | * |
| 2815 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2816 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | * have unhashed the old state_owner for us, and that we can |
| 2818 | * therefore safely retry using a new one. We should still warn |
| 2819 | * the user though... |
| 2820 | */ |
| 2821 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2822 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2823 | " returned a bad sequence-id error!\n", |
| 2824 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | exception.retry = 1; |
| 2826 | continue; |
| 2827 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2828 | /* |
| 2829 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2830 | * state before it received the OPEN_CONFIRM. |
| 2831 | * Recover by retrying the request as per the discussion |
| 2832 | * on Page 181 of RFC3530. |
| 2833 | */ |
| 2834 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2835 | exception.retry = 1; |
| 2836 | continue; |
| 2837 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2838 | if (status == -EAGAIN) { |
| 2839 | /* We must have found a delegation */ |
| 2840 | exception.retry = 1; |
| 2841 | continue; |
| 2842 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2843 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2844 | continue; |
| 2845 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | status, &exception)); |
| 2847 | } while (exception.retry); |
| 2848 | return res; |
| 2849 | } |
| 2850 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2851 | static int _nfs4_do_setattr(struct inode *inode, |
| 2852 | struct nfs_setattrargs *arg, |
| 2853 | struct nfs_setattrres *res, |
| 2854 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2855 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2856 | { |
| 2857 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2858 | struct rpc_message msg = { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2859 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2860 | .rpc_argp = arg, |
| 2861 | .rpc_resp = res, |
| 2862 | .rpc_cred = cred, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2863 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2864 | struct rpc_cred *delegation_cred = NULL; |
| 2865 | unsigned long timestamp = jiffies; |
| 2866 | fmode_t fmode; |
| 2867 | bool truncate; |
| 2868 | int status; |
| 2869 | |
| 2870 | nfs_fattr_init(res->fattr); |
| 2871 | |
| 2872 | /* Servers should only apply open mode checks for file size changes */ |
| 2873 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2874 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2875 | |
| 2876 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2877 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2878 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2879 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2880 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2881 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2882 | l_ctx = nfs_get_lock_context(ctx); |
| 2883 | if (IS_ERR(l_ctx)) |
| 2884 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2885 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2886 | &arg->stateid, &delegation_cred); |
| 2887 | nfs_put_lock_context(l_ctx); |
| 2888 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2889 | return -EBADF; |
| 2890 | } else |
| 2891 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2892 | if (delegation_cred) |
| 2893 | msg.rpc_cred = delegation_cred; |
| 2894 | |
| 2895 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2896 | |
| 2897 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2898 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2899 | renew_lease(server, timestamp); |
| 2900 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2901 | return status; |
| 2902 | } |
| 2903 | |
| 2904 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2905 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2906 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2907 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2909 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2910 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2911 | struct nfs_setattrargs arg = { |
| 2912 | .fh = NFS_FH(inode), |
| 2913 | .iap = sattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | .server = server, |
| 2915 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2916 | .label = ilabel, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2917 | }; |
| 2918 | struct nfs_setattrres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2920 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | .server = server, |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 2922 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2923 | struct nfs4_exception exception = { |
| 2924 | .state = state, |
| 2925 | .inode = inode, |
| 2926 | .stateid = &arg.stateid, |
| 2927 | }; |
| 2928 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2930 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2931 | if (ilabel) |
| 2932 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2935 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2936 | switch (err) { |
| 2937 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2938 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2939 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2940 | "applying open mode checks to " |
| 2941 | "a SETATTR that is not " |
| 2942 | "changing file size.\n", |
| 2943 | server->nfs_client->cl_hostname); |
| 2944 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2945 | if (state && !(state->state & FMODE_WRITE)) { |
| 2946 | err = -EBADF; |
| 2947 | if (sattr->ia_valid & ATTR_OPEN) |
| 2948 | err = -EACCES; |
| 2949 | goto out; |
| 2950 | } |
| 2951 | } |
| 2952 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2954 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | return err; |
| 2956 | } |
| 2957 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2958 | static bool |
| 2959 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2960 | { |
| 2961 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2962 | return false; |
| 2963 | |
| 2964 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2965 | } |
| 2966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | struct nfs4_closedata { |
| 2968 | struct inode *inode; |
| 2969 | struct nfs4_state *state; |
| 2970 | struct nfs_closeargs arg; |
| 2971 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2972 | struct { |
| 2973 | struct nfs4_layoutreturn_args arg; |
| 2974 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 2975 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2976 | u32 roc_barrier; |
| 2977 | bool roc; |
| 2978 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2979 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2980 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | }; |
| 2982 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2983 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2984 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2985 | struct nfs4_closedata *calldata = data; |
| 2986 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2987 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2988 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 2989 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 2990 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 2991 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2992 | nfs4_put_open_state(calldata->state); |
| 2993 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2994 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2995 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2996 | kfree(calldata); |
| 2997 | } |
| 2998 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2999 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3001 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3004 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3006 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3007 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3008 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3009 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3010 | |
| 3011 | /* Handle Layoutreturn errors */ |
| 3012 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3013 | switch (calldata->res.lr_ret) { |
| 3014 | default: |
| 3015 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3016 | break; |
| 3017 | case 0: |
| 3018 | calldata->arg.lr_args = NULL; |
| 3019 | calldata->res.lr_res = NULL; |
| 3020 | break; |
| 3021 | case -NFS4ERR_ADMIN_REVOKED: |
| 3022 | case -NFS4ERR_DELEG_REVOKED: |
| 3023 | case -NFS4ERR_EXPIRED: |
| 3024 | case -NFS4ERR_BAD_STATEID: |
| 3025 | case -NFS4ERR_OLD_STATEID: |
| 3026 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3027 | case -NFS4ERR_WRONG_CRED: |
| 3028 | calldata->arg.lr_args = NULL; |
| 3029 | calldata->res.lr_res = NULL; |
| 3030 | calldata->res.lr_ret = 0; |
| 3031 | rpc_restart_call_prepare(task); |
| 3032 | return; |
| 3033 | } |
| 3034 | } |
| 3035 | |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 3036 | /* 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] | 3037 | * the state_owner. we keep this around to process errors |
| 3038 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | switch (task->tk_status) { |
| 3040 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3041 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3042 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3043 | break; |
Trond Myklebust | f07d4a3 | 2016-12-19 10:34:14 -0500 | [diff] [blame] | 3044 | case -NFS4ERR_ACCESS: |
| 3045 | if (calldata->arg.bitmask != NULL) { |
| 3046 | calldata->arg.bitmask = NULL; |
| 3047 | calldata->res.fattr = NULL; |
| 3048 | task->tk_status = 0; |
| 3049 | rpc_restart_call_prepare(task); |
| 3050 | goto out_release; |
| 3051 | |
| 3052 | } |
| 3053 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3054 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3056 | case -NFS4ERR_EXPIRED: |
| 3057 | nfs4_free_revoked_stateid(server, |
| 3058 | &calldata->arg.stateid, |
| 3059 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3060 | case -NFS4ERR_OLD_STATEID: |
| 3061 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3062 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3063 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3064 | rpc_restart_call_prepare(task); |
| 3065 | goto out_release; |
| 3066 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3067 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3068 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3070 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3071 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3072 | goto out_release; |
| 3073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3075 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3076 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3077 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3078 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3079 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3080 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3083 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3085 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3086 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3087 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3088 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3089 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3090 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3091 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3092 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3093 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3094 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3095 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3096 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3097 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3098 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3099 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3100 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3101 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3102 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3103 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3104 | if (state->n_rdonly == 0) |
| 3105 | call_close |= is_rdonly; |
| 3106 | else if (is_rdonly) |
| 3107 | calldata->arg.fmode |= FMODE_READ; |
| 3108 | if (state->n_wronly == 0) |
| 3109 | call_close |= is_wronly; |
| 3110 | else if (is_wronly) |
| 3111 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3112 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3113 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3114 | } else if (is_rdwr) |
| 3115 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3116 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3117 | if (!nfs4_valid_open_stateid(state) || |
| 3118 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3119 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3120 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3121 | |
| 3122 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3123 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3124 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3125 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3126 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3127 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3128 | nfs_release_seqid(calldata->arg.seqid); |
| 3129 | goto out_wait; |
| 3130 | } |
| 3131 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3132 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3133 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3134 | |
Trond Myklebust | 9413a1a | 2016-12-19 11:36:41 -0500 | [diff] [blame] | 3135 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3136 | /* Close-to-open cache consistency revalidation */ |
| 3137 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3138 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3139 | else |
| 3140 | calldata->arg.bitmask = NULL; |
| 3141 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3142 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3143 | calldata->arg.share_access = |
| 3144 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3145 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3146 | |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3147 | if (calldata->res.fattr == NULL) |
| 3148 | calldata->arg.bitmask = NULL; |
| 3149 | else if (calldata->arg.bitmask == NULL) |
| 3150 | calldata->res.fattr = NULL; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3151 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 3152 | if (nfs4_setup_sequence(NFS_SERVER(inode)->nfs_client, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3153 | &calldata->arg.seq_args, |
| 3154 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3155 | task) != 0) |
| 3156 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3157 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3158 | return; |
| 3159 | out_no_action: |
| 3160 | task->tk_action = NULL; |
| 3161 | out_wait: |
| 3162 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3165 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3166 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3167 | .rpc_call_done = nfs4_close_done, |
| 3168 | .rpc_release = nfs4_free_closedata, |
| 3169 | }; |
| 3170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | /* |
| 3172 | * It is possible for data to be read/written from a mem-mapped file |
| 3173 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3174 | * This means that we can't safely call nfsv4 close on a file until |
| 3175 | * the inode is cleared. This in turn means that we are not good |
| 3176 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3177 | * share state even when we are done with one of the three share |
| 3178 | * stateid's in the inode. |
| 3179 | * |
| 3180 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3181 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3182 | 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] | 3183 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3184 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3185 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3187 | struct nfs4_state_owner *sp = state->owner; |
| 3188 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3189 | struct rpc_message msg = { |
| 3190 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3191 | .rpc_cred = state->owner->so_cred, |
| 3192 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3193 | struct rpc_task_setup task_setup_data = { |
| 3194 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3195 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3196 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3197 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3198 | .flags = RPC_TASK_ASYNC, |
| 3199 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3200 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3202 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3203 | &task_setup_data.rpc_client, &msg); |
| 3204 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3205 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3207 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3208 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3209 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3211 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3213 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3214 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3215 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3216 | goto out_free_calldata; |
Trond Myklebust | d8d8498 | 2016-12-19 12:14:44 -0500 | [diff] [blame] | 3217 | nfs_fattr_init(&calldata->fattr); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3218 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3219 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3220 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3221 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3222 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3223 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3224 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3225 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3226 | if (calldata->lr.roc) { |
| 3227 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3228 | calldata->res.lr_res = &calldata->lr.res; |
| 3229 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3230 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3231 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3232 | msg.rpc_argp = &calldata->arg; |
| 3233 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3234 | task_setup_data.callback_data = calldata; |
| 3235 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3236 | if (IS_ERR(task)) |
| 3237 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3238 | status = 0; |
| 3239 | if (wait) |
| 3240 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3241 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3242 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3243 | out_free_calldata: |
| 3244 | kfree(calldata); |
| 3245 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3246 | nfs4_put_open_state(state); |
| 3247 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3248 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3251 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3252 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3253 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3256 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3257 | |
| 3258 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3260 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3261 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3262 | |
| 3263 | nfs4_label_release_security(label); |
| 3264 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3265 | if (IS_ERR(state)) |
| 3266 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3267 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3270 | 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] | 3271 | { |
| 3272 | if (ctx->state == NULL) |
| 3273 | return; |
| 3274 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3275 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3276 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3277 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3280 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3281 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3282 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3285 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3286 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3287 | struct nfs4_server_caps_arg args = { |
| 3288 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3289 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3290 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | struct nfs4_server_caps_res res = {}; |
| 3292 | struct rpc_message msg = { |
| 3293 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3294 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | .rpc_resp = &res, |
| 3296 | }; |
| 3297 | int status; |
| 3298 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3299 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3300 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3301 | FATTR4_WORD0_LINK_SUPPORT | |
| 3302 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3303 | FATTR4_WORD0_ACLSUPPORT; |
| 3304 | if (minorversion) |
| 3305 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3306 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3307 | 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] | 3308 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3309 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3310 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3311 | case 0: |
| 3312 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3313 | res.attr_bitmask[2] = 0; |
| 3314 | break; |
| 3315 | case 1: |
| 3316 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3317 | break; |
| 3318 | case 2: |
| 3319 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3322 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3323 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3324 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3325 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3326 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3327 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3328 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3329 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | server->caps |= NFS_CAP_ACLS; |
| 3331 | if (res.has_links != 0) |
| 3332 | server->caps |= NFS_CAP_HARDLINKS; |
| 3333 | if (res.has_symlinks != 0) |
| 3334 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3335 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3336 | server->caps |= NFS_CAP_FILEID; |
| 3337 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3338 | server->caps |= NFS_CAP_MODE; |
| 3339 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3340 | server->caps |= NFS_CAP_NLINK; |
| 3341 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3342 | server->caps |= NFS_CAP_OWNER; |
| 3343 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3344 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3345 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3346 | server->caps |= NFS_CAP_ATIME; |
| 3347 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3348 | server->caps |= NFS_CAP_CTIME; |
| 3349 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3350 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3351 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3352 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3353 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3354 | #endif |
| 3355 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3356 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3357 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3358 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3359 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3360 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3361 | 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] | 3362 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3363 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3364 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3366 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | return status; |
| 3370 | } |
| 3371 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3372 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | { |
| 3374 | struct nfs4_exception exception = { }; |
| 3375 | int err; |
| 3376 | do { |
| 3377 | err = nfs4_handle_exception(server, |
| 3378 | _nfs4_server_capabilities(server, fhandle), |
| 3379 | &exception); |
| 3380 | } while (exception.retry); |
| 3381 | return err; |
| 3382 | } |
| 3383 | |
| 3384 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3385 | struct nfs_fsinfo *info) |
| 3386 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3387 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3389 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | }; |
| 3391 | struct nfs4_lookup_res res = { |
| 3392 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3393 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | .fh = fhandle, |
| 3395 | }; |
| 3396 | struct rpc_message msg = { |
| 3397 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3398 | .rpc_argp = &args, |
| 3399 | .rpc_resp = &res, |
| 3400 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3401 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3402 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3403 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3404 | /* |
| 3405 | * Process the label in the upcoming getfattr |
| 3406 | */ |
| 3407 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3408 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3409 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3410 | 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] | 3411 | } |
| 3412 | |
| 3413 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3414 | struct nfs_fsinfo *info) |
| 3415 | { |
| 3416 | struct nfs4_exception exception = { }; |
| 3417 | int err; |
| 3418 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3419 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3420 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3421 | switch (err) { |
| 3422 | case 0: |
| 3423 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3424 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3425 | default: |
| 3426 | err = nfs4_handle_exception(server, err, &exception); |
| 3427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3429 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | return err; |
| 3431 | } |
| 3432 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3433 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3434 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3435 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3436 | struct rpc_auth_create_args auth_args = { |
| 3437 | .pseudoflavor = flavor, |
| 3438 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3439 | struct rpc_auth *auth; |
| 3440 | int ret; |
| 3441 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3442 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3443 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3444 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3445 | goto out; |
| 3446 | } |
| 3447 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3448 | out: |
| 3449 | return ret; |
| 3450 | } |
| 3451 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3452 | /* |
| 3453 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3454 | * |
| 3455 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3456 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3457 | * |
| 3458 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3459 | * negative errno value. |
| 3460 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3461 | 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] | 3462 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3464 | /* Per 3530bis 15.33.5 */ |
| 3465 | static const rpc_authflavor_t flav_array[] = { |
| 3466 | RPC_AUTH_GSS_KRB5P, |
| 3467 | RPC_AUTH_GSS_KRB5I, |
| 3468 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3469 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3470 | RPC_AUTH_NULL, |
| 3471 | }; |
| 3472 | int status = -EPERM; |
| 3473 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3475 | if (server->auth_info.flavor_len > 0) { |
| 3476 | /* try each flavor specified by user */ |
| 3477 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3478 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3479 | server->auth_info.flavors[i]); |
| 3480 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3481 | continue; |
| 3482 | break; |
| 3483 | } |
| 3484 | } else { |
| 3485 | /* no flavors specified by user, try default list */ |
| 3486 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3487 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3488 | flav_array[i]); |
| 3489 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3490 | continue; |
| 3491 | break; |
| 3492 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3493 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3494 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3495 | /* |
| 3496 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3497 | * to access the mount. It could also mean that we tried to mount |
| 3498 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3499 | * existing mount programs don't handle -EACCES very well so it should |
| 3500 | * be mapped to -EPERM instead. |
| 3501 | */ |
| 3502 | if (status == -EACCES) |
| 3503 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3504 | return status; |
| 3505 | } |
| 3506 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3507 | /** |
| 3508 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3509 | * @server: initialized nfs_server handle |
| 3510 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3511 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3512 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3513 | * |
| 3514 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3515 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3516 | 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] | 3517 | struct nfs_fsinfo *info, |
| 3518 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3519 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3520 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3521 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3522 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3523 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3524 | |
| 3525 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3526 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3527 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | if (status == 0) |
| 3530 | status = nfs4_server_capabilities(server, fhandle); |
| 3531 | if (status == 0) |
| 3532 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3533 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3534 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3537 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3538 | struct nfs_fsinfo *info) |
| 3539 | { |
| 3540 | int error; |
| 3541 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3542 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3543 | |
| 3544 | error = nfs4_server_capabilities(server, mntfh); |
| 3545 | if (error < 0) { |
| 3546 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3547 | return error; |
| 3548 | } |
| 3549 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3550 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3551 | if (IS_ERR(label)) |
| 3552 | return PTR_ERR(label); |
| 3553 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3554 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3555 | if (error < 0) { |
| 3556 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3557 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3561 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3562 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3563 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3564 | err_free_label: |
| 3565 | nfs4_label_free(label); |
| 3566 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3567 | return error; |
| 3568 | } |
| 3569 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3570 | /* |
| 3571 | * Get locations and (maybe) other attributes of a referral. |
| 3572 | * Note that we'll actually follow the referral later when |
| 3573 | * we detect fsid mismatch in inode revalidation |
| 3574 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3575 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3576 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3577 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3578 | { |
| 3579 | int status = -ENOMEM; |
| 3580 | struct page *page = NULL; |
| 3581 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3582 | |
| 3583 | page = alloc_page(GFP_KERNEL); |
| 3584 | if (page == NULL) |
| 3585 | goto out; |
| 3586 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3587 | if (locations == NULL) |
| 3588 | goto out; |
| 3589 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3590 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3591 | if (status != 0) |
| 3592 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3593 | |
| 3594 | /* |
| 3595 | * If the fsid didn't change, this is a migration event, not a |
| 3596 | * referral. Cause us to drop into the exception handler, which |
| 3597 | * will kick off migration recovery. |
| 3598 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3599 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3600 | dprintk("%s: server did not return a different fsid for" |
| 3601 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3602 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3603 | goto out; |
| 3604 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3605 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3606 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3607 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3608 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3609 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3610 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3611 | out: |
| 3612 | if (page) |
| 3613 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3614 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3615 | return status; |
| 3616 | } |
| 3617 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3618 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3619 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | { |
| 3621 | struct nfs4_getattr_arg args = { |
| 3622 | .fh = fhandle, |
| 3623 | .bitmask = server->attr_bitmask, |
| 3624 | }; |
| 3625 | struct nfs4_getattr_res res = { |
| 3626 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3627 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | .server = server, |
| 3629 | }; |
| 3630 | struct rpc_message msg = { |
| 3631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3632 | .rpc_argp = &args, |
| 3633 | .rpc_resp = &res, |
| 3634 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3635 | |
| 3636 | args.bitmask = nfs4_bitmask(server, label); |
| 3637 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3638 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3639 | 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] | 3640 | } |
| 3641 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3642 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3643 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | { |
| 3645 | struct nfs4_exception exception = { }; |
| 3646 | int err; |
| 3647 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3648 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3649 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3650 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | &exception); |
| 3652 | } while (exception.retry); |
| 3653 | return err; |
| 3654 | } |
| 3655 | |
| 3656 | /* |
| 3657 | * The file is not closed if it is opened due to the a request to change |
| 3658 | * the size of the file. The open call will not be needed once the |
| 3659 | * VFS layer lookup-intents are implemented. |
| 3660 | * |
| 3661 | * Close is called when the inode is destroyed. |
| 3662 | * If we haven't opened the file for O_WRONLY, we |
| 3663 | * need to in the size_change case to obtain a stateid. |
| 3664 | * |
| 3665 | * Got race? |
| 3666 | * Because OPEN is always done by name in nfsv4, it is |
| 3667 | * possible that we opened a different file by the same |
| 3668 | * name. We can recognize this race condition, but we |
| 3669 | * can't do anything about it besides returning an error. |
| 3670 | * |
| 3671 | * This will be fixed with VFS changes (lookup-intent). |
| 3672 | */ |
| 3673 | static int |
| 3674 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3675 | struct iattr *sattr) |
| 3676 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3677 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3678 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3679 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3680 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | int status; |
| 3682 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3683 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3684 | sattr->ia_valid & ATTR_SIZE && |
| 3685 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3686 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3687 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3688 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3690 | /* Deal with open(O_TRUNC) */ |
| 3691 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3692 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3693 | |
| 3694 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3695 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3696 | return 0; |
| 3697 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3698 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3699 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3700 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3701 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3702 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3703 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3704 | } |
| 3705 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3706 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3707 | if (IS_ERR(label)) |
| 3708 | return PTR_ERR(label); |
| 3709 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3710 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3711 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3712 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3713 | nfs_setsecurity(inode, fattr, label); |
| 3714 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3715 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | return status; |
| 3717 | } |
| 3718 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3719 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3720 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3721 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3722 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3723 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3724 | int status; |
| 3725 | struct nfs4_lookup_arg args = { |
| 3726 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3727 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3728 | .name = name, |
| 3729 | }; |
| 3730 | struct nfs4_lookup_res res = { |
| 3731 | .server = server, |
| 3732 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3733 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3734 | .fh = fhandle, |
| 3735 | }; |
| 3736 | struct rpc_message msg = { |
| 3737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3738 | .rpc_argp = &args, |
| 3739 | .rpc_resp = &res, |
| 3740 | }; |
| 3741 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3742 | args.bitmask = nfs4_bitmask(server, label); |
| 3743 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3744 | nfs_fattr_init(fattr); |
| 3745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3747 | 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] | 3748 | dprintk("NFS reply lookup: %d\n", status); |
| 3749 | return status; |
| 3750 | } |
| 3751 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3752 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3753 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3754 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3755 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3756 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3757 | fattr->nlink = 2; |
| 3758 | } |
| 3759 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3760 | 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] | 3761 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3762 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3763 | { |
| 3764 | struct nfs4_exception exception = { }; |
| 3765 | struct rpc_clnt *client = *clnt; |
| 3766 | int err; |
| 3767 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3768 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3769 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3770 | switch (err) { |
| 3771 | case -NFS4ERR_BADNAME: |
| 3772 | err = -ENOENT; |
| 3773 | goto out; |
| 3774 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3775 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3776 | if (err == -NFS4ERR_MOVED) |
| 3777 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3778 | goto out; |
| 3779 | case -NFS4ERR_WRONGSEC: |
| 3780 | err = -EPERM; |
| 3781 | if (client != *clnt) |
| 3782 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3783 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3784 | if (IS_ERR(client)) |
| 3785 | return PTR_ERR(client); |
| 3786 | |
| 3787 | exception.retry = 1; |
| 3788 | break; |
| 3789 | default: |
| 3790 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3791 | } |
| 3792 | } while (exception.retry); |
| 3793 | |
| 3794 | out: |
| 3795 | if (err == 0) |
| 3796 | *clnt = client; |
| 3797 | else if (client != *clnt) |
| 3798 | rpc_shutdown_client(client); |
| 3799 | |
| 3800 | return err; |
| 3801 | } |
| 3802 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3803 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3804 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3805 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3807 | int status; |
| 3808 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3809 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3810 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3811 | if (client != NFS_CLIENT(dir)) { |
| 3812 | rpc_shutdown_client(client); |
| 3813 | nfs_fixup_secinfo_attributes(fattr); |
| 3814 | } |
| 3815 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3818 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3819 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3820 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3821 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3822 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3823 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3824 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3825 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3826 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3827 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3828 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3829 | } |
| 3830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3832 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3833 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | struct nfs4_accessargs args = { |
| 3835 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3836 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3838 | struct nfs4_accessres res = { |
| 3839 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3840 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | struct rpc_message msg = { |
| 3842 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3843 | .rpc_argp = &args, |
| 3844 | .rpc_resp = &res, |
| 3845 | .rpc_cred = entry->cred, |
| 3846 | }; |
| 3847 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3848 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | |
| 3850 | /* |
| 3851 | * Determine which access bits we want to ask for... |
| 3852 | */ |
| 3853 | if (mode & MAY_READ) |
| 3854 | args.access |= NFS4_ACCESS_READ; |
| 3855 | if (S_ISDIR(inode->i_mode)) { |
| 3856 | if (mode & MAY_WRITE) |
| 3857 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3858 | if (mode & MAY_EXEC) |
| 3859 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3860 | } else { |
| 3861 | if (mode & MAY_WRITE) |
| 3862 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3863 | if (mode & MAY_EXEC) |
| 3864 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3865 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3866 | |
| 3867 | res.fattr = nfs_alloc_fattr(); |
| 3868 | if (res.fattr == NULL) |
| 3869 | return -ENOMEM; |
| 3870 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3871 | 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] | 3872 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3873 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3874 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3876 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | return status; |
| 3878 | } |
| 3879 | |
| 3880 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3881 | { |
| 3882 | struct nfs4_exception exception = { }; |
| 3883 | int err; |
| 3884 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3885 | err = _nfs4_proc_access(inode, entry); |
| 3886 | trace_nfs4_access(inode, err); |
| 3887 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | &exception); |
| 3889 | } while (exception.retry); |
| 3890 | return err; |
| 3891 | } |
| 3892 | |
| 3893 | /* |
| 3894 | * TODO: For the time being, we don't try to get any attributes |
| 3895 | * along with any of the zero-copy operations READ, READDIR, |
| 3896 | * READLINK, WRITE. |
| 3897 | * |
| 3898 | * In the case of the first three, we want to put the GETATTR |
| 3899 | * after the read-type operation -- this is because it is hard |
| 3900 | * to predict the length of a GETATTR response in v4, and thus |
| 3901 | * align the READ data correctly. This means that the GETATTR |
| 3902 | * may end up partially falling into the page cache, and we should |
| 3903 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3904 | * To do this efficiently, we need to know the total length |
| 3905 | * of data received, which doesn't seem to be available outside |
| 3906 | * of the RPC layer. |
| 3907 | * |
| 3908 | * In the case of WRITE, we also want to put the GETATTR after |
| 3909 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3910 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | * |
| 3912 | * Both of these changes to the XDR layer would in fact be quite |
| 3913 | * minor, but I decided to leave them for a subsequent patch. |
| 3914 | */ |
| 3915 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3916 | unsigned int pgbase, unsigned int pglen) |
| 3917 | { |
| 3918 | struct nfs4_readlink args = { |
| 3919 | .fh = NFS_FH(inode), |
| 3920 | .pgbase = pgbase, |
| 3921 | .pglen = pglen, |
| 3922 | .pages = &page, |
| 3923 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3924 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | struct rpc_message msg = { |
| 3926 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3927 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3928 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | }; |
| 3930 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3931 | 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] | 3932 | } |
| 3933 | |
| 3934 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3935 | unsigned int pgbase, unsigned int pglen) |
| 3936 | { |
| 3937 | struct nfs4_exception exception = { }; |
| 3938 | int err; |
| 3939 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3940 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3941 | trace_nfs4_readlink(inode, err); |
| 3942 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | &exception); |
| 3944 | } while (exception.retry); |
| 3945 | return err; |
| 3946 | } |
| 3947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3949 | * 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] | 3950 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | static int |
| 3952 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3953 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3955 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3956 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3957 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | int status = 0; |
| 3960 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3961 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3962 | if (IS_ERR(ctx)) |
| 3963 | return PTR_ERR(ctx); |
| 3964 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3965 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3966 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3967 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 3968 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3969 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | if (IS_ERR(state)) { |
| 3971 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3972 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3975 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3976 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | return status; |
| 3978 | } |
| 3979 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3980 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3982 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3983 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3985 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3987 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3988 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3989 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3992 | .rpc_argp = &args, |
| 3993 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | }; |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 3995 | unsigned long timestamp = jiffies; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3996 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3997 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3998 | 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] | 3999 | if (status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4000 | update_changeattr(dir, &res.cinfo, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | return status; |
| 4002 | } |
| 4003 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4004 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | { |
| 4006 | struct nfs4_exception exception = { }; |
| 4007 | int err; |
| 4008 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4009 | err = _nfs4_proc_remove(dir, name); |
| 4010 | trace_nfs4_remove(dir, name, err); |
| 4011 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | &exception); |
| 4013 | } while (exception.retry); |
| 4014 | return err; |
| 4015 | } |
| 4016 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4017 | 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] | 4018 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4019 | struct nfs_server *server = NFS_SERVER(dir); |
| 4020 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4021 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4023 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4025 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4026 | |
| 4027 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4030 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4031 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4032 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4033 | &data->args.seq_args, |
| 4034 | &data->res.seq_res, |
| 4035 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4038 | 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] | 4039 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4040 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4041 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4042 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 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, |
| 4046 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4047 | return 0; |
Trond Myklebust | c40d52f | 2017-01-11 12:36:11 -0500 | [diff] [blame] | 4048 | if (task->tk_status == 0) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4049 | update_changeattr(dir, &res->cinfo, res->dir_attr->time_start); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4050 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4053 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4054 | { |
| 4055 | struct nfs_server *server = NFS_SERVER(dir); |
| 4056 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4057 | struct nfs_renameres *res = msg->rpc_resp; |
| 4058 | |
| 4059 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4060 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4061 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4062 | } |
| 4063 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4064 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4065 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4066 | nfs4_setup_sequence(NFS_SERVER(data->old_dir)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4067 | &data->args.seq_args, |
| 4068 | &data->res.seq_res, |
| 4069 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4073 | struct inode *new_dir) |
| 4074 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4075 | struct nfs_renamedata *data = task->tk_calldata; |
| 4076 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4077 | |
| 4078 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4079 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4080 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4081 | return 0; |
| 4082 | |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4083 | if (task->tk_status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4084 | update_changeattr(old_dir, &res->old_cinfo, res->old_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4085 | if (new_dir != old_dir) |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4086 | update_changeattr(new_dir, &res->new_cinfo, res->new_fattr->time_start); |
Trond Myklebust | c733c49 | 2017-01-11 12:32:26 -0500 | [diff] [blame] | 4087 | } |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4088 | return 1; |
| 4089 | } |
| 4090 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4091 | 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] | 4092 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4093 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | struct nfs4_link_arg arg = { |
| 4095 | .fh = NFS_FH(inode), |
| 4096 | .dir_fh = NFS_FH(dir), |
| 4097 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4098 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4100 | struct nfs4_link_res res = { |
| 4101 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4102 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | struct rpc_message msg = { |
| 4105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4106 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4107 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4109 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4111 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4112 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4113 | goto out; |
| 4114 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4115 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4116 | if (IS_ERR(res.label)) { |
| 4117 | status = PTR_ERR(res.label); |
| 4118 | goto out; |
| 4119 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4120 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4121 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4122 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4123 | if (!status) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4124 | update_changeattr(dir, &res.cinfo, res.fattr->time_start); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4125 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4126 | if (!status) |
| 4127 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4128 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4129 | |
| 4130 | |
| 4131 | nfs4_label_free(res.label); |
| 4132 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4133 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4134 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | return status; |
| 4136 | } |
| 4137 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4138 | 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] | 4139 | { |
| 4140 | struct nfs4_exception exception = { }; |
| 4141 | int err; |
| 4142 | do { |
| 4143 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4144 | _nfs4_proc_link(inode, dir, name), |
| 4145 | &exception); |
| 4146 | } while (exception.retry); |
| 4147 | return err; |
| 4148 | } |
| 4149 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4150 | struct nfs4_createdata { |
| 4151 | struct rpc_message msg; |
| 4152 | struct nfs4_create_arg arg; |
| 4153 | struct nfs4_create_res res; |
| 4154 | struct nfs_fh fh; |
| 4155 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4156 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4157 | }; |
| 4158 | |
| 4159 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4160 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4161 | { |
| 4162 | struct nfs4_createdata *data; |
| 4163 | |
| 4164 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4165 | if (data != NULL) { |
| 4166 | struct nfs_server *server = NFS_SERVER(dir); |
| 4167 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4168 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4169 | if (IS_ERR(data->label)) |
| 4170 | goto out_free; |
| 4171 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4172 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4173 | data->msg.rpc_argp = &data->arg; |
| 4174 | data->msg.rpc_resp = &data->res; |
| 4175 | data->arg.dir_fh = NFS_FH(dir); |
| 4176 | data->arg.server = server; |
| 4177 | data->arg.name = name; |
| 4178 | data->arg.attrs = sattr; |
| 4179 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4180 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4181 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4182 | data->res.server = server; |
| 4183 | data->res.fh = &data->fh; |
| 4184 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4185 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4186 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4187 | } |
| 4188 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4189 | out_free: |
| 4190 | kfree(data); |
| 4191 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4195 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4196 | 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] | 4197 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4198 | if (status == 0) { |
Trond Myklebust | d3129ef | 2017-01-11 22:07:28 -0500 | [diff] [blame] | 4199 | update_changeattr(dir, &data->res.dir_cinfo, |
| 4200 | data->res.fattr->time_start); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4201 | 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] | 4202 | } |
| 4203 | return status; |
| 4204 | } |
| 4205 | |
| 4206 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4207 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4208 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4209 | kfree(data); |
| 4210 | } |
| 4211 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4212 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4213 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4214 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4216 | struct nfs4_createdata *data; |
| 4217 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4219 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4220 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4221 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4222 | status = -ENOMEM; |
| 4223 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4224 | if (data == NULL) |
| 4225 | goto out; |
| 4226 | |
| 4227 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4228 | data->arg.u.symlink.pages = &page; |
| 4229 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4230 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4232 | status = nfs4_do_create(dir, dentry, data); |
| 4233 | |
| 4234 | nfs4_free_createdata(data); |
| 4235 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | return status; |
| 4237 | } |
| 4238 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4239 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4240 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | { |
| 4242 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4243 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4245 | |
| 4246 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4249 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4250 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4251 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | &exception); |
| 4253 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4254 | |
| 4255 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | return err; |
| 4257 | } |
| 4258 | |
| 4259 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4260 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4262 | struct nfs4_createdata *data; |
| 4263 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4265 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4266 | if (data == NULL) |
| 4267 | goto out; |
| 4268 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4269 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4270 | status = nfs4_do_create(dir, dentry, data); |
| 4271 | |
| 4272 | nfs4_free_createdata(data); |
| 4273 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | return status; |
| 4275 | } |
| 4276 | |
| 4277 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4278 | struct iattr *sattr) |
| 4279 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4280 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4282 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4284 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4285 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4286 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4287 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4288 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4290 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4291 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4292 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | &exception); |
| 4294 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4295 | nfs4_label_release_security(label); |
| 4296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | return err; |
| 4298 | } |
| 4299 | |
| 4300 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4301 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4303 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | struct nfs4_readdir_arg args = { |
| 4305 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4306 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | .pgbase = 0, |
| 4308 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4309 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4310 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | }; |
| 4312 | struct nfs4_readdir_res res; |
| 4313 | struct rpc_message msg = { |
| 4314 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4315 | .rpc_argp = &args, |
| 4316 | .rpc_resp = &res, |
| 4317 | .rpc_cred = cred, |
| 4318 | }; |
| 4319 | int status; |
| 4320 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4321 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4322 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4323 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4324 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4326 | 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] | 4327 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4328 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4329 | status += args.pgbase; |
| 4330 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4331 | |
| 4332 | nfs_invalidate_atime(dir); |
| 4333 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4334 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | return status; |
| 4336 | } |
| 4337 | |
| 4338 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4339 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | { |
| 4341 | struct nfs4_exception exception = { }; |
| 4342 | int err; |
| 4343 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4344 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4345 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4346 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4347 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | &exception); |
| 4349 | } while (exception.retry); |
| 4350 | return err; |
| 4351 | } |
| 4352 | |
| 4353 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4354 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4356 | struct nfs4_createdata *data; |
| 4357 | int mode = sattr->ia_mode; |
| 4358 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4360 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4361 | if (data == NULL) |
| 4362 | goto out; |
| 4363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4365 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4367 | data->arg.ftype = NF4BLK; |
| 4368 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4369 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | } |
| 4371 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4372 | data->arg.ftype = NF4CHR; |
| 4373 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4374 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4375 | } else if (!S_ISSOCK(mode)) { |
| 4376 | status = -EINVAL; |
| 4377 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4379 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4380 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4381 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4382 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4383 | nfs4_free_createdata(data); |
| 4384 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | return status; |
| 4386 | } |
| 4387 | |
| 4388 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4389 | struct iattr *sattr, dev_t rdev) |
| 4390 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4391 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4393 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4395 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4396 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4397 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4398 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4399 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4401 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4402 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4403 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | &exception); |
| 4405 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4406 | |
| 4407 | nfs4_label_release_security(label); |
| 4408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | return err; |
| 4410 | } |
| 4411 | |
| 4412 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4413 | struct nfs_fsstat *fsstat) |
| 4414 | { |
| 4415 | struct nfs4_statfs_arg args = { |
| 4416 | .fh = fhandle, |
| 4417 | .bitmask = server->attr_bitmask, |
| 4418 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4419 | struct nfs4_statfs_res res = { |
| 4420 | .fsstat = fsstat, |
| 4421 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | struct rpc_message msg = { |
| 4423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4424 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4425 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | }; |
| 4427 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4428 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4429 | 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] | 4430 | } |
| 4431 | |
| 4432 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4433 | { |
| 4434 | struct nfs4_exception exception = { }; |
| 4435 | int err; |
| 4436 | do { |
| 4437 | err = nfs4_handle_exception(server, |
| 4438 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4439 | &exception); |
| 4440 | } while (exception.retry); |
| 4441 | return err; |
| 4442 | } |
| 4443 | |
| 4444 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4445 | struct nfs_fsinfo *fsinfo) |
| 4446 | { |
| 4447 | struct nfs4_fsinfo_arg args = { |
| 4448 | .fh = fhandle, |
| 4449 | .bitmask = server->attr_bitmask, |
| 4450 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4451 | struct nfs4_fsinfo_res res = { |
| 4452 | .fsinfo = fsinfo, |
| 4453 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | struct rpc_message msg = { |
| 4455 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4456 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4457 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | }; |
| 4459 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4460 | 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] | 4461 | } |
| 4462 | |
| 4463 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4464 | { |
| 4465 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4466 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | int err; |
| 4468 | |
| 4469 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4470 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4471 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4472 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4473 | nfs4_set_lease_period(server->nfs_client, |
| 4474 | fsinfo->lease_time * HZ, |
| 4475 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4476 | break; |
| 4477 | } |
| 4478 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | } while (exception.retry); |
| 4480 | return err; |
| 4481 | } |
| 4482 | |
| 4483 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4484 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4485 | int error; |
| 4486 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4487 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4488 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4489 | if (error == 0) { |
| 4490 | /* block layout checks this! */ |
| 4491 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4492 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4493 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4494 | |
| 4495 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4499 | struct nfs_pathconf *pathconf) |
| 4500 | { |
| 4501 | struct nfs4_pathconf_arg args = { |
| 4502 | .fh = fhandle, |
| 4503 | .bitmask = server->attr_bitmask, |
| 4504 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4505 | struct nfs4_pathconf_res res = { |
| 4506 | .pathconf = pathconf, |
| 4507 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | struct rpc_message msg = { |
| 4509 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4510 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4511 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | }; |
| 4513 | |
| 4514 | /* None of the pathconf attributes are mandatory to implement */ |
| 4515 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4516 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4517 | return 0; |
| 4518 | } |
| 4519 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4520 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4521 | 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] | 4522 | } |
| 4523 | |
| 4524 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4525 | struct nfs_pathconf *pathconf) |
| 4526 | { |
| 4527 | struct nfs4_exception exception = { }; |
| 4528 | int err; |
| 4529 | |
| 4530 | do { |
| 4531 | err = nfs4_handle_exception(server, |
| 4532 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4533 | &exception); |
| 4534 | } while (exception.retry); |
| 4535 | return err; |
| 4536 | } |
| 4537 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4538 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4539 | const struct nfs_open_context *ctx, |
| 4540 | const struct nfs_lock_context *l_ctx, |
| 4541 | fmode_t fmode) |
| 4542 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4543 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4544 | } |
| 4545 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4546 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4547 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4548 | const struct nfs_open_context *ctx, |
| 4549 | const struct nfs_lock_context *l_ctx, |
| 4550 | fmode_t fmode) |
| 4551 | { |
| 4552 | nfs4_stateid current_stateid; |
| 4553 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4554 | /* If the current stateid represents a lost lock, then exit */ |
| 4555 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4556 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4557 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4558 | } |
| 4559 | |
| 4560 | static bool nfs4_error_stateid_expired(int err) |
| 4561 | { |
| 4562 | switch (err) { |
| 4563 | case -NFS4ERR_DELEG_REVOKED: |
| 4564 | case -NFS4ERR_ADMIN_REVOKED: |
| 4565 | case -NFS4ERR_BAD_STATEID: |
| 4566 | case -NFS4ERR_STALE_STATEID: |
| 4567 | case -NFS4ERR_OLD_STATEID: |
| 4568 | case -NFS4ERR_OPENMODE: |
| 4569 | case -NFS4ERR_EXPIRED: |
| 4570 | return true; |
| 4571 | } |
| 4572 | return false; |
| 4573 | } |
| 4574 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4575 | 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] | 4576 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4577 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4579 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4580 | if (task->tk_status < 0) { |
| 4581 | struct nfs4_exception exception = { |
| 4582 | .inode = hdr->inode, |
| 4583 | .state = hdr->args.context->state, |
| 4584 | .stateid = &hdr->args.stateid, |
| 4585 | }; |
| 4586 | task->tk_status = nfs4_async_handle_exception(task, |
| 4587 | server, task->tk_status, &exception); |
| 4588 | if (exception.retry) { |
| 4589 | rpc_restart_call_prepare(task); |
| 4590 | return -EAGAIN; |
| 4591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4595 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4596 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4599 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4600 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4601 | { |
| 4602 | |
| 4603 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4604 | nfs4_stateid_is_current(&args->stateid, |
| 4605 | args->context, |
| 4606 | args->lock_context, |
| 4607 | FMODE_READ)) |
| 4608 | return false; |
| 4609 | rpc_restart_call_prepare(task); |
| 4610 | return true; |
| 4611 | } |
| 4612 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4613 | 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] | 4614 | { |
| 4615 | |
| 4616 | dprintk("--> %s\n", __func__); |
| 4617 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4618 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4619 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4620 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4621 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4622 | if (task->tk_status > 0) |
| 4623 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4624 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4625 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4628 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4629 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4631 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4632 | if (!hdr->pgio_done_cb) |
| 4633 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4634 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4635 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4638 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4639 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4640 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4641 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode)->nfs_client, |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4642 | &hdr->args.seq_args, |
| 4643 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4644 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4645 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4646 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4647 | hdr->args.lock_context, |
| 4648 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4649 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4650 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4651 | return -EIO; |
| 4652 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4655 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4656 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4658 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4659 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4660 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4661 | if (task->tk_status < 0) { |
| 4662 | struct nfs4_exception exception = { |
| 4663 | .inode = hdr->inode, |
| 4664 | .state = hdr->args.context->state, |
| 4665 | .stateid = &hdr->args.stateid, |
| 4666 | }; |
| 4667 | task->tk_status = nfs4_async_handle_exception(task, |
| 4668 | NFS_SERVER(inode), task->tk_status, |
| 4669 | &exception); |
| 4670 | if (exception.retry) { |
| 4671 | rpc_restart_call_prepare(task); |
| 4672 | return -EAGAIN; |
| 4673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4675 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4676 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4677 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4678 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4679 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4682 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4683 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4684 | { |
| 4685 | |
| 4686 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4687 | nfs4_stateid_is_current(&args->stateid, |
| 4688 | args->context, |
| 4689 | args->lock_context, |
| 4690 | FMODE_WRITE)) |
| 4691 | return false; |
| 4692 | rpc_restart_call_prepare(task); |
| 4693 | return true; |
| 4694 | } |
| 4695 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4696 | 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] | 4697 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4698 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4699 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4700 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4701 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4702 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4703 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4704 | } |
| 4705 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4706 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4707 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4708 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4709 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4711 | return false; |
| 4712 | /* Otherwise, request attributes if and only if we don't hold |
| 4713 | * a delegation |
| 4714 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4715 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4716 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4717 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4718 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4719 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4721 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4722 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4723 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4724 | hdr->args.bitmask = NULL; |
| 4725 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4726 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4727 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4728 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4729 | if (!hdr->pgio_done_cb) |
| 4730 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4731 | hdr->res.server = server; |
| 4732 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4734 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4735 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4738 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4739 | { |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 4740 | nfs4_setup_sequence(NFS_SERVER(data->inode)->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4741 | &data->args.seq_args, |
| 4742 | &data->res.seq_res, |
| 4743 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | } |
| 4745 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4746 | 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] | 4747 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4749 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4750 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4751 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4752 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4753 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4754 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4756 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | } |
| 4758 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4759 | 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] | 4760 | { |
| 4761 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4762 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4763 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4764 | } |
| 4765 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4766 | 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] | 4767 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4768 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4769 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4770 | if (data->commit_done_cb == NULL) |
| 4771 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4772 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4773 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4774 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4777 | struct nfs4_renewdata { |
| 4778 | struct nfs_client *client; |
| 4779 | unsigned long timestamp; |
| 4780 | }; |
| 4781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | /* |
| 4783 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4784 | * standalone procedure for queueing an asynchronous RENEW. |
| 4785 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4786 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4787 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4788 | struct nfs4_renewdata *data = calldata; |
| 4789 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4790 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4791 | if (atomic_read(&clp->cl_count) > 1) |
| 4792 | nfs4_schedule_state_renewal(clp); |
| 4793 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4794 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4795 | } |
| 4796 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4797 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4799 | struct nfs4_renewdata *data = calldata; |
| 4800 | struct nfs_client *clp = data->client; |
| 4801 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4803 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4804 | switch (task->tk_status) { |
| 4805 | case 0: |
| 4806 | break; |
| 4807 | case -NFS4ERR_LEASE_MOVED: |
| 4808 | nfs4_schedule_lease_moved_recovery(clp); |
| 4809 | break; |
| 4810 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4811 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4812 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4813 | return; |
| 4814 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4815 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4816 | return; |
| 4817 | } |
| 4818 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4820 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | } |
| 4822 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4823 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4824 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4825 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4826 | }; |
| 4827 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4828 | 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] | 4829 | { |
| 4830 | struct rpc_message msg = { |
| 4831 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4832 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4833 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4835 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4837 | if (renew_flags == 0) |
| 4838 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4839 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4840 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4841 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4842 | if (data == NULL) |
| 4843 | return -ENOMEM; |
| 4844 | data->client = clp; |
| 4845 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4846 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4847 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | } |
| 4849 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4850 | 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] | 4851 | { |
| 4852 | struct rpc_message msg = { |
| 4853 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4854 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4855 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | }; |
| 4857 | unsigned long now = jiffies; |
| 4858 | int status; |
| 4859 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4860 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | if (status < 0) |
| 4862 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4863 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | return 0; |
| 4865 | } |
| 4866 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4867 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4868 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4869 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4872 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4873 | * 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] | 4874 | * the stack. |
| 4875 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4876 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4877 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4878 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4879 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4880 | { |
| 4881 | struct page *newpage, **spages; |
| 4882 | int rc = 0; |
| 4883 | size_t len; |
| 4884 | spages = pages; |
| 4885 | |
| 4886 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4887 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4888 | newpage = alloc_page(GFP_KERNEL); |
| 4889 | |
| 4890 | if (newpage == NULL) |
| 4891 | goto unwind; |
| 4892 | memcpy(page_address(newpage), buf, len); |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 4893 | buf += len; |
| 4894 | buflen -= len; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4895 | *pages++ = newpage; |
| 4896 | rc++; |
| 4897 | } while (buflen != 0); |
| 4898 | |
| 4899 | return rc; |
| 4900 | |
| 4901 | unwind: |
| 4902 | for(; rc > 0; rc--) |
| 4903 | __free_page(spages[rc-1]); |
| 4904 | return -ENOMEM; |
| 4905 | } |
| 4906 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4907 | struct nfs4_cached_acl { |
| 4908 | int cached; |
| 4909 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4910 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4911 | }; |
| 4912 | |
| 4913 | 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] | 4914 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4915 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4916 | |
| 4917 | spin_lock(&inode->i_lock); |
| 4918 | kfree(nfsi->nfs4_acl); |
| 4919 | nfsi->nfs4_acl = acl; |
| 4920 | spin_unlock(&inode->i_lock); |
| 4921 | } |
| 4922 | |
| 4923 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4924 | { |
| 4925 | nfs4_set_cached_acl(inode, NULL); |
| 4926 | } |
| 4927 | |
| 4928 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4929 | { |
| 4930 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4931 | struct nfs4_cached_acl *acl; |
| 4932 | int ret = -ENOENT; |
| 4933 | |
| 4934 | spin_lock(&inode->i_lock); |
| 4935 | acl = nfsi->nfs4_acl; |
| 4936 | if (acl == NULL) |
| 4937 | goto out; |
| 4938 | if (buf == NULL) /* user is just asking for length */ |
| 4939 | goto out_len; |
| 4940 | if (acl->cached == 0) |
| 4941 | goto out; |
| 4942 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4943 | if (acl->len > buflen) |
| 4944 | goto out; |
| 4945 | memcpy(buf, acl->data, acl->len); |
| 4946 | out_len: |
| 4947 | ret = acl->len; |
| 4948 | out: |
| 4949 | spin_unlock(&inode->i_lock); |
| 4950 | return ret; |
| 4951 | } |
| 4952 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4953 | 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] | 4954 | { |
| 4955 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4956 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4957 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4958 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4959 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4960 | if (acl == NULL) |
| 4961 | goto out; |
| 4962 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4963 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4964 | } else { |
| 4965 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4966 | if (acl == NULL) |
| 4967 | goto out; |
| 4968 | acl->cached = 0; |
| 4969 | } |
| 4970 | acl->len = acl_len; |
| 4971 | out: |
| 4972 | nfs4_set_cached_acl(inode, acl); |
| 4973 | } |
| 4974 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4975 | /* |
| 4976 | * The getxattr API returns the required buffer length when called with a |
| 4977 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4978 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4979 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4980 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4981 | * the cache. If not so, we throw away the page, and cache the required |
| 4982 | * length. The next getxattr call will then produce another round trip to |
| 4983 | * the server, this time with the input buf of the required size. |
| 4984 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4985 | 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] | 4986 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4987 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4988 | struct nfs_getaclargs args = { |
| 4989 | .fh = NFS_FH(inode), |
| 4990 | .acl_pages = pages, |
| 4991 | .acl_len = buflen, |
| 4992 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4993 | struct nfs_getaclres res = { |
| 4994 | .acl_len = buflen, |
| 4995 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4996 | struct rpc_message msg = { |
| 4997 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4998 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4999 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5000 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5001 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5002 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5003 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5004 | /* As long as we're doing a round trip to the server anyway, |
| 5005 | * let's be prepared for a page of acl data. */ |
| 5006 | if (npages == 0) |
| 5007 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5008 | if (npages > ARRAY_SIZE(pages)) |
| 5009 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5010 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5011 | for (i = 0; i < npages; i++) { |
| 5012 | pages[i] = alloc_page(GFP_KERNEL); |
| 5013 | if (!pages[i]) |
| 5014 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5015 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5016 | |
| 5017 | /* for decoding across pages */ |
| 5018 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5019 | if (!res.acl_scratch) |
| 5020 | goto out_free; |
| 5021 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5022 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5023 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5024 | 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] | 5025 | __func__, buf, buflen, npages, args.acl_len); |
| 5026 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5027 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5028 | if (ret) |
| 5029 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5030 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5031 | /* Handle the case where the passed-in buffer is too short */ |
| 5032 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5033 | /* Did the user only issue a request for the acl length? */ |
| 5034 | if (buf == NULL) |
| 5035 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5036 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5037 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5038 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5039 | 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] | 5040 | if (buf) { |
| 5041 | if (res.acl_len > buflen) { |
| 5042 | ret = -ERANGE; |
| 5043 | goto out_free; |
| 5044 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5045 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5046 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5047 | out_ok: |
| 5048 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5049 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5050 | for (i = 0; i < npages; i++) |
| 5051 | if (pages[i]) |
| 5052 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5053 | if (res.acl_scratch) |
| 5054 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5055 | return ret; |
| 5056 | } |
| 5057 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5058 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5059 | { |
| 5060 | struct nfs4_exception exception = { }; |
| 5061 | ssize_t ret; |
| 5062 | do { |
| 5063 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5064 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5065 | if (ret >= 0) |
| 5066 | break; |
| 5067 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5068 | } while (exception.retry); |
| 5069 | return ret; |
| 5070 | } |
| 5071 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5072 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5073 | { |
| 5074 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5075 | int ret; |
| 5076 | |
| 5077 | if (!nfs4_server_supports_acls(server)) |
| 5078 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5079 | ret = nfs_revalidate_inode(server, inode); |
| 5080 | if (ret < 0) |
| 5081 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5082 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5083 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5084 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5085 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5086 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5087 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5088 | return ret; |
| 5089 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5092 | 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] | 5093 | { |
| 5094 | struct nfs_server *server = NFS_SERVER(inode); |
| 5095 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5096 | struct nfs_setaclargs arg = { |
| 5097 | .fh = NFS_FH(inode), |
| 5098 | .acl_pages = pages, |
| 5099 | .acl_len = buflen, |
| 5100 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5101 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5102 | struct rpc_message msg = { |
| 5103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5104 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5105 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5106 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5107 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5108 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5109 | |
| 5110 | if (!nfs4_server_supports_acls(server)) |
| 5111 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5112 | if (npages > ARRAY_SIZE(pages)) |
| 5113 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5114 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5115 | if (i < 0) |
| 5116 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5117 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5118 | 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] | 5119 | |
| 5120 | /* |
| 5121 | * Free each page after tx, so the only ref left is |
| 5122 | * held by the network stack |
| 5123 | */ |
| 5124 | for (; i > 0; i--) |
| 5125 | put_page(pages[i-1]); |
| 5126 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5127 | /* |
| 5128 | * Acl update can result in inode attribute update. |
| 5129 | * so mark the attribute cache invalid. |
| 5130 | */ |
| 5131 | spin_lock(&inode->i_lock); |
| 5132 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5133 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5134 | nfs_access_zap_cache(inode); |
| 5135 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5136 | return ret; |
| 5137 | } |
| 5138 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5139 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5140 | { |
| 5141 | struct nfs4_exception exception = { }; |
| 5142 | int err; |
| 5143 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5144 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5145 | trace_nfs4_set_acl(inode, err); |
| 5146 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5147 | &exception); |
| 5148 | } while (exception.retry); |
| 5149 | return err; |
| 5150 | } |
| 5151 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5152 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5153 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5154 | size_t buflen) |
| 5155 | { |
| 5156 | struct nfs_server *server = NFS_SERVER(inode); |
| 5157 | struct nfs_fattr fattr; |
| 5158 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5159 | |
| 5160 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5161 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5162 | .fh = NFS_FH(inode), |
| 5163 | .bitmask = bitmask, |
| 5164 | }; |
| 5165 | struct nfs4_getattr_res res = { |
| 5166 | .fattr = &fattr, |
| 5167 | .label = &label, |
| 5168 | .server = server, |
| 5169 | }; |
| 5170 | struct rpc_message msg = { |
| 5171 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5172 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5173 | .rpc_resp = &res, |
| 5174 | }; |
| 5175 | int ret; |
| 5176 | |
| 5177 | nfs_fattr_init(&fattr); |
| 5178 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5179 | 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] | 5180 | if (ret) |
| 5181 | return ret; |
| 5182 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5183 | return -ENOENT; |
| 5184 | if (buflen < label.len) |
| 5185 | return -ERANGE; |
| 5186 | return 0; |
| 5187 | } |
| 5188 | |
| 5189 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5190 | size_t buflen) |
| 5191 | { |
| 5192 | struct nfs4_exception exception = { }; |
| 5193 | int err; |
| 5194 | |
| 5195 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5196 | return -EOPNOTSUPP; |
| 5197 | |
| 5198 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5199 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5200 | trace_nfs4_get_security_label(inode, err); |
| 5201 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5202 | &exception); |
| 5203 | } while (exception.retry); |
| 5204 | return err; |
| 5205 | } |
| 5206 | |
| 5207 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5208 | struct nfs4_label *ilabel, |
| 5209 | struct nfs_fattr *fattr, |
| 5210 | struct nfs4_label *olabel) |
| 5211 | { |
| 5212 | |
| 5213 | struct iattr sattr = {0}; |
| 5214 | struct nfs_server *server = NFS_SERVER(inode); |
| 5215 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5216 | struct nfs_setattrargs arg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5217 | .fh = NFS_FH(inode), |
| 5218 | .iap = &sattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5219 | .server = server, |
| 5220 | .bitmask = bitmask, |
| 5221 | .label = ilabel, |
| 5222 | }; |
| 5223 | struct nfs_setattrres res = { |
| 5224 | .fattr = fattr, |
| 5225 | .label = olabel, |
| 5226 | .server = server, |
| 5227 | }; |
| 5228 | struct rpc_message msg = { |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5229 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 5230 | .rpc_argp = &arg, |
| 5231 | .rpc_resp = &res, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5232 | }; |
| 5233 | int status; |
| 5234 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5235 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5236 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5237 | 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] | 5238 | if (status) |
| 5239 | dprintk("%s failed: %d\n", __func__, status); |
| 5240 | |
| 5241 | return status; |
| 5242 | } |
| 5243 | |
| 5244 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5245 | struct nfs4_label *ilabel, |
| 5246 | struct nfs_fattr *fattr, |
| 5247 | struct nfs4_label *olabel) |
| 5248 | { |
| 5249 | struct nfs4_exception exception = { }; |
| 5250 | int err; |
| 5251 | |
| 5252 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5253 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5254 | fattr, olabel); |
| 5255 | trace_nfs4_set_security_label(inode, err); |
| 5256 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5257 | &exception); |
| 5258 | } while (exception.retry); |
| 5259 | return err; |
| 5260 | } |
| 5261 | |
| 5262 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5263 | 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] | 5264 | { |
| 5265 | struct nfs4_label ilabel, *olabel = NULL; |
| 5266 | struct nfs_fattr fattr; |
| 5267 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5268 | int status; |
| 5269 | |
| 5270 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5271 | return -EOPNOTSUPP; |
| 5272 | |
| 5273 | nfs_fattr_init(&fattr); |
| 5274 | |
| 5275 | ilabel.pi = 0; |
| 5276 | ilabel.lfs = 0; |
| 5277 | ilabel.label = (char *)buf; |
| 5278 | ilabel.len = buflen; |
| 5279 | |
| 5280 | cred = rpc_lookup_cred(); |
| 5281 | if (IS_ERR(cred)) |
| 5282 | return PTR_ERR(cred); |
| 5283 | |
| 5284 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5285 | if (IS_ERR(olabel)) { |
| 5286 | status = -PTR_ERR(olabel); |
| 5287 | goto out; |
| 5288 | } |
| 5289 | |
| 5290 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5291 | if (status == 0) |
| 5292 | nfs_setsecurity(inode, &fattr, olabel); |
| 5293 | |
| 5294 | nfs4_label_free(olabel); |
| 5295 | out: |
| 5296 | put_rpccred(cred); |
| 5297 | return status; |
| 5298 | } |
| 5299 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5300 | |
| 5301 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5302 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5303 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5304 | { |
| 5305 | __be32 verf[2]; |
| 5306 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5307 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5308 | /* An impossible timestamp guarantees this value |
| 5309 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5310 | verf[0] = cpu_to_be32(U32_MAX); |
| 5311 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5312 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5313 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5314 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5315 | |
| 5316 | verf[0] = cpu_to_be32(ns >> 32); |
| 5317 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5318 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5319 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5320 | } |
| 5321 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5322 | static int |
| 5323 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5324 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5325 | size_t len; |
| 5326 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5327 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5328 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5329 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5330 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5331 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5332 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5333 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5334 | 1 + |
| 5335 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5336 | 1; |
| 5337 | rcu_read_unlock(); |
| 5338 | |
| 5339 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5340 | return -EINVAL; |
| 5341 | |
| 5342 | /* |
| 5343 | * Since this string is allocated at mount time, and held until the |
| 5344 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5345 | * about a memory-reclaim deadlock. |
| 5346 | */ |
| 5347 | str = kmalloc(len, GFP_KERNEL); |
| 5348 | if (!str) |
| 5349 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5350 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5351 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5352 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5353 | clp->cl_ipaddr, |
| 5354 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5355 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5356 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5357 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5358 | clp->cl_owner_id = str; |
| 5359 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5360 | } |
| 5361 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5362 | static int |
| 5363 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5364 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5365 | size_t len; |
| 5366 | char *str; |
| 5367 | |
| 5368 | len = 10 + 10 + 1 + 10 + 1 + |
| 5369 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5370 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5371 | |
| 5372 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5373 | return -EINVAL; |
| 5374 | |
| 5375 | /* |
| 5376 | * Since this string is allocated at mount time, and held until the |
| 5377 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5378 | * about a memory-reclaim deadlock. |
| 5379 | */ |
| 5380 | str = kmalloc(len, GFP_KERNEL); |
| 5381 | if (!str) |
| 5382 | return -ENOMEM; |
| 5383 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5384 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5385 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5386 | nfs4_client_id_uniquifier, |
| 5387 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5388 | clp->cl_owner_id = str; |
| 5389 | return 0; |
| 5390 | } |
| 5391 | |
| 5392 | static int |
| 5393 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5394 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5395 | size_t len; |
| 5396 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5397 | |
| 5398 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5399 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5400 | |
| 5401 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5402 | return nfs4_init_uniquifier_client_string(clp); |
| 5403 | |
| 5404 | len = 10 + 10 + 1 + 10 + 1 + |
| 5405 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5406 | |
| 5407 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5408 | return -EINVAL; |
| 5409 | |
| 5410 | /* |
| 5411 | * Since this string is allocated at mount time, and held until the |
| 5412 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5413 | * about a memory-reclaim deadlock. |
| 5414 | */ |
| 5415 | str = kmalloc(len, GFP_KERNEL); |
| 5416 | if (!str) |
| 5417 | return -ENOMEM; |
| 5418 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5419 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5420 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5421 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5422 | clp->cl_owner_id = str; |
| 5423 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5424 | } |
| 5425 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5426 | /* |
| 5427 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5428 | * services. Advertise one based on the address family of the |
| 5429 | * clientaddr. |
| 5430 | */ |
| 5431 | static unsigned int |
| 5432 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5433 | { |
| 5434 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5435 | return scnprintf(buf, len, "tcp6"); |
| 5436 | else |
| 5437 | return scnprintf(buf, len, "tcp"); |
| 5438 | } |
| 5439 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5440 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5441 | { |
| 5442 | struct nfs4_setclientid *sc = calldata; |
| 5443 | |
| 5444 | if (task->tk_status == 0) |
| 5445 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5446 | } |
| 5447 | |
| 5448 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5449 | .rpc_call_done = nfs4_setclientid_done, |
| 5450 | }; |
| 5451 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5452 | /** |
| 5453 | * nfs4_proc_setclientid - Negotiate client ID |
| 5454 | * @clp: state data structure |
| 5455 | * @program: RPC program for NFSv4 callback service |
| 5456 | * @port: IP port number for NFS4 callback service |
| 5457 | * @cred: RPC credential to use for this call |
| 5458 | * @res: where to place the result |
| 5459 | * |
| 5460 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5461 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5462 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5463 | unsigned short port, struct rpc_cred *cred, |
| 5464 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | { |
| 5466 | nfs4_verifier sc_verifier; |
| 5467 | struct nfs4_setclientid setclientid = { |
| 5468 | .sc_verifier = &sc_verifier, |
| 5469 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5470 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | }; |
| 5472 | struct rpc_message msg = { |
| 5473 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5474 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5475 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5476 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5478 | struct rpc_task *task; |
| 5479 | struct rpc_task_setup task_setup_data = { |
| 5480 | .rpc_client = clp->cl_rpcclient, |
| 5481 | .rpc_message = &msg, |
| 5482 | .callback_ops = &nfs4_setclientid_ops, |
| 5483 | .callback_data = &setclientid, |
| 5484 | .flags = RPC_TASK_TIMEOUT, |
| 5485 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5486 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5488 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5489 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5490 | |
| 5491 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5492 | status = nfs4_init_uniform_client_string(clp); |
| 5493 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5494 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5495 | |
| 5496 | if (status) |
| 5497 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5498 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5499 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5500 | setclientid.sc_netid_len = |
| 5501 | nfs4_init_callback_netid(clp, |
| 5502 | setclientid.sc_netid, |
| 5503 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5504 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5505 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5507 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5508 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5509 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5510 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5511 | task = rpc_run_task(&task_setup_data); |
| 5512 | if (IS_ERR(task)) { |
| 5513 | status = PTR_ERR(task); |
| 5514 | goto out; |
| 5515 | } |
| 5516 | status = task->tk_status; |
| 5517 | if (setclientid.sc_cred) { |
| 5518 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5519 | put_rpccred(setclientid.sc_cred); |
| 5520 | } |
| 5521 | rpc_put_task(task); |
| 5522 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5523 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5524 | dprintk("NFS reply setclientid: %d\n", status); |
| 5525 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5528 | /** |
| 5529 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5530 | * @clp: state data structure |
| 5531 | * @res: result of a previous SETCLIENTID |
| 5532 | * @cred: RPC credential to use for this call |
| 5533 | * |
| 5534 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5535 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5536 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5537 | struct nfs4_setclientid_res *arg, |
| 5538 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | struct rpc_message msg = { |
| 5541 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5542 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5543 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | int status; |
| 5546 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5547 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5548 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5549 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5550 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5551 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5552 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | return status; |
| 5554 | } |
| 5555 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5556 | struct nfs4_delegreturndata { |
| 5557 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5558 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5559 | struct nfs_fh fh; |
| 5560 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5561 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5562 | struct { |
| 5563 | struct nfs4_layoutreturn_args arg; |
| 5564 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5565 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5566 | u32 roc_barrier; |
| 5567 | bool roc; |
| 5568 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5569 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5570 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5571 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5572 | }; |
| 5573 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5574 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5575 | { |
| 5576 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5577 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5578 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5579 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5580 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5581 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5582 | |
| 5583 | /* Handle Layoutreturn errors */ |
| 5584 | if (data->args.lr_args && task->tk_status != 0) { |
| 5585 | switch(data->res.lr_ret) { |
| 5586 | default: |
| 5587 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5588 | break; |
| 5589 | case 0: |
| 5590 | data->args.lr_args = NULL; |
| 5591 | data->res.lr_res = NULL; |
| 5592 | break; |
| 5593 | case -NFS4ERR_ADMIN_REVOKED: |
| 5594 | case -NFS4ERR_DELEG_REVOKED: |
| 5595 | case -NFS4ERR_EXPIRED: |
| 5596 | case -NFS4ERR_BAD_STATEID: |
| 5597 | case -NFS4ERR_OLD_STATEID: |
| 5598 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5599 | case -NFS4ERR_WRONG_CRED: |
| 5600 | data->args.lr_args = NULL; |
| 5601 | data->res.lr_res = NULL; |
| 5602 | data->res.lr_ret = 0; |
| 5603 | rpc_restart_call_prepare(task); |
| 5604 | return; |
| 5605 | } |
| 5606 | } |
| 5607 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5608 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5609 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5610 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5611 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5612 | case -NFS4ERR_ADMIN_REVOKED: |
| 5613 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5614 | case -NFS4ERR_EXPIRED: |
| 5615 | nfs4_free_revoked_stateid(data->res.server, |
| 5616 | data->args.stateid, |
| 5617 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5618 | case -NFS4ERR_BAD_STATEID: |
| 5619 | case -NFS4ERR_OLD_STATEID: |
| 5620 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5621 | task->tk_status = 0; |
| 5622 | break; |
Trond Myklebust | 8ac2b422 | 2016-12-19 10:23:10 -0500 | [diff] [blame] | 5623 | case -NFS4ERR_ACCESS: |
| 5624 | if (data->args.bitmask) { |
| 5625 | data->args.bitmask = NULL; |
| 5626 | data->res.fattr = NULL; |
| 5627 | task->tk_status = 0; |
| 5628 | rpc_restart_call_prepare(task); |
| 5629 | return; |
| 5630 | } |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5631 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5632 | if (nfs4_async_handle_error(task, data->res.server, |
| 5633 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5634 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5635 | return; |
| 5636 | } |
| 5637 | } |
| 5638 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | static void nfs4_delegreturn_release(void *calldata) |
| 5642 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5643 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5644 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5645 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5646 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5647 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5648 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5649 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame] | 5650 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5651 | nfs_iput_and_deactive(inode); |
| 5652 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5653 | kfree(calldata); |
| 5654 | } |
| 5655 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5656 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5657 | { |
| 5658 | struct nfs4_delegreturndata *d_data; |
| 5659 | |
| 5660 | d_data = (struct nfs4_delegreturndata *)data; |
| 5661 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5662 | 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] | 5663 | return; |
| 5664 | |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5665 | nfs4_setup_sequence(d_data->res.server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5666 | &d_data->args.seq_args, |
| 5667 | &d_data->res.seq_res, |
| 5668 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5669 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5670 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5671 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5672 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5673 | .rpc_call_done = nfs4_delegreturn_done, |
| 5674 | .rpc_release = nfs4_delegreturn_release, |
| 5675 | }; |
| 5676 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5677 | 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] | 5678 | { |
| 5679 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5680 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5681 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5682 | struct rpc_message msg = { |
| 5683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5684 | .rpc_cred = cred, |
| 5685 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5686 | struct rpc_task_setup task_setup_data = { |
| 5687 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5688 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5689 | .callback_ops = &nfs4_delegreturn_ops, |
| 5690 | .flags = RPC_TASK_ASYNC, |
| 5691 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5692 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5693 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5694 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5695 | if (data == NULL) |
| 5696 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5697 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5698 | |
| 5699 | nfs4_state_protect(server->nfs_client, |
| 5700 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5701 | &task_setup_data.rpc_client, &msg); |
| 5702 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5703 | data->args.fhandle = &data->fh; |
| 5704 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5705 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5706 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5707 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5708 | data->res.fattr = &data->fattr; |
| 5709 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5710 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5711 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5712 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5713 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5714 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5715 | 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] | 5716 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5717 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5718 | if (data->lr.roc) { |
| 5719 | data->args.lr_args = &data->lr.arg; |
| 5720 | data->res.lr_res = &data->lr.res; |
| 5721 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5722 | } else if (data->lr.roc) { |
| 5723 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5724 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5725 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5726 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5727 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5728 | msg.rpc_argp = &data->args; |
| 5729 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5730 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5731 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5732 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5733 | if (!issync) |
| 5734 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5735 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5736 | if (status != 0) |
| 5737 | goto out; |
| 5738 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5739 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5740 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5741 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5744 | 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] | 5745 | { |
| 5746 | struct nfs_server *server = NFS_SERVER(inode); |
| 5747 | struct nfs4_exception exception = { }; |
| 5748 | int err; |
| 5749 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5750 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5751 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | switch (err) { |
| 5753 | case -NFS4ERR_STALE_STATEID: |
| 5754 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | case 0: |
| 5756 | return 0; |
| 5757 | } |
| 5758 | err = nfs4_handle_exception(server, err, &exception); |
| 5759 | } while (exception.retry); |
| 5760 | return err; |
| 5761 | } |
| 5762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5764 | { |
| 5765 | struct inode *inode = state->inode; |
| 5766 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5767 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5768 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5770 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5772 | struct nfs_lockt_res res = { |
| 5773 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | }; |
| 5775 | struct rpc_message msg = { |
| 5776 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
Anna Schumaker | d9b67e1 | 2017-01-11 15:04:25 -0500 | [diff] [blame] | 5777 | .rpc_argp = &arg, |
| 5778 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5779 | .rpc_cred = state->owner->so_cred, |
| 5780 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5781 | struct nfs4_lock_state *lsp; |
| 5782 | int status; |
| 5783 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5784 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5785 | status = nfs4_set_lock_state(state, request); |
| 5786 | if (status != 0) |
| 5787 | goto out; |
| 5788 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5789 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5790 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5791 | 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] | 5792 | switch (status) { |
| 5793 | case 0: |
| 5794 | request->fl_type = F_UNLCK; |
| 5795 | break; |
| 5796 | case -NFS4ERR_DENIED: |
| 5797 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5798 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5799 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5800 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5801 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | return status; |
| 5803 | } |
| 5804 | |
| 5805 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5806 | { |
| 5807 | struct nfs4_exception exception = { }; |
| 5808 | int err; |
| 5809 | |
| 5810 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5811 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5812 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5813 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5814 | &exception); |
| 5815 | } while (exception.retry); |
| 5816 | return err; |
| 5817 | } |
| 5818 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5819 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5820 | struct nfs_locku_args arg; |
| 5821 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5822 | struct nfs4_lock_state *lsp; |
| 5823 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5824 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5825 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5826 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5827 | }; |
| 5828 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5829 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5830 | struct nfs_open_context *ctx, |
| 5831 | struct nfs4_lock_state *lsp, |
| 5832 | struct nfs_seqid *seqid) |
| 5833 | { |
| 5834 | struct nfs4_unlockdata *p; |
| 5835 | struct inode *inode = lsp->ls_state->inode; |
| 5836 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5837 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5838 | if (p == NULL) |
| 5839 | return NULL; |
| 5840 | p->arg.fh = NFS_FH(inode); |
| 5841 | p->arg.fl = &p->fl; |
| 5842 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5843 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5844 | p->lsp = lsp; |
| 5845 | atomic_inc(&lsp->ls_count); |
| 5846 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5847 | p->ctx = get_nfs_open_context(ctx); |
| 5848 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5849 | p->server = NFS_SERVER(inode); |
| 5850 | return p; |
| 5851 | } |
| 5852 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5853 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5854 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5855 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5856 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5857 | nfs4_put_lock_state(calldata->lsp); |
| 5858 | put_nfs_open_context(calldata->ctx); |
| 5859 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5862 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5863 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5864 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5865 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5866 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5867 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5868 | switch (task->tk_status) { |
| 5869 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5870 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5871 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5872 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5873 | &calldata->res.stateid)) |
| 5874 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5875 | case -NFS4ERR_ADMIN_REVOKED: |
| 5876 | case -NFS4ERR_EXPIRED: |
| 5877 | nfs4_free_revoked_stateid(calldata->server, |
| 5878 | &calldata->arg.stateid, |
| 5879 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5880 | case -NFS4ERR_BAD_STATEID: |
| 5881 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5882 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5883 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5884 | &calldata->lsp->ls_stateid)) |
| 5885 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5886 | break; |
| 5887 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5888 | if (nfs4_async_handle_error(task, calldata->server, |
| 5889 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5890 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5891 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5892 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5893 | } |
| 5894 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5895 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5896 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5897 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5899 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5900 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5901 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5902 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5903 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5904 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5905 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5906 | calldata->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 5907 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5908 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5909 | &calldata->res.seq_res, |
| 5910 | task) != 0) |
| 5911 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5912 | return; |
| 5913 | out_no_action: |
| 5914 | task->tk_action = NULL; |
| 5915 | out_wait: |
| 5916 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | } |
| 5918 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5919 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5920 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5921 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5922 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5923 | }; |
| 5924 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5925 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5926 | struct nfs_open_context *ctx, |
| 5927 | struct nfs4_lock_state *lsp, |
| 5928 | struct nfs_seqid *seqid) |
| 5929 | { |
| 5930 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5931 | struct rpc_message msg = { |
| 5932 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5933 | .rpc_cred = ctx->cred, |
| 5934 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5935 | struct rpc_task_setup task_setup_data = { |
| 5936 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5937 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5938 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5939 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5940 | .flags = RPC_TASK_ASYNC, |
| 5941 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5942 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5943 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5944 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5945 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5946 | /* Ensure this is an unlock - when canceling a lock, the |
| 5947 | * canceled lock is passed in, and it won't be an unlock. |
| 5948 | */ |
| 5949 | fl->fl_type = F_UNLCK; |
| 5950 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5951 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5952 | if (data == NULL) { |
| 5953 | nfs_free_seqid(seqid); |
| 5954 | return ERR_PTR(-ENOMEM); |
| 5955 | } |
| 5956 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5957 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5958 | msg.rpc_argp = &data->arg; |
| 5959 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5960 | task_setup_data.callback_data = data; |
| 5961 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5962 | } |
| 5963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5965 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5966 | struct inode *inode = state->inode; |
| 5967 | struct nfs4_state_owner *sp = state->owner; |
| 5968 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5969 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5970 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5971 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5972 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5973 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5974 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5975 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5976 | status = nfs4_set_lock_state(state, request); |
| 5977 | /* Unlock _before_ we do the RPC call */ |
| 5978 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5979 | /* Exclude nfs_delegation_claim_locks() */ |
| 5980 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5981 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5982 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5983 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5984 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5985 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5986 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5987 | } |
| 5988 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5989 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5990 | if (status != 0) |
| 5991 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5992 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5993 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5994 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5995 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5996 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5997 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5998 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5999 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6000 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6001 | 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] | 6002 | status = PTR_ERR(task); |
| 6003 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6004 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6005 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6006 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6007 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6008 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6009 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6010 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6013 | struct nfs4_lockdata { |
| 6014 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6015 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6016 | struct nfs4_lock_state *lsp; |
| 6017 | struct nfs_open_context *ctx; |
| 6018 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6019 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6020 | int rpc_status; |
| 6021 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6022 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6023 | }; |
| 6024 | |
| 6025 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6026 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6027 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6028 | { |
| 6029 | struct nfs4_lockdata *p; |
| 6030 | struct inode *inode = lsp->ls_state->inode; |
| 6031 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6032 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6033 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6034 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6035 | if (p == NULL) |
| 6036 | return NULL; |
| 6037 | |
| 6038 | p->arg.fh = NFS_FH(inode); |
| 6039 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6040 | 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] | 6041 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6042 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6043 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6044 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6045 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6046 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6047 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6048 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6049 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6050 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6051 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6052 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6053 | atomic_inc(&lsp->ls_count); |
| 6054 | p->ctx = get_nfs_open_context(ctx); |
| 6055 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6056 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6057 | out_free_seqid: |
| 6058 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6059 | out_free: |
| 6060 | kfree(p); |
| 6061 | return NULL; |
| 6062 | } |
| 6063 | |
| 6064 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6065 | { |
| 6066 | struct nfs4_lockdata *data = calldata; |
| 6067 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6069 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6070 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6071 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6072 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6073 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6074 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6075 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6076 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6077 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6078 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6079 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6080 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6081 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6082 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6083 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6084 | &data->lsp->ls_stateid); |
| 6085 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6086 | if (!nfs4_valid_open_stateid(state)) { |
| 6087 | data->rpc_status = -EBADF; |
| 6088 | task->tk_action = NULL; |
| 6089 | goto out_release_open_seqid; |
| 6090 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6091 | data->timestamp = jiffies; |
Anna Schumaker | 42e1cca | 2017-01-09 15:48:22 -0500 | [diff] [blame] | 6092 | if (nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6093 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6094 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6095 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6096 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6097 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6098 | nfs_release_seqid(data->arg.open_seqid); |
| 6099 | out_release_lock_seqid: |
| 6100 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6101 | out_wait: |
| 6102 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6103 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6104 | } |
| 6105 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6106 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6107 | { |
| 6108 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6109 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6110 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6111 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6112 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6113 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6114 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6115 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6116 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6117 | switch (task->tk_status) { |
| 6118 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6119 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6120 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6121 | if (data->arg.new_lock) { |
| 6122 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6123 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6124 | rpc_restart_call_prepare(task); |
| 6125 | break; |
| 6126 | } |
| 6127 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6128 | if (data->arg.new_lock_owner != 0) { |
| 6129 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6130 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6131 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6132 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6133 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6134 | break; |
| 6135 | case -NFS4ERR_BAD_STATEID: |
| 6136 | case -NFS4ERR_OLD_STATEID: |
| 6137 | case -NFS4ERR_STALE_STATEID: |
| 6138 | case -NFS4ERR_EXPIRED: |
| 6139 | if (data->arg.new_lock_owner != 0) { |
| 6140 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6141 | &lsp->ls_state->open_stateid)) |
| 6142 | rpc_restart_call_prepare(task); |
| 6143 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6144 | &lsp->ls_stateid)) |
| 6145 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6146 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6147 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | static void nfs4_lock_release(void *calldata) |
| 6151 | { |
| 6152 | struct nfs4_lockdata *data = calldata; |
| 6153 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6154 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6155 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6156 | if (data->cancelled != 0) { |
| 6157 | struct rpc_task *task; |
| 6158 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6159 | data->arg.lock_seqid); |
| 6160 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6161 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6162 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6163 | } else |
| 6164 | nfs_free_seqid(data->arg.lock_seqid); |
| 6165 | nfs4_put_lock_state(data->lsp); |
| 6166 | put_nfs_open_context(data->ctx); |
| 6167 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6168 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6172 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6173 | .rpc_call_done = nfs4_lock_done, |
| 6174 | .rpc_release = nfs4_lock_release, |
| 6175 | }; |
| 6176 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6177 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6178 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6179 | switch (error) { |
| 6180 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6181 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6182 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6183 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6184 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6185 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6186 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6187 | break; |
| 6188 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6189 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6190 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6191 | }; |
| 6192 | } |
| 6193 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6194 | 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] | 6195 | { |
| 6196 | struct nfs4_lockdata *data; |
| 6197 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6198 | struct rpc_message msg = { |
| 6199 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6200 | .rpc_cred = state->owner->so_cred, |
| 6201 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6202 | struct rpc_task_setup task_setup_data = { |
| 6203 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6204 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6205 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6206 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6207 | .flags = RPC_TASK_ASYNC, |
| 6208 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6209 | int ret; |
| 6210 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6211 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6212 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6213 | fl->fl_u.nfs4_fl.owner, |
| 6214 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6215 | if (data == NULL) |
| 6216 | return -ENOMEM; |
| 6217 | if (IS_SETLKW(cmd)) |
| 6218 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6219 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6220 | msg.rpc_argp = &data->arg; |
| 6221 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6222 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6223 | if (recovery_type > NFS_LOCK_NEW) { |
| 6224 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6225 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6226 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6227 | } else |
| 6228 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6229 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6230 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6231 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6232 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6233 | if (ret == 0) { |
| 6234 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6235 | if (ret) |
| 6236 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6237 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6238 | } else |
| 6239 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6240 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6241 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6242 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6243 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6247 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6248 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6249 | struct nfs4_exception exception = { |
| 6250 | .inode = state->inode, |
| 6251 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6252 | int err; |
| 6253 | |
| 6254 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6255 | /* Cache the lock if possible... */ |
| 6256 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6257 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6258 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6259 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6260 | break; |
| 6261 | nfs4_handle_exception(server, err, &exception); |
| 6262 | } while (exception.retry); |
| 6263 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | } |
| 6265 | |
| 6266 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6267 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6268 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6269 | struct nfs4_exception exception = { |
| 6270 | .inode = state->inode, |
| 6271 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6272 | int err; |
| 6273 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6274 | err = nfs4_set_lock_state(state, request); |
| 6275 | if (err != 0) |
| 6276 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6277 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6278 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6279 | return 0; |
| 6280 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6281 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6282 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6283 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6284 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6285 | switch (err) { |
| 6286 | default: |
| 6287 | goto out; |
| 6288 | case -NFS4ERR_GRACE: |
| 6289 | case -NFS4ERR_DELAY: |
| 6290 | nfs4_handle_exception(server, err, &exception); |
| 6291 | err = 0; |
| 6292 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6293 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6294 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6295 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | } |
| 6297 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6298 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6299 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6300 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6301 | struct nfs4_lock_state *lsp; |
| 6302 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6303 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6304 | status = nfs4_set_lock_state(state, request); |
| 6305 | if (status != 0) |
| 6306 | return status; |
| 6307 | lsp = request->fl_u.nfs4_fl.owner; |
| 6308 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6309 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6310 | return 0; |
| 6311 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6312 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6313 | } |
| 6314 | #endif |
| 6315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6316 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6317 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6318 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6319 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6320 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6321 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6323 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6324 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6325 | if (status < 0) |
| 6326 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6327 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6328 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6329 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6330 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6331 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6332 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6333 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6334 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6335 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6336 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6337 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6338 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6339 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6340 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6341 | out: |
| 6342 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6343 | return status; |
| 6344 | } |
| 6345 | |
| 6346 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6347 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6348 | struct nfs4_exception exception = { |
| 6349 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6350 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6351 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6352 | int err; |
| 6353 | |
| 6354 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6355 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6356 | if (err == -NFS4ERR_DENIED) |
| 6357 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6359 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | } while (exception.retry); |
| 6361 | return err; |
| 6362 | } |
| 6363 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6364 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6365 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6366 | |
| 6367 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6368 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6369 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6370 | { |
| 6371 | int status = -ERESTARTSYS; |
| 6372 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6373 | |
| 6374 | while(!signalled()) { |
| 6375 | status = nfs4_proc_setlk(state, cmd, request); |
| 6376 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6377 | break; |
| 6378 | freezable_schedule_timeout_interruptible(timeout); |
| 6379 | timeout *= 2; |
| 6380 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6381 | status = -ERESTARTSYS; |
| 6382 | } |
| 6383 | return status; |
| 6384 | } |
| 6385 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6386 | #ifdef CONFIG_NFS_V4_1 |
| 6387 | struct nfs4_lock_waiter { |
| 6388 | struct task_struct *task; |
| 6389 | struct inode *inode; |
| 6390 | struct nfs_lowner *owner; |
| 6391 | bool notified; |
| 6392 | }; |
| 6393 | |
| 6394 | static int |
| 6395 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6396 | { |
| 6397 | int ret; |
| 6398 | struct cb_notify_lock_args *cbnl = key; |
| 6399 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6400 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6401 | *wowner = waiter->owner; |
| 6402 | |
| 6403 | /* Only wake if the callback was for the same owner */ |
| 6404 | if (lowner->clientid != wowner->clientid || |
| 6405 | lowner->id != wowner->id || |
| 6406 | lowner->s_dev != wowner->s_dev) |
| 6407 | return 0; |
| 6408 | |
| 6409 | /* Make sure it's for the right inode */ |
| 6410 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6411 | return 0; |
| 6412 | |
| 6413 | waiter->notified = true; |
| 6414 | |
| 6415 | /* override "private" so we can use default_wake_function */ |
| 6416 | wait->private = waiter->task; |
| 6417 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6418 | wait->private = waiter; |
| 6419 | return ret; |
| 6420 | } |
| 6421 | |
| 6422 | static int |
| 6423 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6424 | { |
| 6425 | int status = -ERESTARTSYS; |
| 6426 | unsigned long flags; |
| 6427 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6428 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6429 | struct nfs_client *clp = server->nfs_client; |
| 6430 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6431 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6432 | .id = lsp->ls_seqid.owner_id, |
| 6433 | .s_dev = server->s_dev }; |
| 6434 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6435 | .inode = state->inode, |
| 6436 | .owner = &owner, |
| 6437 | .notified = false }; |
| 6438 | wait_queue_t wait; |
| 6439 | |
| 6440 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6441 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6442 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6443 | |
| 6444 | init_wait(&wait); |
| 6445 | wait.private = &waiter; |
| 6446 | wait.func = nfs4_wake_lock_waiter; |
| 6447 | add_wait_queue(q, &wait); |
| 6448 | |
| 6449 | while(!signalled()) { |
| 6450 | status = nfs4_proc_setlk(state, cmd, request); |
| 6451 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6452 | break; |
| 6453 | |
| 6454 | status = -ERESTARTSYS; |
| 6455 | spin_lock_irqsave(&q->lock, flags); |
| 6456 | if (waiter.notified) { |
| 6457 | spin_unlock_irqrestore(&q->lock, flags); |
| 6458 | continue; |
| 6459 | } |
| 6460 | set_current_state(TASK_INTERRUPTIBLE); |
| 6461 | spin_unlock_irqrestore(&q->lock, flags); |
| 6462 | |
| 6463 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6464 | } |
| 6465 | |
| 6466 | finish_wait(q, &wait); |
| 6467 | return status; |
| 6468 | } |
| 6469 | #else /* !CONFIG_NFS_V4_1 */ |
| 6470 | static inline int |
| 6471 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6472 | { |
| 6473 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6474 | } |
| 6475 | #endif |
| 6476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6477 | static int |
| 6478 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6479 | { |
| 6480 | struct nfs_open_context *ctx; |
| 6481 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6482 | int status; |
| 6483 | |
| 6484 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6485 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6486 | state = ctx->state; |
| 6487 | |
| 6488 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6489 | return -EINVAL; |
| 6490 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6491 | if (IS_GETLK(cmd)) { |
| 6492 | if (state != NULL) |
| 6493 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6494 | return 0; |
| 6495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6496 | |
| 6497 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6498 | return -EINVAL; |
| 6499 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6500 | if (request->fl_type == F_UNLCK) { |
| 6501 | if (state != NULL) |
| 6502 | return nfs4_proc_unlck(state, cmd, request); |
| 6503 | return 0; |
| 6504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6505 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6506 | if (state == NULL) |
| 6507 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6508 | |
| 6509 | if ((request->fl_flags & FL_POSIX) && |
| 6510 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6511 | return -ENOLCK; |
| 6512 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6513 | /* |
| 6514 | * Don't rely on the VFS having checked the file open mode, |
| 6515 | * since it won't do this for flock() locks. |
| 6516 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6517 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6518 | case F_RDLCK: |
| 6519 | if (!(filp->f_mode & FMODE_READ)) |
| 6520 | return -EBADF; |
| 6521 | break; |
| 6522 | case F_WRLCK: |
| 6523 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6524 | return -EBADF; |
| 6525 | } |
| 6526 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6527 | status = nfs4_set_lock_state(state, request); |
| 6528 | if (status != 0) |
| 6529 | return status; |
| 6530 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6531 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6532 | } |
| 6533 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6534 | 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] | 6535 | { |
| 6536 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6537 | int err; |
| 6538 | |
| 6539 | err = nfs4_set_lock_state(state, fl); |
| 6540 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6541 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6542 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6543 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6544 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6545 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6546 | struct nfs_release_lockowner_data { |
| 6547 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6548 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6549 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6550 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6551 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6552 | }; |
| 6553 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6554 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6555 | { |
| 6556 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6557 | struct nfs_server *server = data->server; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 6558 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 6559 | &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6560 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6561 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6562 | } |
| 6563 | |
| 6564 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6565 | { |
| 6566 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6567 | struct nfs_server *server = data->server; |
| 6568 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6569 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6570 | |
| 6571 | switch (task->tk_status) { |
| 6572 | case 0: |
| 6573 | renew_lease(server, data->timestamp); |
| 6574 | break; |
| 6575 | case -NFS4ERR_STALE_CLIENTID: |
| 6576 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6577 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6578 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6579 | case -NFS4ERR_LEASE_MOVED: |
| 6580 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6581 | if (nfs4_async_handle_error(task, server, |
| 6582 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6583 | rpc_restart_call_prepare(task); |
| 6584 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6585 | } |
| 6586 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6587 | static void nfs4_release_lockowner_release(void *calldata) |
| 6588 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6589 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6590 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6591 | kfree(calldata); |
| 6592 | } |
| 6593 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6594 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6595 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6596 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6597 | .rpc_release = nfs4_release_lockowner_release, |
| 6598 | }; |
| 6599 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6600 | static void |
| 6601 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6602 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6603 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6604 | struct rpc_message msg = { |
| 6605 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6606 | }; |
| 6607 | |
| 6608 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6609 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6610 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6611 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6612 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6613 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6614 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6615 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6616 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6617 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6618 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6619 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6620 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6621 | msg.rpc_resp = &data->res; |
| 6622 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6623 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6624 | } |
| 6625 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6626 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6627 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6628 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6629 | struct dentry *unused, struct inode *inode, |
| 6630 | const char *key, const void *buf, |
| 6631 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6632 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6633 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6634 | } |
| 6635 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6636 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6637 | struct dentry *unused, struct inode *inode, |
| 6638 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6639 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6640 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6641 | } |
| 6642 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6643 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6644 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6645 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6646 | } |
| 6647 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6648 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6649 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6650 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6651 | struct dentry *unused, struct inode *inode, |
| 6652 | const char *key, const void *buf, |
| 6653 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6654 | { |
| 6655 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6656 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6657 | |
| 6658 | return -EOPNOTSUPP; |
| 6659 | } |
| 6660 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6661 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6662 | struct dentry *unused, struct inode *inode, |
| 6663 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6664 | { |
| 6665 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6666 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6667 | return -EOPNOTSUPP; |
| 6668 | } |
| 6669 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6670 | static ssize_t |
| 6671 | 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] | 6672 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6673 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6674 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6675 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6676 | len = security_inode_listsecurity(inode, list, list_len); |
| 6677 | if (list_len && len > list_len) |
| 6678 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6679 | } |
| 6680 | return len; |
| 6681 | } |
| 6682 | |
| 6683 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6684 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6685 | .get = nfs4_xattr_get_nfs4_label, |
| 6686 | .set = nfs4_xattr_set_nfs4_label, |
| 6687 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6688 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6689 | #else |
| 6690 | |
| 6691 | static ssize_t |
| 6692 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6693 | { |
| 6694 | return 0; |
| 6695 | } |
| 6696 | |
| 6697 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6698 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6699 | /* |
| 6700 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6701 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6702 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6703 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6704 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6705 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6706 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6707 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6708 | return; |
| 6709 | |
| 6710 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6711 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6712 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6713 | fattr->nlink = 2; |
| 6714 | } |
| 6715 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6716 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6717 | const struct qstr *name, |
| 6718 | struct nfs4_fs_locations *fs_locations, |
| 6719 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6720 | { |
| 6721 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6722 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6723 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6724 | }; |
| 6725 | struct nfs4_fs_locations_arg args = { |
| 6726 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6727 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6728 | .page = page, |
| 6729 | .bitmask = bitmask, |
| 6730 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6731 | struct nfs4_fs_locations_res res = { |
| 6732 | .fs_locations = fs_locations, |
| 6733 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6734 | struct rpc_message msg = { |
| 6735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6736 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6737 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6738 | }; |
| 6739 | int status; |
| 6740 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6741 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6742 | |
| 6743 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6744 | * is not supported */ |
| 6745 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6746 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6747 | else |
| 6748 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6749 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6750 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6751 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6752 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6753 | 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] | 6754 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6755 | return status; |
| 6756 | } |
| 6757 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6758 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6759 | const struct qstr *name, |
| 6760 | struct nfs4_fs_locations *fs_locations, |
| 6761 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6762 | { |
| 6763 | struct nfs4_exception exception = { }; |
| 6764 | int err; |
| 6765 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6766 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6767 | fs_locations, page); |
| 6768 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6769 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6770 | &exception); |
| 6771 | } while (exception.retry); |
| 6772 | return err; |
| 6773 | } |
| 6774 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6775 | /* |
| 6776 | * This operation also signals the server that this client is |
| 6777 | * performing migration recovery. The server can stop returning |
| 6778 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6779 | * appended to this compound to identify the client ID which is |
| 6780 | * performing recovery. |
| 6781 | */ |
| 6782 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6783 | struct nfs4_fs_locations *locations, |
| 6784 | struct page *page, struct rpc_cred *cred) |
| 6785 | { |
| 6786 | struct nfs_server *server = NFS_SERVER(inode); |
| 6787 | struct rpc_clnt *clnt = server->client; |
| 6788 | u32 bitmask[2] = { |
| 6789 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6790 | }; |
| 6791 | struct nfs4_fs_locations_arg args = { |
| 6792 | .clientid = server->nfs_client->cl_clientid, |
| 6793 | .fh = NFS_FH(inode), |
| 6794 | .page = page, |
| 6795 | .bitmask = bitmask, |
| 6796 | .migration = 1, /* skip LOOKUP */ |
| 6797 | .renew = 1, /* append RENEW */ |
| 6798 | }; |
| 6799 | struct nfs4_fs_locations_res res = { |
| 6800 | .fs_locations = locations, |
| 6801 | .migration = 1, |
| 6802 | .renew = 1, |
| 6803 | }; |
| 6804 | struct rpc_message msg = { |
| 6805 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6806 | .rpc_argp = &args, |
| 6807 | .rpc_resp = &res, |
| 6808 | .rpc_cred = cred, |
| 6809 | }; |
| 6810 | unsigned long now = jiffies; |
| 6811 | int status; |
| 6812 | |
| 6813 | nfs_fattr_init(&locations->fattr); |
| 6814 | locations->server = server; |
| 6815 | locations->nlocations = 0; |
| 6816 | |
| 6817 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6818 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6819 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6820 | &args.seq_args, &res.seq_res); |
| 6821 | if (status) |
| 6822 | return status; |
| 6823 | |
| 6824 | renew_lease(server, now); |
| 6825 | return 0; |
| 6826 | } |
| 6827 | |
| 6828 | #ifdef CONFIG_NFS_V4_1 |
| 6829 | |
| 6830 | /* |
| 6831 | * This operation also signals the server that this client is |
| 6832 | * performing migration recovery. The server can stop asserting |
| 6833 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6834 | * performing this operation is identified in the SEQUENCE |
| 6835 | * operation in this compound. |
| 6836 | * |
| 6837 | * When the client supports GETATTR(fs_locations_info), it can |
| 6838 | * be plumbed in here. |
| 6839 | */ |
| 6840 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6841 | struct nfs4_fs_locations *locations, |
| 6842 | struct page *page, struct rpc_cred *cred) |
| 6843 | { |
| 6844 | struct nfs_server *server = NFS_SERVER(inode); |
| 6845 | struct rpc_clnt *clnt = server->client; |
| 6846 | u32 bitmask[2] = { |
| 6847 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6848 | }; |
| 6849 | struct nfs4_fs_locations_arg args = { |
| 6850 | .fh = NFS_FH(inode), |
| 6851 | .page = page, |
| 6852 | .bitmask = bitmask, |
| 6853 | .migration = 1, /* skip LOOKUP */ |
| 6854 | }; |
| 6855 | struct nfs4_fs_locations_res res = { |
| 6856 | .fs_locations = locations, |
| 6857 | .migration = 1, |
| 6858 | }; |
| 6859 | struct rpc_message msg = { |
| 6860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6861 | .rpc_argp = &args, |
| 6862 | .rpc_resp = &res, |
| 6863 | .rpc_cred = cred, |
| 6864 | }; |
| 6865 | int status; |
| 6866 | |
| 6867 | nfs_fattr_init(&locations->fattr); |
| 6868 | locations->server = server; |
| 6869 | locations->nlocations = 0; |
| 6870 | |
| 6871 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6872 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6873 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6874 | &args.seq_args, &res.seq_res); |
| 6875 | if (status == NFS4_OK && |
| 6876 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6877 | status = -NFS4ERR_LEASE_MOVED; |
| 6878 | return status; |
| 6879 | } |
| 6880 | |
| 6881 | #endif /* CONFIG_NFS_V4_1 */ |
| 6882 | |
| 6883 | /** |
| 6884 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6885 | * @inode: inode on FSID that is migrating |
| 6886 | * @locations: result of query |
| 6887 | * @page: buffer |
| 6888 | * @cred: credential to use for this operation |
| 6889 | * |
| 6890 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6891 | * operation failed, or a negative errno if a local error occurred. |
| 6892 | * |
| 6893 | * On success, "locations" is filled in, but if the server has |
| 6894 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6895 | * asserted. |
| 6896 | * |
| 6897 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6898 | * from this client that require migration recovery. |
| 6899 | */ |
| 6900 | int nfs4_proc_get_locations(struct inode *inode, |
| 6901 | struct nfs4_fs_locations *locations, |
| 6902 | struct page *page, struct rpc_cred *cred) |
| 6903 | { |
| 6904 | struct nfs_server *server = NFS_SERVER(inode); |
| 6905 | struct nfs_client *clp = server->nfs_client; |
| 6906 | const struct nfs4_mig_recovery_ops *ops = |
| 6907 | clp->cl_mvops->mig_recovery_ops; |
| 6908 | struct nfs4_exception exception = { }; |
| 6909 | int status; |
| 6910 | |
| 6911 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6912 | (unsigned long long)server->fsid.major, |
| 6913 | (unsigned long long)server->fsid.minor, |
| 6914 | clp->cl_hostname); |
| 6915 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6916 | |
| 6917 | do { |
| 6918 | status = ops->get_locations(inode, locations, page, cred); |
| 6919 | if (status != -NFS4ERR_DELAY) |
| 6920 | break; |
| 6921 | nfs4_handle_exception(server, status, &exception); |
| 6922 | } while (exception.retry); |
| 6923 | return status; |
| 6924 | } |
| 6925 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6926 | /* |
| 6927 | * This operation also signals the server that this client is |
| 6928 | * performing "lease moved" recovery. The server can stop |
| 6929 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6930 | * is appended to this compound to identify the client ID which is |
| 6931 | * performing recovery. |
| 6932 | */ |
| 6933 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6934 | { |
| 6935 | struct nfs_server *server = NFS_SERVER(inode); |
| 6936 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6937 | struct rpc_clnt *clnt = server->client; |
| 6938 | struct nfs4_fsid_present_arg args = { |
| 6939 | .fh = NFS_FH(inode), |
| 6940 | .clientid = clp->cl_clientid, |
| 6941 | .renew = 1, /* append RENEW */ |
| 6942 | }; |
| 6943 | struct nfs4_fsid_present_res res = { |
| 6944 | .renew = 1, |
| 6945 | }; |
| 6946 | struct rpc_message msg = { |
| 6947 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6948 | .rpc_argp = &args, |
| 6949 | .rpc_resp = &res, |
| 6950 | .rpc_cred = cred, |
| 6951 | }; |
| 6952 | unsigned long now = jiffies; |
| 6953 | int status; |
| 6954 | |
| 6955 | res.fh = nfs_alloc_fhandle(); |
| 6956 | if (res.fh == NULL) |
| 6957 | return -ENOMEM; |
| 6958 | |
| 6959 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6960 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6961 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6962 | &args.seq_args, &res.seq_res); |
| 6963 | nfs_free_fhandle(res.fh); |
| 6964 | if (status) |
| 6965 | return status; |
| 6966 | |
| 6967 | do_renew_lease(clp, now); |
| 6968 | return 0; |
| 6969 | } |
| 6970 | |
| 6971 | #ifdef CONFIG_NFS_V4_1 |
| 6972 | |
| 6973 | /* |
| 6974 | * This operation also signals the server that this client is |
| 6975 | * performing "lease moved" recovery. The server can stop asserting |
| 6976 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6977 | * this operation is identified in the SEQUENCE operation in this |
| 6978 | * compound. |
| 6979 | */ |
| 6980 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6981 | { |
| 6982 | struct nfs_server *server = NFS_SERVER(inode); |
| 6983 | struct rpc_clnt *clnt = server->client; |
| 6984 | struct nfs4_fsid_present_arg args = { |
| 6985 | .fh = NFS_FH(inode), |
| 6986 | }; |
| 6987 | struct nfs4_fsid_present_res res = { |
| 6988 | }; |
| 6989 | struct rpc_message msg = { |
| 6990 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6991 | .rpc_argp = &args, |
| 6992 | .rpc_resp = &res, |
| 6993 | .rpc_cred = cred, |
| 6994 | }; |
| 6995 | int status; |
| 6996 | |
| 6997 | res.fh = nfs_alloc_fhandle(); |
| 6998 | if (res.fh == NULL) |
| 6999 | return -ENOMEM; |
| 7000 | |
| 7001 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7002 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7003 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7004 | &args.seq_args, &res.seq_res); |
| 7005 | nfs_free_fhandle(res.fh); |
| 7006 | if (status == NFS4_OK && |
| 7007 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7008 | status = -NFS4ERR_LEASE_MOVED; |
| 7009 | return status; |
| 7010 | } |
| 7011 | |
| 7012 | #endif /* CONFIG_NFS_V4_1 */ |
| 7013 | |
| 7014 | /** |
| 7015 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7016 | * @inode: inode on FSID to check |
| 7017 | * @cred: credential to use for this operation |
| 7018 | * |
| 7019 | * Server indicates whether the FSID is present, moved, or not |
| 7020 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7021 | * condition for this client ID. |
| 7022 | * |
| 7023 | * Returns NFS4_OK if the FSID is present on this server, |
| 7024 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7025 | * NFS4ERR code if some error occurred on the server, or a |
| 7026 | * negative errno if a local failure occurred. |
| 7027 | */ |
| 7028 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7029 | { |
| 7030 | struct nfs_server *server = NFS_SERVER(inode); |
| 7031 | struct nfs_client *clp = server->nfs_client; |
| 7032 | const struct nfs4_mig_recovery_ops *ops = |
| 7033 | clp->cl_mvops->mig_recovery_ops; |
| 7034 | struct nfs4_exception exception = { }; |
| 7035 | int status; |
| 7036 | |
| 7037 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7038 | (unsigned long long)server->fsid.major, |
| 7039 | (unsigned long long)server->fsid.minor, |
| 7040 | clp->cl_hostname); |
| 7041 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7042 | |
| 7043 | do { |
| 7044 | status = ops->fsid_present(inode, cred); |
| 7045 | if (status != -NFS4ERR_DELAY) |
| 7046 | break; |
| 7047 | nfs4_handle_exception(server, status, &exception); |
| 7048 | } while (exception.retry); |
| 7049 | return status; |
| 7050 | } |
| 7051 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7052 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7053 | * If 'use_integrity' is true and the state managment nfs_client |
| 7054 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7055 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7056 | * Considerations sections. Otherwise, just use the user cred with the |
| 7057 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7058 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7059 | 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] | 7060 | { |
| 7061 | int status; |
| 7062 | struct nfs4_secinfo_arg args = { |
| 7063 | .dir_fh = NFS_FH(dir), |
| 7064 | .name = name, |
| 7065 | }; |
| 7066 | struct nfs4_secinfo_res res = { |
| 7067 | .flavors = flavors, |
| 7068 | }; |
| 7069 | struct rpc_message msg = { |
| 7070 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7071 | .rpc_argp = &args, |
| 7072 | .rpc_resp = &res, |
| 7073 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7074 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7075 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7076 | |
| 7077 | if (use_integrity) { |
| 7078 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7079 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7080 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7081 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7082 | |
| 7083 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7084 | |
| 7085 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7086 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7087 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7088 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7089 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7090 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7091 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7092 | if (cred) |
| 7093 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7094 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7095 | return status; |
| 7096 | } |
| 7097 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7098 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7099 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7100 | { |
| 7101 | struct nfs4_exception exception = { }; |
| 7102 | int err; |
| 7103 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7104 | err = -NFS4ERR_WRONGSEC; |
| 7105 | |
| 7106 | /* try to use integrity protection with machine cred */ |
| 7107 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7108 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7109 | |
| 7110 | /* |
| 7111 | * if unable to use integrity protection, or SECINFO with |
| 7112 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7113 | * disallowed by spec, but exists in deployed servers) use |
| 7114 | * the current filesystem's rpc_client and the user cred. |
| 7115 | */ |
| 7116 | if (err == -NFS4ERR_WRONGSEC) |
| 7117 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7118 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7119 | trace_nfs4_secinfo(dir, name, err); |
| 7120 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7121 | &exception); |
| 7122 | } while (exception.retry); |
| 7123 | return err; |
| 7124 | } |
| 7125 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7126 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7127 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7128 | * Check the exchange flags returned by the server for invalid flags, having |
| 7129 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7130 | * DS flags set. |
| 7131 | */ |
| 7132 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7133 | { |
| 7134 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7135 | goto out_inval; |
| 7136 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7137 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7138 | goto out_inval; |
| 7139 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7140 | goto out_inval; |
| 7141 | return NFS_OK; |
| 7142 | out_inval: |
| 7143 | return -NFS4ERR_INVAL; |
| 7144 | } |
| 7145 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7146 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7147 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7148 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7149 | { |
| 7150 | if (a->server_scope_sz == b->server_scope_sz && |
| 7151 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7152 | return true; |
| 7153 | |
| 7154 | return false; |
| 7155 | } |
| 7156 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7157 | static void |
| 7158 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7159 | { |
| 7160 | } |
| 7161 | |
| 7162 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7163 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7164 | }; |
| 7165 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7166 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7167 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7168 | * |
| 7169 | * The 4.1 client currently uses the same TCP connection for the |
| 7170 | * fore and backchannel. |
| 7171 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7172 | static |
| 7173 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7174 | struct rpc_xprt *xprt, |
| 7175 | struct nfs_client *clp, |
| 7176 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7177 | { |
| 7178 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7179 | struct nfs41_bind_conn_to_session_args args = { |
| 7180 | .client = clp, |
| 7181 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7182 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7183 | struct nfs41_bind_conn_to_session_res res; |
| 7184 | struct rpc_message msg = { |
| 7185 | .rpc_proc = |
| 7186 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7187 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7188 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7189 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7190 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7191 | struct rpc_task_setup task_setup_data = { |
| 7192 | .rpc_client = clnt, |
| 7193 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7194 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7195 | .rpc_message = &msg, |
| 7196 | .flags = RPC_TASK_TIMEOUT, |
| 7197 | }; |
| 7198 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7199 | |
| 7200 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7201 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7202 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7203 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7204 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7205 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7206 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7207 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7208 | args.dir = NFS4_CDFC4_FORE; |
| 7209 | |
| 7210 | task = rpc_run_task(&task_setup_data); |
| 7211 | if (!IS_ERR(task)) { |
| 7212 | status = task->tk_status; |
| 7213 | rpc_put_task(task); |
| 7214 | } else |
| 7215 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7216 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7217 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7218 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7219 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7220 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7221 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7222 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7223 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7224 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7225 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7226 | __func__); |
| 7227 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7228 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7229 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7230 | 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] | 7231 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7232 | __func__); |
| 7233 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7234 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7235 | } |
| 7236 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7237 | out: |
| 7238 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7239 | return status; |
| 7240 | } |
| 7241 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7242 | struct rpc_bind_conn_calldata { |
| 7243 | struct nfs_client *clp; |
| 7244 | struct rpc_cred *cred; |
| 7245 | }; |
| 7246 | |
| 7247 | static int |
| 7248 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7249 | struct rpc_xprt *xprt, |
| 7250 | void *calldata) |
| 7251 | { |
| 7252 | struct rpc_bind_conn_calldata *p = calldata; |
| 7253 | |
| 7254 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7255 | } |
| 7256 | |
| 7257 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7258 | { |
| 7259 | struct rpc_bind_conn_calldata data = { |
| 7260 | .clp = clp, |
| 7261 | .cred = cred, |
| 7262 | }; |
| 7263 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7264 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7265 | } |
| 7266 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7268 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7269 | * 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] | 7270 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7271 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7272 | .how = SP4_MACH_CRED, |
| 7273 | .enforce.u.words = { |
| 7274 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7275 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7276 | 1 << (OP_CREATE_SESSION - 32) | |
| 7277 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7278 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7279 | }, |
| 7280 | .allow.u.words = { |
| 7281 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7282 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7283 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7284 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7285 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7286 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7287 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7288 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7289 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7290 | 1 << (OP_FREE_STATEID - 32) | |
| 7291 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7292 | } |
| 7293 | }; |
| 7294 | |
| 7295 | /* |
| 7296 | * Select the state protection mode for client `clp' given the server results |
| 7297 | * from exchange_id in `sp'. |
| 7298 | * |
| 7299 | * Returns 0 on success, negative errno otherwise. |
| 7300 | */ |
| 7301 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7302 | struct nfs41_state_protection *sp) |
| 7303 | { |
| 7304 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7305 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7306 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7307 | 1 << (OP_CREATE_SESSION - 32) | |
| 7308 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7309 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7310 | }; |
| 7311 | unsigned int i; |
| 7312 | |
| 7313 | if (sp->how == SP4_MACH_CRED) { |
| 7314 | /* Print state protect result */ |
| 7315 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7316 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7317 | if (test_bit(i, sp->enforce.u.longs)) |
| 7318 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7319 | if (test_bit(i, sp->allow.u.longs)) |
| 7320 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7321 | } |
| 7322 | |
| 7323 | /* make sure nothing is on enforce list that isn't supported */ |
| 7324 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7325 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7326 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7327 | return -EINVAL; |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | /* |
| 7332 | * Minimal mode - state operations are allowed to use machine |
| 7333 | * credential. Note this already happens by default, so the |
| 7334 | * client doesn't have to do anything more than the negotiation. |
| 7335 | * |
| 7336 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7337 | * we're already using the machine cred for exchange_id |
| 7338 | * and will never use a different cred. |
| 7339 | */ |
| 7340 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7341 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7342 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7343 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7344 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7345 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7346 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7347 | } else { |
| 7348 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7349 | return -EINVAL; |
| 7350 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7351 | |
| 7352 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7353 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7354 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7355 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7356 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7357 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7358 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7359 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7360 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7361 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7362 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7363 | &clp->cl_sp4_flags); |
| 7364 | } |
| 7365 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7366 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7367 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7368 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7369 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7370 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7371 | |
| 7372 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7373 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7374 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7375 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7376 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7377 | |
| 7378 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7379 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7380 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7381 | } |
| 7382 | |
| 7383 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7384 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7385 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7386 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | return 0; |
| 7390 | } |
| 7391 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7392 | struct nfs41_exchange_id_data { |
| 7393 | struct nfs41_exchange_id_res res; |
| 7394 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7395 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7396 | int rpc_status; |
| 7397 | }; |
| 7398 | |
| 7399 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7400 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7401 | struct nfs41_exchange_id_data *cdata = |
| 7402 | (struct nfs41_exchange_id_data *)data; |
| 7403 | struct nfs_client *clp = cdata->args.client; |
| 7404 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7405 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7406 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7407 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7408 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7409 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7410 | |
| 7411 | if (cdata->xprt && status == 0) { |
| 7412 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7413 | cdata->xprt); |
| 7414 | goto out; |
| 7415 | } |
| 7416 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7417 | if (status == 0) |
| 7418 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7419 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7420 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7421 | clp->cl_clientid = cdata->res.clientid; |
| 7422 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7423 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7424 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7425 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7426 | &clp->cl_session->session_state); |
| 7427 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7428 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7429 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7430 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7431 | clp->cl_serverowner = cdata->res.server_owner; |
| 7432 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7433 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7434 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7435 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7436 | clp->cl_implid = cdata->res.impl_id; |
| 7437 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7438 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7439 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7440 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7441 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7442 | dprintk("%s: server_scope mismatch detected\n", |
| 7443 | __func__); |
| 7444 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7445 | kfree(clp->cl_serverscope); |
| 7446 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7447 | } |
| 7448 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7449 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7450 | clp->cl_serverscope = cdata->res.server_scope; |
| 7451 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7452 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7453 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7454 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7455 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7456 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7457 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7458 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7459 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7460 | } |
| 7461 | |
| 7462 | static void nfs4_exchange_id_release(void *data) |
| 7463 | { |
| 7464 | struct nfs41_exchange_id_data *cdata = |
| 7465 | (struct nfs41_exchange_id_data *)data; |
| 7466 | |
| 7467 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7468 | if (cdata->xprt) { |
| 7469 | xprt_put(cdata->xprt); |
| 7470 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7471 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7472 | kfree(cdata->res.impl_id); |
| 7473 | kfree(cdata->res.server_scope); |
| 7474 | kfree(cdata->res.server_owner); |
| 7475 | kfree(cdata); |
| 7476 | } |
| 7477 | |
| 7478 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7479 | .rpc_call_done = nfs4_exchange_id_done, |
| 7480 | .rpc_release = nfs4_exchange_id_release, |
| 7481 | }; |
| 7482 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7483 | /* |
| 7484 | * _nfs4_proc_exchange_id() |
| 7485 | * |
| 7486 | * Wrapper for EXCHANGE_ID operation. |
| 7487 | */ |
| 7488 | 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] | 7489 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7490 | { |
| 7491 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7492 | struct rpc_message msg = { |
| 7493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7494 | .rpc_cred = cred, |
| 7495 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7496 | struct rpc_task_setup task_setup_data = { |
| 7497 | .rpc_client = clp->cl_rpcclient, |
| 7498 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7499 | .rpc_message = &msg, |
| 7500 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7501 | }; |
| 7502 | struct nfs41_exchange_id_data *calldata; |
| 7503 | struct rpc_task *task; |
| 7504 | int status = -EIO; |
| 7505 | |
| 7506 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7507 | goto out; |
| 7508 | |
| 7509 | status = -ENOMEM; |
| 7510 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7511 | if (!calldata) |
| 7512 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7513 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7514 | if (!xprt) |
| 7515 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7516 | |
| 7517 | status = nfs4_init_uniform_client_string(clp); |
| 7518 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7519 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7520 | |
| 7521 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7522 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7523 | clp->cl_owner_id); |
| 7524 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7525 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7526 | GFP_NOFS); |
| 7527 | status = -ENOMEM; |
| 7528 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7529 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7530 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7531 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7532 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7533 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7534 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7535 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7536 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7537 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7538 | goto out_server_scope; |
| 7539 | |
| 7540 | switch (sp4_how) { |
| 7541 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7542 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7543 | break; |
| 7544 | |
| 7545 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7546 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7547 | break; |
| 7548 | |
| 7549 | default: |
| 7550 | /* unsupported! */ |
| 7551 | WARN_ON_ONCE(1); |
| 7552 | status = -EINVAL; |
| 7553 | goto out_impl_id; |
| 7554 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7555 | if (xprt) { |
| 7556 | calldata->xprt = xprt; |
| 7557 | task_setup_data.rpc_xprt = xprt; |
| 7558 | task_setup_data.flags = |
| 7559 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7560 | calldata->args.verifier = &clp->cl_confirm; |
| 7561 | } else { |
| 7562 | calldata->args.verifier = &verifier; |
| 7563 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7564 | calldata->args.client = clp; |
| 7565 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7566 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7567 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7568 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7569 | #else |
| 7570 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7571 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7572 | #endif |
| 7573 | msg.rpc_argp = &calldata->args; |
| 7574 | msg.rpc_resp = &calldata->res; |
| 7575 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7576 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7577 | task = rpc_run_task(&task_setup_data); |
| 7578 | if (IS_ERR(task)) { |
| 7579 | status = PTR_ERR(task); |
| 7580 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7581 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7582 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7583 | if (!xprt) { |
| 7584 | status = rpc_wait_for_completion_task(task); |
| 7585 | if (!status) |
| 7586 | status = calldata->rpc_status; |
| 7587 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7588 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7589 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7590 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7591 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7592 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7593 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7594 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7595 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7596 | clp->cl_implid->date.seconds, |
| 7597 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7598 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7599 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7600 | |
| 7601 | out_impl_id: |
| 7602 | kfree(calldata->res.impl_id); |
| 7603 | out_server_scope: |
| 7604 | kfree(calldata->res.server_scope); |
| 7605 | out_server_owner: |
| 7606 | kfree(calldata->res.server_owner); |
| 7607 | out_calldata: |
| 7608 | kfree(calldata); |
| 7609 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7610 | } |
| 7611 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7612 | /* |
| 7613 | * nfs4_proc_exchange_id() |
| 7614 | * |
| 7615 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7616 | * |
| 7617 | * Since the clientid has expired, all compounds using sessions |
| 7618 | * associated with the stale clientid will be returning |
| 7619 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7620 | * be in some phase of session reset. |
| 7621 | * |
| 7622 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7623 | */ |
| 7624 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7625 | { |
| 7626 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7627 | int status; |
| 7628 | |
| 7629 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7630 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7631 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7632 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7633 | if (!status) |
| 7634 | return 0; |
| 7635 | } |
| 7636 | |
| 7637 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7638 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7639 | } |
| 7640 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7641 | /** |
| 7642 | * nfs4_test_session_trunk |
| 7643 | * |
| 7644 | * This is an add_xprt_test() test function called from |
| 7645 | * rpc_clnt_setup_test_and_add_xprt. |
| 7646 | * |
| 7647 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7648 | * and is dereferrenced in nfs4_exchange_id_release |
| 7649 | * |
| 7650 | * Upon success, add the new transport to the rpc_clnt |
| 7651 | * |
| 7652 | * @clnt: struct rpc_clnt to get new transport |
| 7653 | * @xprt: the rpc_xprt to test |
| 7654 | * @data: call data for _nfs4_proc_exchange_id. |
| 7655 | */ |
| 7656 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7657 | void *data) |
| 7658 | { |
| 7659 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7660 | u32 sp4_how; |
| 7661 | |
| 7662 | dprintk("--> %s try %s\n", __func__, |
| 7663 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7664 | |
| 7665 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7666 | |
| 7667 | /* Test connection for session trunking. Async exchange_id call */ |
| 7668 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7669 | } |
| 7670 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7671 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7672 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7673 | struct rpc_cred *cred) |
| 7674 | { |
| 7675 | struct rpc_message msg = { |
| 7676 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7677 | .rpc_argp = clp, |
| 7678 | .rpc_cred = cred, |
| 7679 | }; |
| 7680 | int status; |
| 7681 | |
| 7682 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7683 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7684 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7685 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7686 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7687 | return status; |
| 7688 | } |
| 7689 | |
| 7690 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7691 | struct rpc_cred *cred) |
| 7692 | { |
| 7693 | unsigned int loop; |
| 7694 | int ret; |
| 7695 | |
| 7696 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7697 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7698 | switch (ret) { |
| 7699 | case -NFS4ERR_DELAY: |
| 7700 | case -NFS4ERR_CLIENTID_BUSY: |
| 7701 | ssleep(1); |
| 7702 | break; |
| 7703 | default: |
| 7704 | return ret; |
| 7705 | } |
| 7706 | } |
| 7707 | return 0; |
| 7708 | } |
| 7709 | |
| 7710 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7711 | { |
| 7712 | struct rpc_cred *cred; |
| 7713 | int ret = 0; |
| 7714 | |
| 7715 | if (clp->cl_mvops->minor_version < 1) |
| 7716 | goto out; |
| 7717 | if (clp->cl_exchange_flags == 0) |
| 7718 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7719 | if (clp->cl_preserve_clid) |
| 7720 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7721 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7722 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7723 | if (cred) |
| 7724 | put_rpccred(cred); |
| 7725 | switch (ret) { |
| 7726 | case 0: |
| 7727 | case -NFS4ERR_STALE_CLIENTID: |
| 7728 | clp->cl_exchange_flags = 0; |
| 7729 | } |
| 7730 | out: |
| 7731 | return ret; |
| 7732 | } |
| 7733 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7734 | struct nfs4_get_lease_time_data { |
| 7735 | struct nfs4_get_lease_time_args *args; |
| 7736 | struct nfs4_get_lease_time_res *res; |
| 7737 | struct nfs_client *clp; |
| 7738 | }; |
| 7739 | |
| 7740 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7741 | void *calldata) |
| 7742 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7743 | struct nfs4_get_lease_time_data *data = |
| 7744 | (struct nfs4_get_lease_time_data *)calldata; |
| 7745 | |
| 7746 | dprintk("--> %s\n", __func__); |
| 7747 | /* just setup sequence, do not trigger session recovery |
| 7748 | since we're invoked within one */ |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 7749 | nfs4_setup_sequence(data->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7750 | &data->args->la_seq_args, |
| 7751 | &data->res->lr_seq_res, |
| 7752 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7753 | dprintk("<-- %s\n", __func__); |
| 7754 | } |
| 7755 | |
| 7756 | /* |
| 7757 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7758 | * from sequence operation or clientid errors. |
| 7759 | */ |
| 7760 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7761 | { |
| 7762 | struct nfs4_get_lease_time_data *data = |
| 7763 | (struct nfs4_get_lease_time_data *)calldata; |
| 7764 | |
| 7765 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7766 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7767 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7768 | switch (task->tk_status) { |
| 7769 | case -NFS4ERR_DELAY: |
| 7770 | case -NFS4ERR_GRACE: |
| 7771 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7772 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7773 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7774 | /* fall through */ |
| 7775 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7776 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7777 | return; |
| 7778 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7779 | dprintk("<-- %s\n", __func__); |
| 7780 | } |
| 7781 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7782 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7783 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7784 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7785 | }; |
| 7786 | |
| 7787 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7788 | { |
| 7789 | struct rpc_task *task; |
| 7790 | struct nfs4_get_lease_time_args args; |
| 7791 | struct nfs4_get_lease_time_res res = { |
| 7792 | .lr_fsinfo = fsinfo, |
| 7793 | }; |
| 7794 | struct nfs4_get_lease_time_data data = { |
| 7795 | .args = &args, |
| 7796 | .res = &res, |
| 7797 | .clp = clp, |
| 7798 | }; |
| 7799 | struct rpc_message msg = { |
| 7800 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7801 | .rpc_argp = &args, |
| 7802 | .rpc_resp = &res, |
| 7803 | }; |
| 7804 | struct rpc_task_setup task_setup = { |
| 7805 | .rpc_client = clp->cl_rpcclient, |
| 7806 | .rpc_message = &msg, |
| 7807 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7808 | .callback_data = &data, |
| 7809 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7810 | }; |
| 7811 | int status; |
| 7812 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7813 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7814 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7815 | dprintk("--> %s\n", __func__); |
| 7816 | task = rpc_run_task(&task_setup); |
| 7817 | |
| 7818 | if (IS_ERR(task)) |
| 7819 | status = PTR_ERR(task); |
| 7820 | else { |
| 7821 | status = task->tk_status; |
| 7822 | rpc_put_task(task); |
| 7823 | } |
| 7824 | dprintk("<-- %s return %d\n", __func__, status); |
| 7825 | |
| 7826 | return status; |
| 7827 | } |
| 7828 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7829 | /* |
| 7830 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7831 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7832 | * use them. |
| 7833 | * |
| 7834 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7835 | * always set csa_cachethis to FALSE because the current implementation |
| 7836 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7837 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7838 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7839 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7840 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7841 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7842 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7843 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7844 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7845 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7846 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7847 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7848 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7849 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7850 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7851 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7852 | |
| 7853 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7854 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7855 | __func__, |
| 7856 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7857 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7858 | |
| 7859 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7860 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7861 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7862 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7863 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7864 | 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] | 7865 | |
| 7866 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7867 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7868 | __func__, |
| 7869 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7870 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7871 | args->bc_attrs.max_reqs); |
| 7872 | } |
| 7873 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7874 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7875 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7876 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7877 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7878 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7879 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7880 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7881 | return -EINVAL; |
| 7882 | /* |
| 7883 | * Our requested max_ops is the minimum we need; we're not |
| 7884 | * prepared to break up compounds into smaller pieces than that. |
| 7885 | * So, no point even trying to continue if the server won't |
| 7886 | * cooperate: |
| 7887 | */ |
| 7888 | if (rcvd->max_ops < sent->max_ops) |
| 7889 | return -EINVAL; |
| 7890 | if (rcvd->max_reqs == 0) |
| 7891 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7892 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7893 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7894 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7895 | } |
| 7896 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7897 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7898 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7899 | { |
| 7900 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7901 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7902 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7903 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7904 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7905 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7906 | return -EINVAL; |
| 7907 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7908 | return -EINVAL; |
| 7909 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7910 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7911 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7912 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7913 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7914 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7915 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7916 | return 0; |
| 7917 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7918 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7919 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7920 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7921 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7922 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7923 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7924 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7925 | if (ret) |
| 7926 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7927 | return nfs4_verify_back_channel_attrs(args, res); |
| 7928 | } |
| 7929 | |
| 7930 | static void nfs4_update_session(struct nfs4_session *session, |
| 7931 | struct nfs41_create_session_res *res) |
| 7932 | { |
| 7933 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7934 | /* Mark client id and session as being confirmed */ |
| 7935 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7936 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7937 | session->flags = res->flags; |
| 7938 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7939 | if (res->flags & SESSION4_BACK_CHAN) |
| 7940 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7941 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7942 | } |
| 7943 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7944 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7945 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7946 | { |
| 7947 | struct nfs4_session *session = clp->cl_session; |
| 7948 | struct nfs41_create_session_args args = { |
| 7949 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7950 | .clientid = clp->cl_clientid, |
| 7951 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7952 | .cb_program = NFS4_CALLBACK, |
| 7953 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7954 | struct nfs41_create_session_res res; |
| 7955 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7956 | struct rpc_message msg = { |
| 7957 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7958 | .rpc_argp = &args, |
| 7959 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7960 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7961 | }; |
| 7962 | int status; |
| 7963 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7964 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7965 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7966 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7967 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7968 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7969 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7970 | switch (status) { |
| 7971 | case -NFS4ERR_STALE_CLIENTID: |
| 7972 | case -NFS4ERR_DELAY: |
| 7973 | case -ETIMEDOUT: |
| 7974 | case -EACCES: |
| 7975 | case -EAGAIN: |
| 7976 | goto out; |
| 7977 | }; |
| 7978 | |
| 7979 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7980 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7981 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7982 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7983 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7984 | if (status) |
| 7985 | goto out; |
| 7986 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7987 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7988 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7989 | return status; |
| 7990 | } |
| 7991 | |
| 7992 | /* |
| 7993 | * Issues a CREATE_SESSION operation to the server. |
| 7994 | * It is the responsibility of the caller to verify the session is |
| 7995 | * expired before calling this routine. |
| 7996 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7997 | 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] | 7998 | { |
| 7999 | int status; |
| 8000 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8001 | struct nfs4_session *session = clp->cl_session; |
| 8002 | |
| 8003 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8004 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8005 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8006 | if (status) |
| 8007 | goto out; |
| 8008 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8009 | /* Init or reset the session slot tables */ |
| 8010 | status = nfs4_setup_session_slot_tables(session); |
| 8011 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8012 | if (status) |
| 8013 | goto out; |
| 8014 | |
| 8015 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8016 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8017 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8018 | out: |
| 8019 | dprintk("<-- %s\n", __func__); |
| 8020 | return status; |
| 8021 | } |
| 8022 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8023 | /* |
| 8024 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8025 | * The caller must serialize access to this routine. |
| 8026 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8027 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8028 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8029 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8030 | struct rpc_message msg = { |
| 8031 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8032 | .rpc_argp = session, |
| 8033 | .rpc_cred = cred, |
| 8034 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8035 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8036 | |
| 8037 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8038 | |
| 8039 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8040 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8041 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8042 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8043 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8044 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8045 | |
| 8046 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8047 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8048 | "Session has been destroyed regardless...\n", status); |
| 8049 | |
| 8050 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8051 | return status; |
| 8052 | } |
| 8053 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8054 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8055 | * Renew the cl_session lease. |
| 8056 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8057 | struct nfs4_sequence_data { |
| 8058 | struct nfs_client *clp; |
| 8059 | struct nfs4_sequence_args args; |
| 8060 | struct nfs4_sequence_res res; |
| 8061 | }; |
| 8062 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8063 | static void nfs41_sequence_release(void *data) |
| 8064 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8065 | struct nfs4_sequence_data *calldata = data; |
| 8066 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8067 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8068 | if (atomic_read(&clp->cl_count) > 1) |
| 8069 | nfs4_schedule_state_renewal(clp); |
| 8070 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8071 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8072 | } |
| 8073 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8074 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8075 | { |
| 8076 | switch(task->tk_status) { |
| 8077 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8078 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8079 | return -EAGAIN; |
| 8080 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8081 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8082 | } |
| 8083 | return 0; |
| 8084 | } |
| 8085 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8086 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8087 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8088 | struct nfs4_sequence_data *calldata = data; |
| 8089 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8090 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8091 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8092 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8093 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8094 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8095 | if (task->tk_status < 0) { |
| 8096 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8097 | if (atomic_read(&clp->cl_count) == 1) |
| 8098 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8099 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8100 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8101 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8102 | return; |
| 8103 | } |
| 8104 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8105 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8106 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8107 | dprintk("<-- %s\n", __func__); |
| 8108 | } |
| 8109 | |
| 8110 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8111 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8112 | struct nfs4_sequence_data *calldata = data; |
| 8113 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8114 | struct nfs4_sequence_args *args; |
| 8115 | struct nfs4_sequence_res *res; |
| 8116 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8117 | args = task->tk_msg.rpc_argp; |
| 8118 | res = task->tk_msg.rpc_resp; |
| 8119 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8120 | nfs4_setup_sequence(clp, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8124 | .rpc_call_done = nfs41_sequence_call_done, |
| 8125 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8126 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8127 | }; |
| 8128 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8129 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8130 | struct rpc_cred *cred, |
| 8131 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8132 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8133 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8134 | struct rpc_message msg = { |
| 8135 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8136 | .rpc_cred = cred, |
| 8137 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8138 | struct rpc_task_setup task_setup_data = { |
| 8139 | .rpc_client = clp->cl_rpcclient, |
| 8140 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8141 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8142 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8143 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8144 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8145 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8146 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8147 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8148 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8149 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8150 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8151 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8152 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8153 | if (is_privileged) |
| 8154 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8155 | msg.rpc_argp = &calldata->args; |
| 8156 | msg.rpc_resp = &calldata->res; |
| 8157 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8158 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8159 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8160 | return rpc_run_task(&task_setup_data); |
| 8161 | } |
| 8162 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8163 | 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] | 8164 | { |
| 8165 | struct rpc_task *task; |
| 8166 | int ret = 0; |
| 8167 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8168 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8169 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8170 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8171 | if (IS_ERR(task)) |
| 8172 | ret = PTR_ERR(task); |
| 8173 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8174 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8175 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8176 | return ret; |
| 8177 | } |
| 8178 | |
| 8179 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8180 | { |
| 8181 | struct rpc_task *task; |
| 8182 | int ret; |
| 8183 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8184 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8185 | if (IS_ERR(task)) { |
| 8186 | ret = PTR_ERR(task); |
| 8187 | goto out; |
| 8188 | } |
| 8189 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8190 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8191 | ret = task->tk_status; |
| 8192 | rpc_put_task(task); |
| 8193 | out: |
| 8194 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8195 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8196 | } |
| 8197 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8198 | struct nfs4_reclaim_complete_data { |
| 8199 | struct nfs_client *clp; |
| 8200 | struct nfs41_reclaim_complete_args arg; |
| 8201 | struct nfs41_reclaim_complete_res res; |
| 8202 | }; |
| 8203 | |
| 8204 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8205 | { |
| 8206 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8207 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8208 | nfs4_setup_sequence(calldata->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8209 | &calldata->arg.seq_args, |
| 8210 | &calldata->res.seq_res, |
| 8211 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8212 | } |
| 8213 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8214 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8215 | { |
| 8216 | switch(task->tk_status) { |
| 8217 | case 0: |
| 8218 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8219 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8220 | break; |
| 8221 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8222 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8223 | /* fall through */ |
| 8224 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8225 | return -EAGAIN; |
| 8226 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8227 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8228 | } |
| 8229 | return 0; |
| 8230 | } |
| 8231 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8232 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8233 | { |
| 8234 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8235 | struct nfs_client *clp = calldata->clp; |
| 8236 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8237 | |
| 8238 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8239 | if (!nfs41_sequence_done(task, res)) |
| 8240 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8241 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8242 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8243 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8244 | rpc_restart_call_prepare(task); |
| 8245 | return; |
| 8246 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8247 | dprintk("<-- %s\n", __func__); |
| 8248 | } |
| 8249 | |
| 8250 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8251 | { |
| 8252 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8253 | |
| 8254 | kfree(calldata); |
| 8255 | } |
| 8256 | |
| 8257 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8258 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8259 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8260 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8261 | }; |
| 8262 | |
| 8263 | /* |
| 8264 | * Issue a global reclaim complete. |
| 8265 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8266 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8267 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8268 | { |
| 8269 | struct nfs4_reclaim_complete_data *calldata; |
| 8270 | struct rpc_task *task; |
| 8271 | struct rpc_message msg = { |
| 8272 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8273 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8274 | }; |
| 8275 | struct rpc_task_setup task_setup_data = { |
| 8276 | .rpc_client = clp->cl_rpcclient, |
| 8277 | .rpc_message = &msg, |
| 8278 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8279 | .flags = RPC_TASK_ASYNC, |
| 8280 | }; |
| 8281 | int status = -ENOMEM; |
| 8282 | |
| 8283 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8284 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8285 | if (calldata == NULL) |
| 8286 | goto out; |
| 8287 | calldata->clp = clp; |
| 8288 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8289 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8290 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8291 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8292 | msg.rpc_argp = &calldata->arg; |
| 8293 | msg.rpc_resp = &calldata->res; |
| 8294 | task_setup_data.callback_data = calldata; |
| 8295 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8296 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8297 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8298 | goto out; |
| 8299 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8300 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8301 | if (status == 0) |
| 8302 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8303 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8304 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8305 | out: |
| 8306 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8307 | return status; |
| 8308 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8309 | |
| 8310 | static void |
| 8311 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8312 | { |
| 8313 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8314 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8315 | |
| 8316 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8317 | nfs4_setup_sequence(server->nfs_client, &lgp->args.seq_args, |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8318 | &lgp->res.seq_res, task); |
| 8319 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8323 | { |
| 8324 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8325 | |
| 8326 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8327 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8328 | dprintk("<-- %s\n", __func__); |
| 8329 | } |
| 8330 | |
| 8331 | static int |
| 8332 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8333 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8334 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8335 | struct inode *inode = lgp->args.inode; |
| 8336 | struct nfs_server *server = NFS_SERVER(inode); |
| 8337 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8338 | int nfs4err = task->tk_status; |
| 8339 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8340 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8341 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8342 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8343 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8344 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8345 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8346 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8347 | |
| 8348 | /* |
| 8349 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8350 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8351 | * retry go inband. |
| 8352 | */ |
| 8353 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8354 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8355 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8356 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8357 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8358 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8359 | */ |
| 8360 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8361 | status = -EOVERFLOW; |
| 8362 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8363 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8364 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8365 | * (or clients) writing to the same RAID stripe except when |
| 8366 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8367 | * |
| 8368 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8369 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8370 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8371 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8372 | if (lgp->args.minlength == 0) { |
| 8373 | status = -EOVERFLOW; |
| 8374 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8375 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8376 | status = -EBUSY; |
| 8377 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8378 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8379 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8380 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8381 | case -NFS4ERR_DELEG_REVOKED: |
| 8382 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8383 | case -NFS4ERR_EXPIRED: |
| 8384 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8385 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8386 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8387 | lo = NFS_I(inode)->layout; |
| 8388 | /* If the open stateid was bad, then recover it. */ |
| 8389 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8390 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8391 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8392 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8393 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8394 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8395 | break; |
| 8396 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8397 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8398 | /* |
| 8399 | * Mark the bad layout state as invalid, then retry |
| 8400 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8401 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8402 | spin_unlock(&inode->i_lock); |
| 8403 | pnfs_free_lseg_list(&head); |
| 8404 | status = -EAGAIN; |
| 8405 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8406 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8407 | |
Trond Myklebust | 8ac0925 | 2017-01-23 22:44:12 -0500 | [diff] [blame] | 8408 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8409 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8410 | if (!status) { |
| 8411 | if (exception->retry) |
| 8412 | status = -EAGAIN; |
| 8413 | else |
| 8414 | status = err; |
| 8415 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8416 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8417 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8418 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8419 | } |
| 8420 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8421 | static size_t max_response_pages(struct nfs_server *server) |
| 8422 | { |
| 8423 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8424 | return nfs_page_array_len(0, max_resp_sz); |
| 8425 | } |
| 8426 | |
| 8427 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8428 | { |
| 8429 | int i; |
| 8430 | |
| 8431 | if (!pages) |
| 8432 | return; |
| 8433 | |
| 8434 | for (i = 0; i < size; i++) { |
| 8435 | if (!pages[i]) |
| 8436 | break; |
| 8437 | __free_page(pages[i]); |
| 8438 | } |
| 8439 | kfree(pages); |
| 8440 | } |
| 8441 | |
| 8442 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8443 | { |
| 8444 | struct page **pages; |
| 8445 | int i; |
| 8446 | |
| 8447 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8448 | if (!pages) { |
| 8449 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8450 | return NULL; |
| 8451 | } |
| 8452 | |
| 8453 | for (i = 0; i < size; i++) { |
| 8454 | pages[i] = alloc_page(gfp_flags); |
| 8455 | if (!pages[i]) { |
| 8456 | dprintk("%s: failed to allocate page\n", __func__); |
| 8457 | nfs4_free_pages(pages, size); |
| 8458 | return NULL; |
| 8459 | } |
| 8460 | } |
| 8461 | |
| 8462 | return pages; |
| 8463 | } |
| 8464 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8465 | static void nfs4_layoutget_release(void *calldata) |
| 8466 | { |
| 8467 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8468 | struct inode *inode = lgp->args.inode; |
| 8469 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8470 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8471 | |
| 8472 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8473 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8474 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8475 | put_nfs_open_context(lgp->args.ctx); |
| 8476 | kfree(calldata); |
| 8477 | dprintk("<-- %s\n", __func__); |
| 8478 | } |
| 8479 | |
| 8480 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8481 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8482 | .rpc_call_done = nfs4_layoutget_done, |
| 8483 | .rpc_release = nfs4_layoutget_release, |
| 8484 | }; |
| 8485 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8486 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8487 | 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] | 8488 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8489 | struct inode *inode = lgp->args.inode; |
| 8490 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8491 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8492 | struct rpc_task *task; |
| 8493 | struct rpc_message msg = { |
| 8494 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8495 | .rpc_argp = &lgp->args, |
| 8496 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8497 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8498 | }; |
| 8499 | struct rpc_task_setup task_setup_data = { |
| 8500 | .rpc_client = server->client, |
| 8501 | .rpc_message = &msg, |
| 8502 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8503 | .callback_data = lgp, |
| 8504 | .flags = RPC_TASK_ASYNC, |
| 8505 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8506 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8507 | struct nfs4_exception exception = { |
| 8508 | .inode = inode, |
| 8509 | .timeout = *timeout, |
| 8510 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8511 | int status = 0; |
| 8512 | |
| 8513 | dprintk("--> %s\n", __func__); |
| 8514 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8515 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8516 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8517 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8518 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8519 | if (!lgp->args.layout.pages) { |
| 8520 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8521 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8522 | } |
| 8523 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8524 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8525 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8526 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8527 | 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] | 8528 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8529 | task = rpc_run_task(&task_setup_data); |
| 8530 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8531 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8532 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8533 | if (status == 0) { |
| 8534 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8535 | *timeout = exception.timeout; |
| 8536 | } |
| 8537 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8538 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8539 | &lgp->args.range, |
| 8540 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8541 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8542 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8543 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8544 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8545 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8546 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8547 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8548 | rpc_put_task(task); |
| 8549 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8550 | if (status) |
| 8551 | return ERR_PTR(status); |
| 8552 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8553 | } |
| 8554 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8555 | static void |
| 8556 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8557 | { |
| 8558 | struct nfs4_layoutreturn *lrp = calldata; |
| 8559 | |
| 8560 | dprintk("--> %s\n", __func__); |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8561 | nfs4_setup_sequence(lrp->clp, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8562 | &lrp->args.seq_args, |
| 8563 | &lrp->res.seq_res, |
| 8564 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8565 | } |
| 8566 | |
| 8567 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8568 | { |
| 8569 | struct nfs4_layoutreturn *lrp = calldata; |
| 8570 | struct nfs_server *server; |
| 8571 | |
| 8572 | dprintk("--> %s\n", __func__); |
| 8573 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8574 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8575 | return; |
| 8576 | |
| 8577 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8578 | switch (task->tk_status) { |
| 8579 | default: |
| 8580 | task->tk_status = 0; |
| 8581 | case 0: |
| 8582 | break; |
| 8583 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8584 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8585 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8586 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8587 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8588 | return; |
| 8589 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8590 | dprintk("<-- %s\n", __func__); |
| 8591 | } |
| 8592 | |
| 8593 | static void nfs4_layoutreturn_release(void *calldata) |
| 8594 | { |
| 8595 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8596 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8597 | |
| 8598 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8599 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8600 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8601 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8602 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8603 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8604 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8605 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8606 | kfree(calldata); |
| 8607 | dprintk("<-- %s\n", __func__); |
| 8608 | } |
| 8609 | |
| 8610 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8611 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8612 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8613 | .rpc_release = nfs4_layoutreturn_release, |
| 8614 | }; |
| 8615 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8616 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8617 | { |
| 8618 | struct rpc_task *task; |
| 8619 | struct rpc_message msg = { |
| 8620 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8621 | .rpc_argp = &lrp->args, |
| 8622 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8623 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8624 | }; |
| 8625 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8626 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8627 | .rpc_message = &msg, |
| 8628 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8629 | .callback_data = lrp, |
| 8630 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8631 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8632 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8633 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8634 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8635 | &task_setup_data.rpc_client, &msg); |
| 8636 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8637 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8638 | if (!sync) { |
| 8639 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8640 | if (!lrp->inode) { |
| 8641 | nfs4_layoutreturn_release(lrp); |
| 8642 | return -EAGAIN; |
| 8643 | } |
| 8644 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8645 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8646 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8647 | task = rpc_run_task(&task_setup_data); |
| 8648 | if (IS_ERR(task)) |
| 8649 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8650 | if (sync) |
| 8651 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8652 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8653 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8654 | rpc_put_task(task); |
| 8655 | return status; |
| 8656 | } |
| 8657 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8658 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8659 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8660 | struct pnfs_device *pdev, |
| 8661 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8662 | { |
| 8663 | struct nfs4_getdeviceinfo_args args = { |
| 8664 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8665 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8666 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8667 | }; |
| 8668 | struct nfs4_getdeviceinfo_res res = { |
| 8669 | .pdev = pdev, |
| 8670 | }; |
| 8671 | struct rpc_message msg = { |
| 8672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8673 | .rpc_argp = &args, |
| 8674 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8675 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8676 | }; |
| 8677 | int status; |
| 8678 | |
| 8679 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8680 | 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] | 8681 | if (res.notification & ~args.notify_types) |
| 8682 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8683 | if (res.notification != args.notify_types) |
| 8684 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8685 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8686 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8687 | |
| 8688 | return status; |
| 8689 | } |
| 8690 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8691 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8692 | struct pnfs_device *pdev, |
| 8693 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8694 | { |
| 8695 | struct nfs4_exception exception = { }; |
| 8696 | int err; |
| 8697 | |
| 8698 | do { |
| 8699 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8700 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8701 | &exception); |
| 8702 | } while (exception.retry); |
| 8703 | return err; |
| 8704 | } |
| 8705 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8706 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8707 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8708 | { |
| 8709 | struct nfs4_layoutcommit_data *data = calldata; |
| 8710 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8711 | |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 8712 | nfs4_setup_sequence(server->nfs_client, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8713 | &data->args.seq_args, |
| 8714 | &data->res.seq_res, |
| 8715 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8716 | } |
| 8717 | |
| 8718 | static void |
| 8719 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8720 | { |
| 8721 | struct nfs4_layoutcommit_data *data = calldata; |
| 8722 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8723 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8724 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8725 | return; |
| 8726 | |
| 8727 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8728 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8729 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8730 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8731 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8732 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8733 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8734 | break; |
| 8735 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8736 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8737 | rpc_restart_call_prepare(task); |
| 8738 | return; |
| 8739 | } |
| 8740 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | static void nfs4_layoutcommit_release(void *calldata) |
| 8744 | { |
| 8745 | struct nfs4_layoutcommit_data *data = calldata; |
| 8746 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8747 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8748 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8749 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8750 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8751 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8752 | kfree(data); |
| 8753 | } |
| 8754 | |
| 8755 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8756 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8757 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8758 | .rpc_release = nfs4_layoutcommit_release, |
| 8759 | }; |
| 8760 | |
| 8761 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8762 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8763 | { |
| 8764 | struct rpc_message msg = { |
| 8765 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8766 | .rpc_argp = &data->args, |
| 8767 | .rpc_resp = &data->res, |
| 8768 | .rpc_cred = data->cred, |
| 8769 | }; |
| 8770 | struct rpc_task_setup task_setup_data = { |
| 8771 | .task = &data->task, |
| 8772 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8773 | .rpc_message = &msg, |
| 8774 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8775 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8776 | }; |
| 8777 | struct rpc_task *task; |
| 8778 | int status = 0; |
| 8779 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8780 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8781 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8782 | data->args.lastbytewritten, |
| 8783 | data->args.inode->i_ino); |
| 8784 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8785 | if (!sync) { |
| 8786 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8787 | if (data->inode == NULL) { |
| 8788 | nfs4_layoutcommit_release(data); |
| 8789 | return -EAGAIN; |
| 8790 | } |
| 8791 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8792 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8793 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8794 | task = rpc_run_task(&task_setup_data); |
| 8795 | if (IS_ERR(task)) |
| 8796 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8797 | if (sync) |
| 8798 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8799 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8800 | dprintk("%s: status %d\n", __func__, status); |
| 8801 | rpc_put_task(task); |
| 8802 | return status; |
| 8803 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8804 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8805 | /** |
| 8806 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8807 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8808 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8809 | static int |
| 8810 | _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] | 8811 | struct nfs_fsinfo *info, |
| 8812 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8813 | { |
| 8814 | struct nfs41_secinfo_no_name_args args = { |
| 8815 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8816 | }; |
| 8817 | struct nfs4_secinfo_res res = { |
| 8818 | .flavors = flavors, |
| 8819 | }; |
| 8820 | struct rpc_message msg = { |
| 8821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8822 | .rpc_argp = &args, |
| 8823 | .rpc_resp = &res, |
| 8824 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8825 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8826 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8827 | int status; |
| 8828 | |
| 8829 | if (use_integrity) { |
| 8830 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8831 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8832 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8833 | } |
| 8834 | |
| 8835 | dprintk("--> %s\n", __func__); |
| 8836 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8837 | &res.seq_res, 0); |
| 8838 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8839 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8840 | if (cred) |
| 8841 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8842 | |
| 8843 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8844 | } |
| 8845 | |
| 8846 | static int |
| 8847 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8848 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8849 | { |
| 8850 | struct nfs4_exception exception = { }; |
| 8851 | int err; |
| 8852 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8853 | /* first try using integrity protection */ |
| 8854 | err = -NFS4ERR_WRONGSEC; |
| 8855 | |
| 8856 | /* try to use integrity protection with machine cred */ |
| 8857 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8858 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8859 | flavors, true); |
| 8860 | |
| 8861 | /* |
| 8862 | * if unable to use integrity protection, or SECINFO with |
| 8863 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8864 | * disallowed by spec, but exists in deployed servers) use |
| 8865 | * the current filesystem's rpc_client and the user cred. |
| 8866 | */ |
| 8867 | if (err == -NFS4ERR_WRONGSEC) |
| 8868 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8869 | flavors, false); |
| 8870 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8871 | switch (err) { |
| 8872 | case 0: |
| 8873 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8874 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8875 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8876 | default: |
| 8877 | err = nfs4_handle_exception(server, err, &exception); |
| 8878 | } |
| 8879 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8880 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8881 | return err; |
| 8882 | } |
| 8883 | |
| 8884 | static int |
| 8885 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8886 | struct nfs_fsinfo *info) |
| 8887 | { |
| 8888 | int err; |
| 8889 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8890 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8891 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8892 | struct nfs4_secinfo4 *secinfo; |
| 8893 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8894 | |
| 8895 | page = alloc_page(GFP_KERNEL); |
| 8896 | if (!page) { |
| 8897 | err = -ENOMEM; |
| 8898 | goto out; |
| 8899 | } |
| 8900 | |
| 8901 | flavors = page_address(page); |
| 8902 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8903 | |
| 8904 | /* |
| 8905 | * Fall back on "guess and check" method if |
| 8906 | * the server doesn't support SECINFO_NO_NAME |
| 8907 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8908 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8909 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8910 | goto out_freepage; |
| 8911 | } |
| 8912 | if (err) |
| 8913 | goto out_freepage; |
| 8914 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8915 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8916 | secinfo = &flavors->flavors[i]; |
| 8917 | |
| 8918 | switch (secinfo->flavor) { |
| 8919 | case RPC_AUTH_NULL: |
| 8920 | case RPC_AUTH_UNIX: |
| 8921 | case RPC_AUTH_GSS: |
| 8922 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8923 | &secinfo->flavor_info); |
| 8924 | break; |
| 8925 | default: |
| 8926 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8927 | break; |
| 8928 | } |
| 8929 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8930 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8931 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8932 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8933 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8934 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8935 | info, flavor); |
| 8936 | if (!err) |
| 8937 | break; |
| 8938 | } |
| 8939 | } |
| 8940 | |
| 8941 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8942 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8943 | |
| 8944 | out_freepage: |
| 8945 | put_page(page); |
| 8946 | if (err == -EACCES) |
| 8947 | return -EPERM; |
| 8948 | out: |
| 8949 | return err; |
| 8950 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8951 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8952 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8953 | nfs4_stateid *stateid, |
| 8954 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8955 | { |
| 8956 | int status; |
| 8957 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8958 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8959 | }; |
| 8960 | struct nfs41_test_stateid_res res; |
| 8961 | struct rpc_message msg = { |
| 8962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8963 | .rpc_argp = &args, |
| 8964 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8965 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8966 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8967 | struct rpc_clnt *rpc_client = server->client; |
| 8968 | |
| 8969 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8970 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8971 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8972 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8973 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8974 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8975 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8976 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8977 | if (status != NFS_OK) { |
| 8978 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8979 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8980 | } |
| 8981 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8982 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8983 | } |
| 8984 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8985 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8986 | int err, struct nfs4_exception *exception) |
| 8987 | { |
| 8988 | exception->retry = 0; |
| 8989 | switch(err) { |
| 8990 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 8991 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8992 | nfs4_handle_exception(server, err, exception); |
| 8993 | break; |
| 8994 | case -NFS4ERR_BADSESSION: |
| 8995 | case -NFS4ERR_BADSLOT: |
| 8996 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8997 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8998 | case -NFS4ERR_DEADSESSION: |
| 8999 | nfs4_do_handle_exception(server, err, exception); |
| 9000 | } |
| 9001 | } |
| 9002 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9003 | /** |
| 9004 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9005 | * |
| 9006 | * @server: server / transport on which to perform the operation |
| 9007 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9008 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9009 | * |
| 9010 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9011 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9012 | * failed or the state ID is not currently valid. |
| 9013 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9014 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9015 | nfs4_stateid *stateid, |
| 9016 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9017 | { |
| 9018 | struct nfs4_exception exception = { }; |
| 9019 | int err; |
| 9020 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9021 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9022 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9023 | } while (exception.retry); |
| 9024 | return err; |
| 9025 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9026 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9027 | struct nfs_free_stateid_data { |
| 9028 | struct nfs_server *server; |
| 9029 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9030 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9031 | }; |
| 9032 | |
| 9033 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9034 | { |
| 9035 | struct nfs_free_stateid_data *data = calldata; |
Anna Schumaker | 7981c8a | 2017-01-10 11:39:53 -0500 | [diff] [blame] | 9036 | nfs4_setup_sequence(data->server->nfs_client, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9037 | &data->args.seq_args, |
| 9038 | &data->res.seq_res, |
| 9039 | task); |
| 9040 | } |
| 9041 | |
| 9042 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9043 | { |
| 9044 | struct nfs_free_stateid_data *data = calldata; |
| 9045 | |
| 9046 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9047 | |
| 9048 | switch (task->tk_status) { |
| 9049 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9050 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9051 | rpc_restart_call_prepare(task); |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | static void nfs41_free_stateid_release(void *calldata) |
| 9056 | { |
| 9057 | kfree(calldata); |
| 9058 | } |
| 9059 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9060 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9061 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9062 | .rpc_call_done = nfs41_free_stateid_done, |
| 9063 | .rpc_release = nfs41_free_stateid_release, |
| 9064 | }; |
| 9065 | |
| 9066 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9067 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9068 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9069 | bool privileged) |
| 9070 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9071 | struct rpc_message msg = { |
| 9072 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9073 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9074 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9075 | struct rpc_task_setup task_setup = { |
| 9076 | .rpc_client = server->client, |
| 9077 | .rpc_message = &msg, |
| 9078 | .callback_ops = &nfs41_free_stateid_ops, |
| 9079 | .flags = RPC_TASK_ASYNC, |
| 9080 | }; |
| 9081 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9082 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9083 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9084 | &task_setup.rpc_client, &msg); |
| 9085 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9086 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9087 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9088 | if (!data) |
| 9089 | return ERR_PTR(-ENOMEM); |
| 9090 | data->server = server; |
| 9091 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9092 | |
| 9093 | task_setup.callback_data = data; |
| 9094 | |
| 9095 | msg.rpc_argp = &data->args; |
| 9096 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9097 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9098 | if (privileged) |
| 9099 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9100 | |
| 9101 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9102 | } |
| 9103 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9104 | /** |
| 9105 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9106 | * |
| 9107 | * @server: server / transport on which to perform the operation |
| 9108 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9109 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9110 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9111 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9112 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9113 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9114 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9115 | const nfs4_stateid *stateid, |
| 9116 | struct rpc_cred *cred, |
| 9117 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9118 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9119 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9120 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9121 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9122 | if (IS_ERR(task)) |
| 9123 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9124 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9125 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9126 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9127 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9128 | static void |
| 9129 | 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] | 9130 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9131 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9132 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9133 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9134 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9135 | } |
| 9136 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9137 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9138 | const nfs4_stateid *s2) |
| 9139 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9140 | if (s1->type != s2->type) |
| 9141 | return false; |
| 9142 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9143 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9144 | return false; |
| 9145 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9146 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9147 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9148 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9149 | return true; |
| 9150 | |
| 9151 | return false; |
| 9152 | } |
| 9153 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9154 | #endif /* CONFIG_NFS_V4_1 */ |
| 9155 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9156 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9157 | const nfs4_stateid *s2) |
| 9158 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9159 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9160 | } |
| 9161 | |
| 9162 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9163 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9164 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9165 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9166 | .recover_open = nfs4_open_reclaim, |
| 9167 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9168 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9169 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9170 | }; |
| 9171 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9172 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9173 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9174 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9175 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9176 | .recover_open = nfs4_open_reclaim, |
| 9177 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9178 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9179 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9180 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9181 | }; |
| 9182 | #endif /* CONFIG_NFS_V4_1 */ |
| 9183 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9184 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9185 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9186 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9187 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9188 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9189 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9190 | }; |
| 9191 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9192 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9193 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9194 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9195 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9196 | .recover_open = nfs41_open_expired, |
| 9197 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9198 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9199 | }; |
| 9200 | #endif /* CONFIG_NFS_V4_1 */ |
| 9201 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9202 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9203 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9204 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9205 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9206 | }; |
| 9207 | |
| 9208 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9209 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9210 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9211 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9212 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9213 | }; |
| 9214 | #endif |
| 9215 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9216 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9217 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9218 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9219 | }; |
| 9220 | |
| 9221 | #if defined(CONFIG_NFS_V4_1) |
| 9222 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9223 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9224 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9225 | }; |
| 9226 | #endif /* CONFIG_NFS_V4_1 */ |
| 9227 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9228 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9229 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9230 | .init_caps = NFS_CAP_READDIRPLUS |
| 9231 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9232 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9233 | .init_client = nfs40_init_client, |
| 9234 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9235 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9236 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9237 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9238 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9239 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9240 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9241 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9242 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9243 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9244 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9245 | }; |
| 9246 | |
| 9247 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9248 | static struct nfs_seqid * |
| 9249 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9250 | { |
| 9251 | return NULL; |
| 9252 | } |
| 9253 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9254 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9255 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9256 | .init_caps = NFS_CAP_READDIRPLUS |
| 9257 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9258 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9259 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9260 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9261 | .init_client = nfs41_init_client, |
| 9262 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9263 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9264 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9265 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9266 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9267 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9268 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9269 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9270 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9271 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9272 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9273 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9274 | }; |
| 9275 | #endif |
| 9276 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9277 | #if defined(CONFIG_NFS_V4_2) |
| 9278 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9279 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9280 | .init_caps = NFS_CAP_READDIRPLUS |
| 9281 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9282 | | NFS_CAP_POSIX_LOCK |
| 9283 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9284 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9285 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9286 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9287 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9288 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9289 | | NFS_CAP_LAYOUTSTATS |
| 9290 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9291 | .init_client = nfs41_init_client, |
| 9292 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9293 | .match_stateid = nfs41_match_stateid, |
| 9294 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9295 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9296 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9297 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9298 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9299 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9300 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9301 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9302 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9303 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9304 | }; |
| 9305 | #endif |
| 9306 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9307 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9308 | [0] = &nfs_v4_0_minor_ops, |
| 9309 | #if defined(CONFIG_NFS_V4_1) |
| 9310 | [1] = &nfs_v4_1_minor_ops, |
| 9311 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9312 | #if defined(CONFIG_NFS_V4_2) |
| 9313 | [2] = &nfs_v4_2_minor_ops, |
| 9314 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9315 | }; |
| 9316 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9317 | 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] | 9318 | { |
| 9319 | ssize_t error, error2; |
| 9320 | |
| 9321 | error = generic_listxattr(dentry, list, size); |
| 9322 | if (error < 0) |
| 9323 | return error; |
| 9324 | if (list) { |
| 9325 | list += error; |
| 9326 | size -= error; |
| 9327 | } |
| 9328 | |
| 9329 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9330 | if (error2 < 0) |
| 9331 | return error2; |
| 9332 | return error + error2; |
| 9333 | } |
| 9334 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9335 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9336 | .create = nfs_create, |
| 9337 | .lookup = nfs_lookup, |
| 9338 | .atomic_open = nfs_atomic_open, |
| 9339 | .link = nfs_link, |
| 9340 | .unlink = nfs_unlink, |
| 9341 | .symlink = nfs_symlink, |
| 9342 | .mkdir = nfs_mkdir, |
| 9343 | .rmdir = nfs_rmdir, |
| 9344 | .mknod = nfs_mknod, |
| 9345 | .rename = nfs_rename, |
| 9346 | .permission = nfs_permission, |
| 9347 | .getattr = nfs_getattr, |
| 9348 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9349 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9350 | }; |
| 9351 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9352 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9353 | .permission = nfs_permission, |
| 9354 | .getattr = nfs_getattr, |
| 9355 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9356 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9357 | }; |
| 9358 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9359 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9360 | .version = 4, /* protocol version */ |
| 9361 | .dentry_ops = &nfs4_dentry_operations, |
| 9362 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9363 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9364 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9365 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9366 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9367 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9368 | .getattr = nfs4_proc_getattr, |
| 9369 | .setattr = nfs4_proc_setattr, |
| 9370 | .lookup = nfs4_proc_lookup, |
| 9371 | .access = nfs4_proc_access, |
| 9372 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9373 | .create = nfs4_proc_create, |
| 9374 | .remove = nfs4_proc_remove, |
| 9375 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9376 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9377 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9378 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9379 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9380 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9381 | .link = nfs4_proc_link, |
| 9382 | .symlink = nfs4_proc_symlink, |
| 9383 | .mkdir = nfs4_proc_mkdir, |
| 9384 | .rmdir = nfs4_proc_remove, |
| 9385 | .readdir = nfs4_proc_readdir, |
| 9386 | .mknod = nfs4_proc_mknod, |
| 9387 | .statfs = nfs4_proc_statfs, |
| 9388 | .fsinfo = nfs4_proc_fsinfo, |
| 9389 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9390 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9391 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9392 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9393 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9394 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9395 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9396 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9397 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9398 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9399 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9400 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9401 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9402 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9403 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9404 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9405 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9406 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9407 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9408 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9409 | .create_server = nfs4_create_server, |
| 9410 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9411 | }; |
| 9412 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9413 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9414 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9415 | .list = nfs4_xattr_list_nfs4_acl, |
| 9416 | .get = nfs4_xattr_get_nfs4_acl, |
| 9417 | .set = nfs4_xattr_set_nfs4_acl, |
| 9418 | }; |
| 9419 | |
| 9420 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9421 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9422 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9423 | &nfs4_xattr_nfs4_label_handler, |
| 9424 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9425 | NULL |
| 9426 | }; |
| 9427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9428 | /* |
| 9429 | * Local variables: |
| 9430 | * c-basic-offset: 8 |
| 9431 | * End: |
| 9432 | */ |