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> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | 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] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | 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] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 100 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 101 | struct rpc_cred *); |
| 102 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 103 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 229 | | FATTR4_WORD0_CHANGE |
| 230 | | FATTR4_WORD0_FILEID, |
| 231 | }; |
| 232 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 233 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | FATTR4_WORD0_FILES_AVAIL |
| 235 | | FATTR4_WORD0_FILES_FREE |
| 236 | | FATTR4_WORD0_FILES_TOTAL, |
| 237 | FATTR4_WORD1_SPACE_AVAIL |
| 238 | | FATTR4_WORD1_SPACE_FREE |
| 239 | | FATTR4_WORD1_SPACE_TOTAL |
| 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | FATTR4_WORD0_MAXLINK |
| 244 | | FATTR4_WORD0_MAXNAME, |
| 245 | 0 |
| 246 | }; |
| 247 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 248 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | | FATTR4_WORD0_MAXREAD |
| 250 | | FATTR4_WORD0_MAXWRITE |
| 251 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 252 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 253 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 254 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 255 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | FATTR4_WORD0_TYPE |
| 260 | | FATTR4_WORD0_CHANGE |
| 261 | | FATTR4_WORD0_SIZE |
| 262 | | FATTR4_WORD0_FSID |
| 263 | | FATTR4_WORD0_FILEID |
| 264 | | FATTR4_WORD0_FS_LOCATIONS, |
| 265 | FATTR4_WORD1_MODE |
| 266 | | FATTR4_WORD1_NUMLINKS |
| 267 | | FATTR4_WORD1_OWNER |
| 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | readdir->cookie = 0; |
| 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 290 | if (cookie == 2) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * NFSv4 servers do not return entries for '.' and '..' |
| 295 | * Therefore, we fake these entries here. We let '.' |
| 296 | * have cookie 0 and '..' have cookie 1. Note that |
| 297 | * when talking to the server, we always send cookie 0 |
| 298 | * instead of 1 or 2. |
| 299 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (cookie == 0) { |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_one; /* cookie, second word */ |
| 306 | *p++ = xdr_one; /* entry len */ |
| 307 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
| 322 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 323 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 324 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | readdir->pgbase = (char *)p - (char *)start; |
| 327 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 331 | static long nfs4_update_delay(long *timeout) |
| 332 | { |
| 333 | long ret; |
| 334 | if (!timeout) |
| 335 | return NFS4_POLL_RETRY_MAX; |
| 336 | if (*timeout <= 0) |
| 337 | *timeout = NFS4_POLL_RETRY_MIN; |
| 338 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 339 | *timeout = NFS4_POLL_RETRY_MAX; |
| 340 | ret = *timeout; |
| 341 | *timeout <<= 1; |
| 342 | return ret; |
| 343 | } |
| 344 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 346 | { |
| 347 | int res = 0; |
| 348 | |
| 349 | might_sleep(); |
| 350 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 351 | freezable_schedule_timeout_killable_unsafe( |
| 352 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | if (fatal_signal_pending(current)) |
| 354 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | return res; |
| 356 | } |
| 357 | |
| 358 | /* This is the error handling routine for processes that are allowed |
| 359 | * to sleep. |
| 360 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 361 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 362 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | { |
| 364 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 365 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 366 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 367 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 368 | int ret = errorcode; |
| 369 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 370 | exception->delay = 0; |
| 371 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | exception->retry = 0; |
| 373 | switch(errorcode) { |
| 374 | case 0: |
| 375 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 376 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_DELEG_REVOKED: |
| 378 | case -NFS4ERR_ADMIN_REVOKED: |
| 379 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 380 | if (inode) { |
| 381 | int err; |
| 382 | |
| 383 | err = nfs_async_inode_return_delegation(inode, |
| 384 | stateid); |
| 385 | if (err == 0) |
| 386 | goto wait_on_recovery; |
| 387 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 388 | exception->retry = 1; |
| 389 | break; |
| 390 | } |
| 391 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | if (state == NULL) |
| 393 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 394 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 395 | if (ret < 0) |
| 396 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 398 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 399 | if (state != NULL) { |
| 400 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 401 | if (ret < 0) |
| 402 | break; |
| 403 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 405 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 406 | nfs4_schedule_lease_recovery(clp); |
| 407 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 408 | case -NFS4ERR_MOVED: |
| 409 | ret = nfs4_schedule_migration_recovery(server); |
| 410 | if (ret < 0) |
| 411 | break; |
| 412 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 413 | case -NFS4ERR_LEASE_MOVED: |
| 414 | nfs4_schedule_lease_moved_recovery(clp); |
| 415 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 416 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 417 | case -NFS4ERR_BADSESSION: |
| 418 | case -NFS4ERR_BADSLOT: |
| 419 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 420 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 421 | case -NFS4ERR_DEADSESSION: |
| 422 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 423 | case -NFS4ERR_SEQ_MISORDERED: |
| 424 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 425 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 426 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 427 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 428 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 430 | if (exception->timeout > HZ) { |
| 431 | /* We have retried a decent amount, time to |
| 432 | * fail |
| 433 | */ |
| 434 | ret = -EBUSY; |
| 435 | break; |
| 436 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 438 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 439 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 440 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 441 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 442 | exception->delay = 1; |
| 443 | return 0; |
| 444 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 445 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 446 | case -NFS4ERR_OLD_STATEID: |
| 447 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 448 | break; |
| 449 | case -NFS4ERR_BADOWNER: |
| 450 | /* The following works around a Linux server bug! */ |
| 451 | case -NFS4ERR_BADNAME: |
| 452 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 453 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 454 | exception->retry = 1; |
| 455 | printk(KERN_WARNING "NFS: v4 server %s " |
| 456 | "does not accept raw " |
| 457 | "uid/gids. " |
| 458 | "Reenabling the idmapper.\n", |
| 459 | server->nfs_client->cl_hostname); |
| 460 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | } |
| 462 | /* We failed to handle the error */ |
| 463 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 464 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 465 | exception->recovering = 1; |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /* This is the error handling routine for processes that are allowed |
| 470 | * to sleep. |
| 471 | */ |
| 472 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 473 | { |
| 474 | struct nfs_client *clp = server->nfs_client; |
| 475 | int ret; |
| 476 | |
| 477 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 478 | if (exception->delay) { |
| 479 | ret = nfs4_delay(server->client, &exception->timeout); |
| 480 | goto out_retry; |
| 481 | } |
| 482 | if (exception->recovering) { |
| 483 | ret = nfs4_wait_clnt_recover(clp); |
| 484 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 485 | return -EIO; |
| 486 | goto out_retry; |
| 487 | } |
| 488 | return ret; |
| 489 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 490 | if (ret == 0) |
| 491 | exception->retry = 1; |
| 492 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 495 | static int |
| 496 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 497 | int errorcode, struct nfs4_exception *exception) |
| 498 | { |
| 499 | struct nfs_client *clp = server->nfs_client; |
| 500 | int ret; |
| 501 | |
| 502 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 503 | if (exception->delay) { |
| 504 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 505 | goto out_retry; |
| 506 | } |
| 507 | if (exception->recovering) { |
| 508 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 509 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 510 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 511 | goto out_retry; |
| 512 | } |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | ret = -EIO; |
| 515 | return ret; |
| 516 | out_retry: |
| 517 | if (ret == 0) |
| 518 | exception->retry = 1; |
| 519 | return ret; |
| 520 | } |
| 521 | |
| 522 | static int |
| 523 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 524 | struct nfs4_state *state, long *timeout) |
| 525 | { |
| 526 | struct nfs4_exception exception = { |
| 527 | .state = state, |
| 528 | }; |
| 529 | |
| 530 | if (task->tk_status >= 0) |
| 531 | return 0; |
| 532 | if (timeout) |
| 533 | exception.timeout = *timeout; |
| 534 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 535 | task->tk_status, |
| 536 | &exception); |
| 537 | if (exception.delay && timeout) |
| 538 | *timeout = exception.timeout; |
| 539 | if (exception.retry) |
| 540 | return -EAGAIN; |
| 541 | return 0; |
| 542 | } |
| 543 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 544 | /* |
| 545 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 546 | * or 'false' otherwise. |
| 547 | */ |
| 548 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 549 | { |
| 550 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 551 | |
| 552 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 553 | flavor == RPC_AUTH_GSS_KRB5P) |
| 554 | return true; |
| 555 | |
| 556 | return false; |
| 557 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 558 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 559 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | spin_lock(&clp->cl_lock); |
| 562 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 563 | clp->cl_last_renewal = timestamp; |
| 564 | spin_unlock(&clp->cl_lock); |
| 565 | } |
| 566 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 567 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 568 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 569 | struct nfs_client *clp = server->nfs_client; |
| 570 | |
| 571 | if (!nfs4_has_session(clp)) |
| 572 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 575 | struct nfs4_call_sync_data { |
| 576 | const struct nfs_server *seq_server; |
| 577 | struct nfs4_sequence_args *seq_args; |
| 578 | struct nfs4_sequence_res *seq_res; |
| 579 | }; |
| 580 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 581 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 582 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 583 | { |
| 584 | args->sa_slot = NULL; |
| 585 | args->sa_cache_this = cache_reply; |
| 586 | args->sa_privileged = 0; |
| 587 | |
| 588 | res->sr_slot = NULL; |
| 589 | } |
| 590 | |
| 591 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 592 | { |
| 593 | args->sa_privileged = 1; |
| 594 | } |
| 595 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 596 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 597 | struct nfs4_sequence_args *args, |
| 598 | struct nfs4_sequence_res *res, |
| 599 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 600 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 601 | struct nfs4_slot *slot; |
| 602 | |
| 603 | /* slot already allocated? */ |
| 604 | if (res->sr_slot != NULL) |
| 605 | goto out_start; |
| 606 | |
| 607 | spin_lock(&tbl->slot_tbl_lock); |
| 608 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 609 | goto out_sleep; |
| 610 | |
| 611 | slot = nfs4_alloc_slot(tbl); |
| 612 | if (IS_ERR(slot)) { |
| 613 | if (slot == ERR_PTR(-ENOMEM)) |
| 614 | task->tk_timeout = HZ >> 2; |
| 615 | goto out_sleep; |
| 616 | } |
| 617 | spin_unlock(&tbl->slot_tbl_lock); |
| 618 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 619 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 620 | args->sa_slot = slot; |
| 621 | res->sr_slot = slot; |
| 622 | |
| 623 | out_start: |
| 624 | rpc_call_start(task); |
| 625 | return 0; |
| 626 | |
| 627 | out_sleep: |
| 628 | if (args->sa_privileged) |
| 629 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 630 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 631 | else |
| 632 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 633 | spin_unlock(&tbl->slot_tbl_lock); |
| 634 | return -EAGAIN; |
| 635 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 636 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 637 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 638 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 639 | { |
| 640 | struct nfs4_slot *slot = res->sr_slot; |
| 641 | struct nfs4_slot_table *tbl; |
| 642 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 643 | tbl = slot->table; |
| 644 | spin_lock(&tbl->slot_tbl_lock); |
| 645 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 646 | nfs4_free_slot(tbl, slot); |
| 647 | spin_unlock(&tbl->slot_tbl_lock); |
| 648 | |
| 649 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static int nfs40_sequence_done(struct rpc_task *task, |
| 653 | struct nfs4_sequence_res *res) |
| 654 | { |
| 655 | if (res->sr_slot != NULL) |
| 656 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 657 | return 1; |
| 658 | } |
| 659 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 660 | #if defined(CONFIG_NFS_V4_1) |
| 661 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 662 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 663 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 664 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 665 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 666 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 667 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 668 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 670 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 671 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 672 | /* Bump the slot sequence number */ |
| 673 | if (slot->seq_done) |
| 674 | slot->seq_nr++; |
| 675 | slot->seq_done = 0; |
| 676 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 677 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 678 | /* Be nice to the server: try to ensure that the last transmitted |
| 679 | * value for highest_user_slotid <= target_highest_slotid |
| 680 | */ |
| 681 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 682 | send_new_highest_used_slotid = true; |
| 683 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 684 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 685 | send_new_highest_used_slotid = false; |
| 686 | goto out_unlock; |
| 687 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 688 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 689 | |
| 690 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 691 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 692 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 693 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 694 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 695 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 696 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 697 | if (waitqueue_active(&tbl->slot_waitq)) |
| 698 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 701 | static int nfs41_sequence_process(struct rpc_task *task, |
| 702 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 703 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 704 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 706 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 707 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 708 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 709 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 710 | if (slot == NULL) |
| 711 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 712 | /* don't increment the sequence number if the task wasn't sent */ |
| 713 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 714 | goto out; |
| 715 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 716 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 717 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 718 | if (slot->interrupted) { |
| 719 | slot->interrupted = 0; |
| 720 | interrupted = true; |
| 721 | } |
| 722 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 723 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 724 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 725 | switch (res->sr_status) { |
| 726 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 727 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 728 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 729 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 730 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 731 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 732 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 733 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 734 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | case 1: |
| 737 | /* |
| 738 | * sr_status remains 1 if an RPC level error occurred. |
| 739 | * The server may or may not have processed the sequence |
| 740 | * operation.. |
| 741 | * Mark the slot as having hosted an interrupted RPC call. |
| 742 | */ |
| 743 | slot->interrupted = 1; |
| 744 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 745 | case -NFS4ERR_DELAY: |
| 746 | /* The server detected a resend of the RPC call and |
| 747 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 748 | * of RFC5661. |
| 749 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 750 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 751 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 752 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 753 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 754 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 755 | case -NFS4ERR_BADSLOT: |
| 756 | /* |
| 757 | * The slot id we used was probably retired. Try again |
| 758 | * using a different slot id. |
| 759 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 760 | goto retry_nowait; |
| 761 | case -NFS4ERR_SEQ_MISORDERED: |
| 762 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 763 | * Was the last operation on this sequence interrupted? |
| 764 | * If so, retry after bumping the sequence number. |
| 765 | */ |
| 766 | if (interrupted) { |
| 767 | ++slot->seq_nr; |
| 768 | goto retry_nowait; |
| 769 | } |
| 770 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 771 | * Could this slot have been previously retired? |
| 772 | * If so, then the server may be expecting seq_nr = 1! |
| 773 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 774 | if (slot->seq_nr != 1) { |
| 775 | slot->seq_nr = 1; |
| 776 | goto retry_nowait; |
| 777 | } |
| 778 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 779 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 780 | ++slot->seq_nr; |
| 781 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 782 | default: |
| 783 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 784 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 785 | } |
| 786 | out: |
| 787 | /* The session may be reset by one of the error handlers. */ |
| 788 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 789 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 790 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | retry_nowait: |
| 792 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 794 | task->tk_status = 0; |
| 795 | ret = 0; |
| 796 | } |
| 797 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 799 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 800 | goto out; |
| 801 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 802 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 803 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 804 | |
| 805 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 806 | { |
| 807 | if (!nfs41_sequence_process(task, res)) |
| 808 | return 0; |
| 809 | if (res->sr_slot != NULL) |
| 810 | nfs41_sequence_free_slot(res); |
| 811 | return 1; |
| 812 | |
| 813 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 814 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 817 | { |
| 818 | if (res->sr_slot == NULL) |
| 819 | return 1; |
| 820 | if (res->sr_slot->table->session != NULL) |
| 821 | return nfs41_sequence_process(task, res); |
| 822 | return nfs40_sequence_done(task, res); |
| 823 | } |
| 824 | |
| 825 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 826 | { |
| 827 | if (res->sr_slot != NULL) { |
| 828 | if (res->sr_slot->table->session != NULL) |
| 829 | nfs41_sequence_free_slot(res); |
| 830 | else |
| 831 | nfs40_sequence_free_slot(res); |
| 832 | } |
| 833 | } |
| 834 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 835 | 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] | 836 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 837 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 839 | if (!res->sr_slot->table->session) |
| 840 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 841 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 844 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 845 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | struct nfs4_sequence_args *args, |
| 847 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 848 | struct rpc_task *task) |
| 849 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 850 | struct nfs4_slot *slot; |
| 851 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 852 | |
| 853 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 854 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 855 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 856 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 857 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 858 | tbl = &session->fc_slot_table; |
| 859 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 860 | task->tk_timeout = 0; |
| 861 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 862 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 863 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 864 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 865 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 866 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 867 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 870 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 871 | if (IS_ERR(slot)) { |
| 872 | /* If out of memory, try again in 1/4 second */ |
| 873 | if (slot == ERR_PTR(-ENOMEM)) |
| 874 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 875 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 876 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 877 | } |
| 878 | spin_unlock(&tbl->slot_tbl_lock); |
| 879 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 880 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 881 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 882 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 883 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 884 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 885 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 886 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 887 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 888 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | /* |
| 890 | * sr_status is only set in decode_sequence, and so will remain |
| 891 | * set to 1 if an rpc level failure occurs. |
| 892 | */ |
| 893 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 894 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 895 | out_success: |
| 896 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 898 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 899 | /* Privileged tasks are queued with top priority */ |
| 900 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 901 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 902 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 903 | else |
| 904 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 905 | spin_unlock(&tbl->slot_tbl_lock); |
| 906 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 907 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 908 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 909 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 910 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 911 | struct nfs4_sequence_args *args, |
| 912 | struct nfs4_sequence_res *res, |
| 913 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 914 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 915 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 916 | int ret = 0; |
| 917 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 918 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 919 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 920 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 921 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 922 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 923 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 924 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 925 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 926 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 927 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 928 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 929 | return ret; |
| 930 | } |
| 931 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 932 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 933 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 934 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 935 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 936 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 937 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 938 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 939 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 942 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 943 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 944 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 945 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 946 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 949 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 950 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 951 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 952 | }; |
| 953 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 954 | #else /* !CONFIG_NFS_V4_1 */ |
| 955 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 956 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 957 | struct nfs4_sequence_args *args, |
| 958 | struct nfs4_sequence_res *res, |
| 959 | struct rpc_task *task) |
| 960 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 961 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 962 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 963 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 964 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 965 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 966 | { |
| 967 | return nfs40_sequence_done(task, res); |
| 968 | } |
| 969 | |
| 970 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 971 | { |
| 972 | if (res->sr_slot != NULL) |
| 973 | nfs40_sequence_free_slot(res); |
| 974 | } |
| 975 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 976 | int nfs4_sequence_done(struct rpc_task *task, |
| 977 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 978 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 979 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 980 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 981 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 982 | |
| 983 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 984 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 985 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 986 | { |
| 987 | struct nfs4_call_sync_data *data = calldata; |
| 988 | nfs4_setup_sequence(data->seq_server, |
| 989 | data->seq_args, data->seq_res, task); |
| 990 | } |
| 991 | |
| 992 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 993 | { |
| 994 | struct nfs4_call_sync_data *data = calldata; |
| 995 | nfs4_sequence_done(task, data->seq_res); |
| 996 | } |
| 997 | |
| 998 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 999 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1000 | .rpc_call_done = nfs40_call_sync_done, |
| 1001 | }; |
| 1002 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1003 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1004 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1006 | struct nfs4_sequence_args *args, |
| 1007 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1008 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1009 | int ret; |
| 1010 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1011 | struct nfs_client *clp = server->nfs_client; |
| 1012 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1013 | .seq_server = server, |
| 1014 | .seq_args = args, |
| 1015 | .seq_res = res, |
| 1016 | }; |
| 1017 | struct rpc_task_setup task_setup = { |
| 1018 | .rpc_client = clnt, |
| 1019 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1020 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1021 | .callback_data = &data |
| 1022 | }; |
| 1023 | |
| 1024 | task = rpc_run_task(&task_setup); |
| 1025 | if (IS_ERR(task)) |
| 1026 | ret = PTR_ERR(task); |
| 1027 | else { |
| 1028 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1029 | rpc_put_task(task); |
| 1030 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1034 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1035 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1036 | struct rpc_message *msg, |
| 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res, |
| 1039 | int cache_reply) |
| 1040 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1041 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1042 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
| 1045 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1046 | { |
| 1047 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1048 | |
| 1049 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1050 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1051 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1053 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1054 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1055 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | spin_unlock(&dir->i_lock); |
| 1057 | } |
| 1058 | |
| 1059 | struct nfs4_opendata { |
| 1060 | struct kref kref; |
| 1061 | struct nfs_openargs o_arg; |
| 1062 | struct nfs_openres o_res; |
| 1063 | struct nfs_open_confirmargs c_arg; |
| 1064 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1065 | struct nfs4_string owner_name; |
| 1066 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1067 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1069 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1071 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | struct nfs4_state_owner *owner; |
| 1073 | struct nfs4_state *state; |
| 1074 | struct iattr attrs; |
| 1075 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1076 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1077 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1078 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1079 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | int cancelled; |
| 1081 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1082 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1083 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1084 | int err, struct nfs4_exception *exception) |
| 1085 | { |
| 1086 | if (err != -EINVAL) |
| 1087 | return false; |
| 1088 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1089 | return false; |
| 1090 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1091 | exception->retry = 1; |
| 1092 | return true; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1095 | static u32 |
| 1096 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1097 | fmode_t fmode, int openflags) |
| 1098 | { |
| 1099 | u32 res = 0; |
| 1100 | |
| 1101 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1102 | case FMODE_READ: |
| 1103 | res = NFS4_SHARE_ACCESS_READ; |
| 1104 | break; |
| 1105 | case FMODE_WRITE: |
| 1106 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1107 | break; |
| 1108 | case FMODE_READ|FMODE_WRITE: |
| 1109 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1110 | } |
| 1111 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1112 | goto out; |
| 1113 | /* Want no delegation if we're using O_DIRECT */ |
| 1114 | if (openflags & O_DIRECT) |
| 1115 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1116 | out: |
| 1117 | return res; |
| 1118 | } |
| 1119 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1120 | static enum open_claim_type4 |
| 1121 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1122 | enum open_claim_type4 claim) |
| 1123 | { |
| 1124 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1125 | return claim; |
| 1126 | switch (claim) { |
| 1127 | default: |
| 1128 | return claim; |
| 1129 | case NFS4_OPEN_CLAIM_FH: |
| 1130 | return NFS4_OPEN_CLAIM_NULL; |
| 1131 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1132 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1133 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1134 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1135 | } |
| 1136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1139 | { |
| 1140 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1141 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1142 | p->o_res.seqid = p->o_arg.seqid; |
| 1143 | p->c_res.seqid = p->c_arg.seqid; |
| 1144 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1145 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1146 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1147 | 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] | 1148 | } |
| 1149 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1150 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1151 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1152 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1153 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1154 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1155 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1156 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1157 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1158 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1159 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1160 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | struct nfs4_opendata *p; |
| 1162 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1163 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1164 | if (p == NULL) |
| 1165 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1166 | |
| 1167 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1168 | if (IS_ERR(p->f_label)) |
| 1169 | goto err_free_p; |
| 1170 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1171 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1172 | if (IS_ERR(p->a_label)) |
| 1173 | goto err_free_f; |
| 1174 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1175 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1176 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1177 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1178 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1179 | nfs_sb_active(dentry->d_sb); |
| 1180 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1181 | p->dir = parent; |
| 1182 | p->owner = sp; |
| 1183 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1184 | p->o_arg.open_flags = flags; |
| 1185 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1186 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1187 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1188 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1189 | * will return permission denied for all bits until close */ |
| 1190 | if (!(flags & O_EXCL)) { |
| 1191 | /* ask server to check for all possible rights as results |
| 1192 | * are cached */ |
| 1193 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1194 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1195 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1196 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1197 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1198 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1199 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1201 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1202 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1203 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1204 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1205 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1206 | case NFS4_OPEN_CLAIM_NULL: |
| 1207 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1208 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1209 | p->o_arg.fh = NFS_FH(dir); |
| 1210 | break; |
| 1211 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1212 | case NFS4_OPEN_CLAIM_FH: |
| 1213 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1214 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1215 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1216 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1217 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1218 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1219 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | p->o_arg.u.attrs = &p->attrs; |
| 1221 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1222 | |
| 1223 | verf[0] = jiffies; |
| 1224 | verf[1] = current->pid; |
| 1225 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1226 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1227 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1228 | p->c_arg.fh = &p->o_res.fh; |
| 1229 | p->c_arg.stateid = &p->o_res.stateid; |
| 1230 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1231 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1232 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1233 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1234 | |
| 1235 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1236 | nfs4_label_free(p->a_label); |
| 1237 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1238 | nfs4_label_free(p->f_label); |
| 1239 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1240 | kfree(p); |
| 1241 | err: |
| 1242 | dput(parent); |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1246 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1247 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1248 | struct nfs4_opendata *p = container_of(kref, |
| 1249 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1250 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1251 | |
| 1252 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1253 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1254 | if (p->state != NULL) |
| 1255 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1256 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1257 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1258 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1259 | nfs4_label_free(p->f_label); |
| 1260 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1261 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1262 | dput(p->dentry); |
| 1263 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1264 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1265 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1266 | kfree(p); |
| 1267 | } |
| 1268 | |
| 1269 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1270 | { |
| 1271 | if (p != NULL) |
| 1272 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1275 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1276 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1277 | int ret; |
| 1278 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1279 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1283 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1284 | fmode_t fmode) |
| 1285 | { |
| 1286 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1287 | case FMODE_READ|FMODE_WRITE: |
| 1288 | return state->n_rdwr != 0; |
| 1289 | case FMODE_WRITE: |
| 1290 | return state->n_wronly != 0; |
| 1291 | case FMODE_READ: |
| 1292 | return state->n_rdonly != 0; |
| 1293 | } |
| 1294 | WARN_ON_ONCE(1); |
| 1295 | return false; |
| 1296 | } |
| 1297 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1298 | 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] | 1299 | { |
| 1300 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1301 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1302 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1303 | goto out; |
| 1304 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1305 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1306 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1307 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1308 | break; |
| 1309 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1310 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1311 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1312 | break; |
| 1313 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1314 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1315 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1316 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1317 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1318 | return ret; |
| 1319 | } |
| 1320 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1321 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1322 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1323 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1324 | if (delegation == NULL) |
| 1325 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1326 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1327 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1328 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1329 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1330 | switch (claim) { |
| 1331 | case NFS4_OPEN_CLAIM_NULL: |
| 1332 | case NFS4_OPEN_CLAIM_FH: |
| 1333 | break; |
| 1334 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1335 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1336 | break; |
| 1337 | default: |
| 1338 | return 0; |
| 1339 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1340 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1341 | return 1; |
| 1342 | } |
| 1343 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1345 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1347 | case FMODE_WRITE: |
| 1348 | state->n_wronly++; |
| 1349 | break; |
| 1350 | case FMODE_READ: |
| 1351 | state->n_rdonly++; |
| 1352 | break; |
| 1353 | case FMODE_READ|FMODE_WRITE: |
| 1354 | state->n_rdwr++; |
| 1355 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1356 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1359 | 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] | 1360 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1361 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1362 | bool need_recover = false; |
| 1363 | |
| 1364 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1365 | need_recover = true; |
| 1366 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1367 | need_recover = true; |
| 1368 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1369 | need_recover = true; |
| 1370 | if (need_recover) |
| 1371 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1372 | } |
| 1373 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1374 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1375 | nfs4_stateid *stateid) |
| 1376 | { |
| 1377 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1378 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1379 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1380 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1381 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1382 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1383 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1384 | return true; |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1388 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1389 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1390 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1391 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1392 | if (state->n_wronly) |
| 1393 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1394 | if (state->n_rdonly) |
| 1395 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1396 | if (state->n_rdwr) |
| 1397 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1398 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1401 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1402 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1403 | nfs4_stateid *stateid, fmode_t fmode) |
| 1404 | { |
| 1405 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1406 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1407 | case FMODE_WRITE: |
| 1408 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1409 | break; |
| 1410 | case FMODE_READ: |
| 1411 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1412 | break; |
| 1413 | case 0: |
| 1414 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1415 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1416 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1417 | } |
| 1418 | if (stateid == NULL) |
| 1419 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1420 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1421 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1422 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1423 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1424 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1425 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1426 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1427 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1428 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1429 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1430 | } |
| 1431 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1432 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1433 | nfs4_stateid *arg_stateid, |
| 1434 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1435 | { |
| 1436 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1437 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1438 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1439 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1440 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1441 | } |
| 1442 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1443 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1444 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1445 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1446 | case FMODE_READ: |
| 1447 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1448 | break; |
| 1449 | case FMODE_WRITE: |
| 1450 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1451 | break; |
| 1452 | case FMODE_READ|FMODE_WRITE: |
| 1453 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1454 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1455 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1456 | return; |
| 1457 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1458 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1459 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1464 | /* |
| 1465 | * Protect the call to nfs4_state_set_mode_locked and |
| 1466 | * serialise the stateid update |
| 1467 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1468 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1469 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1470 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1471 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1472 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1473 | } |
| 1474 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1476 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1477 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1478 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1481 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1482 | { |
| 1483 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1484 | struct nfs_delegation *deleg_cur; |
| 1485 | int ret = 0; |
| 1486 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1487 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1488 | |
| 1489 | rcu_read_lock(); |
| 1490 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1491 | if (deleg_cur == NULL) |
| 1492 | goto no_delegation; |
| 1493 | |
| 1494 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1495 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1496 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1497 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1498 | goto no_delegation_unlock; |
| 1499 | |
| 1500 | if (delegation == NULL) |
| 1501 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1502 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1503 | goto no_delegation_unlock; |
| 1504 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1505 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1506 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
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 | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1514 | __update_open_stateid(state, open_stateid, NULL, fmode); |
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)) |
| 1518 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1523 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1524 | const nfs4_stateid *stateid) |
| 1525 | { |
| 1526 | struct nfs4_state *state = lsp->ls_state; |
| 1527 | bool ret = false; |
| 1528 | |
| 1529 | spin_lock(&state->state_lock); |
| 1530 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1531 | goto out_noupdate; |
| 1532 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1533 | goto out_noupdate; |
| 1534 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1535 | ret = true; |
| 1536 | out_noupdate: |
| 1537 | spin_unlock(&state->state_lock); |
| 1538 | return ret; |
| 1539 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1540 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1542 | { |
| 1543 | struct nfs_delegation *delegation; |
| 1544 | |
| 1545 | rcu_read_lock(); |
| 1546 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1547 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | rcu_read_unlock(); |
| 1549 | return; |
| 1550 | } |
| 1551 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1552 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1555 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1556 | { |
| 1557 | struct nfs4_state *state = opendata->state; |
| 1558 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1559 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1560 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1561 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1562 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1563 | nfs4_stateid stateid; |
| 1564 | int ret = -EAGAIN; |
| 1565 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1566 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1567 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1568 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1569 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1570 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1571 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1572 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1573 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | rcu_read_lock(); |
| 1575 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1576 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1577 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1578 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1579 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1580 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1581 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1582 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1583 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1584 | if (!opendata->is_recover) { |
| 1585 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1586 | if (ret != 0) |
| 1587 | goto out; |
| 1588 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1589 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1590 | |
| 1591 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1592 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1593 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1594 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1595 | out: |
| 1596 | return ERR_PTR(ret); |
| 1597 | out_return_state: |
| 1598 | atomic_inc(&state->count); |
| 1599 | return state; |
| 1600 | } |
| 1601 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1602 | static void |
| 1603 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1604 | { |
| 1605 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1606 | struct nfs_delegation *delegation; |
| 1607 | int delegation_flags = 0; |
| 1608 | |
| 1609 | rcu_read_lock(); |
| 1610 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1611 | if (delegation) |
| 1612 | delegation_flags = delegation->flags; |
| 1613 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1614 | switch (data->o_arg.claim) { |
| 1615 | default: |
| 1616 | break; |
| 1617 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1618 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1619 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1620 | "returning a delegation for " |
| 1621 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1622 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1623 | return; |
| 1624 | } |
| 1625 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1626 | nfs_inode_set_delegation(state->inode, |
| 1627 | data->owner->so_cred, |
| 1628 | &data->o_res); |
| 1629 | else |
| 1630 | nfs_inode_reclaim_delegation(state->inode, |
| 1631 | data->owner->so_cred, |
| 1632 | &data->o_res); |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1637 | * and update the nfs4_state. |
| 1638 | */ |
| 1639 | static struct nfs4_state * |
| 1640 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1641 | { |
| 1642 | struct inode *inode = data->state->inode; |
| 1643 | struct nfs4_state *state = data->state; |
| 1644 | int ret; |
| 1645 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1646 | if (!data->rpc_done) { |
| 1647 | if (data->rpc_status) { |
| 1648 | ret = data->rpc_status; |
| 1649 | goto err; |
| 1650 | } |
| 1651 | /* cached opens have already been processed */ |
| 1652 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1656 | if (ret) |
| 1657 | goto err; |
| 1658 | |
| 1659 | if (data->o_res.delegation_type != 0) |
| 1660 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1661 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1662 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1663 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1664 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1665 | |
| 1666 | return state; |
| 1667 | err: |
| 1668 | return ERR_PTR(ret); |
| 1669 | |
| 1670 | } |
| 1671 | |
| 1672 | static struct nfs4_state * |
| 1673 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1674 | { |
| 1675 | struct inode *inode; |
| 1676 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1677 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1680 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1681 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | goto out; |
| 1683 | } |
| 1684 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1685 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1687 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1688 | 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] | 1689 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1690 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1691 | goto err; |
| 1692 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | state = nfs4_get_open_state(inode, data->owner); |
| 1694 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1695 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1696 | if (data->o_res.delegation_type != 0) |
| 1697 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1698 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1699 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1701 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1702 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | err_put_inode: |
| 1705 | iput(inode); |
| 1706 | err: |
| 1707 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1710 | static struct nfs4_state * |
| 1711 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1712 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1713 | struct nfs4_state *ret; |
| 1714 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1715 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1716 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1717 | else |
| 1718 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1719 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1720 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1724 | { |
| 1725 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1726 | struct nfs_open_context *ctx; |
| 1727 | |
| 1728 | spin_lock(&state->inode->i_lock); |
| 1729 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1730 | if (ctx->state != state) |
| 1731 | continue; |
| 1732 | get_nfs_open_context(ctx); |
| 1733 | spin_unlock(&state->inode->i_lock); |
| 1734 | return ctx; |
| 1735 | } |
| 1736 | spin_unlock(&state->inode->i_lock); |
| 1737 | return ERR_PTR(-ENOENT); |
| 1738 | } |
| 1739 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1740 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1741 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1742 | { |
| 1743 | struct nfs4_opendata *opendata; |
| 1744 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1745 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1746 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1747 | if (opendata == NULL) |
| 1748 | return ERR_PTR(-ENOMEM); |
| 1749 | opendata->state = state; |
| 1750 | atomic_inc(&state->count); |
| 1751 | return opendata; |
| 1752 | } |
| 1753 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1754 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1755 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1756 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1757 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | int ret; |
| 1759 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1760 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1761 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1762 | opendata->o_arg.open_flags = 0; |
| 1763 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1764 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1765 | NFS_SB(opendata->dentry->d_sb), |
| 1766 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1767 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1768 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1769 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1770 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1771 | if (ret != 0) |
| 1772 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1773 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1774 | if (IS_ERR(newstate)) |
| 1775 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1776 | if (newstate != opendata->state) |
| 1777 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1778 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1779 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1783 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | int ret; |
| 1785 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1786 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1787 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1788 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1789 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1791 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1792 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1793 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1794 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1795 | if (ret != 0) |
| 1796 | return ret; |
| 1797 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1798 | if (ret != 0) |
| 1799 | return ret; |
| 1800 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1801 | if (ret != 0) |
| 1802 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1803 | /* |
| 1804 | * We may have performed cached opens for all three recoveries. |
| 1805 | * Check if we need to update the current stateid. |
| 1806 | */ |
| 1807 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1808 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1809 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 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_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1812 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1813 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * OPEN_RECLAIM: |
| 1819 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1821 | 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] | 1822 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1823 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1825 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | int status; |
| 1827 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1828 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1829 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1830 | if (IS_ERR(opendata)) |
| 1831 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1832 | rcu_read_lock(); |
| 1833 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1834 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1835 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1836 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1837 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1838 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1839 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | return status; |
| 1841 | } |
| 1842 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1843 | 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] | 1844 | { |
| 1845 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1846 | struct nfs4_exception exception = { }; |
| 1847 | int err; |
| 1848 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1849 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1850 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1851 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1852 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1853 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } while (exception.retry); |
| 1857 | return err; |
| 1858 | } |
| 1859 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1861 | { |
| 1862 | struct nfs_open_context *ctx; |
| 1863 | int ret; |
| 1864 | |
| 1865 | ctx = nfs4_state_find_open_context(state); |
| 1866 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1867 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1868 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1869 | put_nfs_open_context(ctx); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1873 | 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] | 1874 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1875 | switch (err) { |
| 1876 | default: |
| 1877 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1878 | "%d.\n", __func__, err); |
| 1879 | case 0: |
| 1880 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1881 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1882 | case -ESTALE: |
| 1883 | break; |
| 1884 | case -NFS4ERR_BADSESSION: |
| 1885 | case -NFS4ERR_BADSLOT: |
| 1886 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1887 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1888 | case -NFS4ERR_DEADSESSION: |
| 1889 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1890 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1891 | return -EAGAIN; |
| 1892 | case -NFS4ERR_STALE_CLIENTID: |
| 1893 | case -NFS4ERR_STALE_STATEID: |
| 1894 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1895 | case -NFS4ERR_EXPIRED: |
| 1896 | /* Don't recall a delegation if it was lost */ |
| 1897 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1898 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1899 | case -NFS4ERR_MOVED: |
| 1900 | nfs4_schedule_migration_recovery(server); |
| 1901 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1902 | case -NFS4ERR_LEASE_MOVED: |
| 1903 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1904 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1905 | case -NFS4ERR_DELEG_REVOKED: |
| 1906 | case -NFS4ERR_ADMIN_REVOKED: |
| 1907 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1908 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1909 | nfs_inode_find_state_and_recover(state->inode, |
| 1910 | stateid); |
| 1911 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1912 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1913 | case -NFS4ERR_DELAY: |
| 1914 | case -NFS4ERR_GRACE: |
| 1915 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1916 | ssleep(1); |
| 1917 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1918 | case -ENOMEM: |
| 1919 | case -NFS4ERR_DENIED: |
| 1920 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1921 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | return err; |
| 1924 | } |
| 1925 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1926 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1927 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1928 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1929 | { |
| 1930 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1931 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1932 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1933 | |
| 1934 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1935 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1936 | if (IS_ERR(opendata)) |
| 1937 | return PTR_ERR(opendata); |
| 1938 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1939 | write_seqlock(&state->seqlock); |
| 1940 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1943 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1944 | case FMODE_READ|FMODE_WRITE: |
| 1945 | case FMODE_WRITE: |
| 1946 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1947 | if (err) |
| 1948 | break; |
| 1949 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1950 | if (err) |
| 1951 | break; |
| 1952 | case FMODE_READ: |
| 1953 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1954 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1955 | nfs4_opendata_put(opendata); |
| 1956 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1957 | } |
| 1958 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1959 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1960 | { |
| 1961 | struct nfs4_opendata *data = calldata; |
| 1962 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1963 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1964 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1967 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1968 | { |
| 1969 | struct nfs4_opendata *data = calldata; |
| 1970 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1971 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1972 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1973 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1974 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1975 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1976 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1977 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1978 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1979 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static void nfs4_open_confirm_release(void *calldata) |
| 1983 | { |
| 1984 | struct nfs4_opendata *data = calldata; |
| 1985 | struct nfs4_state *state = NULL; |
| 1986 | |
| 1987 | /* If this request hasn't been cancelled, do nothing */ |
| 1988 | if (data->cancelled == 0) |
| 1989 | goto out_free; |
| 1990 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1991 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1992 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1993 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1994 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1995 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1996 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1997 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2001 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2002 | .rpc_call_done = nfs4_open_confirm_done, |
| 2003 | .rpc_release = nfs4_open_confirm_release, |
| 2004 | }; |
| 2005 | |
| 2006 | /* |
| 2007 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2008 | */ |
| 2009 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2010 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2011 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2012 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2013 | struct rpc_message msg = { |
| 2014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2015 | .rpc_argp = &data->c_arg, |
| 2016 | .rpc_resp = &data->c_res, |
| 2017 | .rpc_cred = data->owner->so_cred, |
| 2018 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2019 | struct rpc_task_setup task_setup_data = { |
| 2020 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2021 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | .callback_ops = &nfs4_open_confirm_ops, |
| 2023 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2024 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .flags = RPC_TASK_ASYNC, |
| 2026 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | int status; |
| 2028 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2029 | 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] | 2030 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2031 | data->rpc_done = 0; |
| 2032 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2033 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2034 | if (data->is_recover) |
| 2035 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2036 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2037 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2038 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2039 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2040 | if (status != 0) { |
| 2041 | data->cancelled = 1; |
| 2042 | smp_wmb(); |
| 2043 | } else |
| 2044 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2045 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | return status; |
| 2047 | } |
| 2048 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2049 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2051 | struct nfs4_opendata *data = calldata; |
| 2052 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2053 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2054 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2055 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2056 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2057 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2058 | /* |
| 2059 | * Check if we still need to send an OPEN call, or if we can use |
| 2060 | * a delegation instead. |
| 2061 | */ |
| 2062 | if (data->state != NULL) { |
| 2063 | struct nfs_delegation *delegation; |
| 2064 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2065 | 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] | 2066 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2067 | rcu_read_lock(); |
| 2068 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2069 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2070 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2071 | rcu_read_unlock(); |
| 2072 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2073 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2074 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2075 | switch (claim) { |
| 2076 | default: |
| 2077 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2078 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2079 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2080 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2081 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2082 | case NFS4_OPEN_CLAIM_FH: |
| 2083 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2084 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2085 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2086 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2087 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2088 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2089 | &data->o_res.seq_res, |
| 2090 | task) != 0) |
| 2091 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2092 | |
| 2093 | /* Set the create mode (note dependency on the session type) */ |
| 2094 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2095 | if (data->o_arg.open_flags & O_EXCL) { |
| 2096 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2097 | if (nfs4_has_persistent_session(clp)) |
| 2098 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2099 | else if (clp->cl_mvops->minor_version > 0) |
| 2100 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2101 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2102 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2103 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2104 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2105 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2106 | out_no_action: |
| 2107 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2108 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2109 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2112 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2113 | { |
| 2114 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2116 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2117 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2118 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2119 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2120 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2121 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2122 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2123 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2124 | case S_IFREG: |
| 2125 | break; |
| 2126 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2127 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2128 | break; |
| 2129 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2130 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2133 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2134 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2135 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2136 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2137 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2138 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2139 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2140 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2141 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | static void nfs4_open_release(void *calldata) |
| 2144 | { |
| 2145 | struct nfs4_opendata *data = calldata; |
| 2146 | struct nfs4_state *state = NULL; |
| 2147 | |
| 2148 | /* If this request hasn't been cancelled, do nothing */ |
| 2149 | if (data->cancelled == 0) |
| 2150 | goto out_free; |
| 2151 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2152 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2153 | goto out_free; |
| 2154 | /* In case we need an open_confirm, no cleanup! */ |
| 2155 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2156 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2157 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2158 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2159 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2161 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2165 | .rpc_call_prepare = nfs4_open_prepare, |
| 2166 | .rpc_call_done = nfs4_open_done, |
| 2167 | .rpc_release = nfs4_open_release, |
| 2168 | }; |
| 2169 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2170 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2171 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2172 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2173 | struct nfs_server *server = NFS_SERVER(dir); |
| 2174 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2175 | struct nfs_openres *o_res = &data->o_res; |
| 2176 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2177 | struct rpc_message msg = { |
| 2178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2179 | .rpc_argp = o_arg, |
| 2180 | .rpc_resp = o_res, |
| 2181 | .rpc_cred = data->owner->so_cred, |
| 2182 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2183 | struct rpc_task_setup task_setup_data = { |
| 2184 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2185 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2186 | .callback_ops = &nfs4_open_ops, |
| 2187 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2188 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | .flags = RPC_TASK_ASYNC, |
| 2190 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | int status; |
| 2192 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2193 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2194 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2195 | data->rpc_done = 0; |
| 2196 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2197 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2198 | data->is_recover = 0; |
| 2199 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2200 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2201 | data->is_recover = 1; |
| 2202 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2203 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2204 | if (IS_ERR(task)) |
| 2205 | return PTR_ERR(task); |
| 2206 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2207 | if (status != 0) { |
| 2208 | data->cancelled = 1; |
| 2209 | smp_wmb(); |
| 2210 | } else |
| 2211 | status = data->rpc_status; |
| 2212 | rpc_put_task(task); |
| 2213 | |
| 2214 | return status; |
| 2215 | } |
| 2216 | |
| 2217 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2218 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2219 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2220 | struct nfs_openres *o_res = &data->o_res; |
| 2221 | int status; |
| 2222 | |
| 2223 | status = nfs4_run_open_task(data, 1); |
| 2224 | if (status != 0 || !data->rpc_done) |
| 2225 | return status; |
| 2226 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2227 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2228 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2229 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2230 | status = _nfs4_proc_open_confirm(data); |
| 2231 | if (status != 0) |
| 2232 | return status; |
| 2233 | } |
| 2234 | |
| 2235 | return status; |
| 2236 | } |
| 2237 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2238 | /* |
| 2239 | * Additional permission checks in order to distinguish between an |
| 2240 | * open for read, and an open for execute. This works around the |
| 2241 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2242 | * the same. |
| 2243 | * Note that in the non-execute case, we want to turn off permission |
| 2244 | * checking if we just created a new file (POSIX open() semantics). |
| 2245 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2246 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2247 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2248 | struct nfs4_state *state, fmode_t fmode, |
| 2249 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2250 | { |
| 2251 | struct nfs_access_entry cache; |
| 2252 | u32 mask; |
| 2253 | |
| 2254 | /* access call failed or for some reason the server doesn't |
| 2255 | * support any access modes -- defer access call until later */ |
| 2256 | if (opendata->o_res.access_supported == 0) |
| 2257 | return 0; |
| 2258 | |
| 2259 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2260 | /* |
| 2261 | * Use openflags to check for exec, because fmode won't |
| 2262 | * always have FMODE_EXEC set when file open for exec. |
| 2263 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2264 | if (openflags & __FMODE_EXEC) { |
| 2265 | /* ONLY check for exec rights */ |
| 2266 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2267 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2268 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2269 | |
| 2270 | cache.cred = cred; |
| 2271 | cache.jiffies = jiffies; |
| 2272 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2273 | nfs_access_add_cache(state->inode, &cache); |
| 2274 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2275 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2276 | return 0; |
| 2277 | |
| 2278 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2279 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2280 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2283 | /* |
| 2284 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2285 | */ |
| 2286 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2287 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2288 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2289 | struct nfs_server *server = NFS_SERVER(dir); |
| 2290 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2291 | struct nfs_openres *o_res = &data->o_res; |
| 2292 | int status; |
| 2293 | |
| 2294 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2295 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2296 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2297 | if (status != 0) { |
| 2298 | if (status == -NFS4ERR_BADNAME && |
| 2299 | !(o_arg->open_flags & O_CREAT)) |
| 2300 | return -ENOENT; |
| 2301 | return status; |
| 2302 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2303 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2304 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2305 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2306 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2307 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2308 | if (o_arg->open_flags & O_EXCL) |
| 2309 | data->file_created = 1; |
| 2310 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2311 | data->file_created = 1; |
| 2312 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2313 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2314 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2316 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | } |
| 2320 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2321 | 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] | 2322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2325 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2326 | { |
| 2327 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2328 | } |
| 2329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | /* |
| 2331 | * OPEN_EXPIRED: |
| 2332 | * reclaim state on the server after a network partition. |
| 2333 | * Assumes caller holds the appropriate lock |
| 2334 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2335 | 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] | 2336 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2337 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2338 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2340 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2341 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2342 | if (IS_ERR(opendata)) |
| 2343 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2344 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2345 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2346 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2347 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2351 | 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] | 2352 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2353 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2354 | struct nfs4_exception exception = { }; |
| 2355 | int err; |
| 2356 | |
| 2357 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2358 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2359 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2360 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2361 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2362 | switch (err) { |
| 2363 | default: |
| 2364 | goto out; |
| 2365 | case -NFS4ERR_GRACE: |
| 2366 | case -NFS4ERR_DELAY: |
| 2367 | nfs4_handle_exception(server, err, &exception); |
| 2368 | err = 0; |
| 2369 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2370 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2371 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2372 | return err; |
| 2373 | } |
| 2374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2378 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2380 | ctx = nfs4_state_find_open_context(state); |
| 2381 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2382 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2383 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2384 | put_nfs_open_context(ctx); |
| 2385 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2388 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2389 | { |
| 2390 | nfs_remove_bad_delegation(state->inode); |
| 2391 | write_seqlock(&state->seqlock); |
| 2392 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2393 | write_sequnlock(&state->seqlock); |
| 2394 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2395 | } |
| 2396 | |
| 2397 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2398 | { |
| 2399 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2400 | nfs_finish_clear_delegation_stateid(state); |
| 2401 | } |
| 2402 | |
| 2403 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2404 | { |
| 2405 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2406 | nfs40_clear_delegation_stateid(state); |
| 2407 | return nfs4_open_expired(sp, state); |
| 2408 | } |
| 2409 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2410 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame^] | 2411 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2412 | nfs4_stateid *stateid, |
| 2413 | struct rpc_cred *cred) |
| 2414 | { |
| 2415 | int status; |
| 2416 | |
| 2417 | status = nfs41_test_stateid(server, stateid, cred); |
| 2418 | |
| 2419 | switch (status) { |
| 2420 | case -NFS4ERR_EXPIRED: |
| 2421 | case -NFS4ERR_ADMIN_REVOKED: |
| 2422 | case -NFS4ERR_DELEG_REVOKED: |
| 2423 | /* Ack the revoked state to the server */ |
| 2424 | nfs41_free_stateid(server, stateid, cred); |
| 2425 | case -NFS4ERR_BAD_STATEID: |
| 2426 | return status; |
| 2427 | } |
| 2428 | return NFS_OK; |
| 2429 | } |
| 2430 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2431 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2432 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2433 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2434 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2435 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2436 | struct rpc_cred *cred; |
| 2437 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2438 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2439 | /* Get the delegation credential for use by test/free_stateid */ |
| 2440 | rcu_read_lock(); |
| 2441 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2442 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2443 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2444 | return; |
| 2445 | } |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2446 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2447 | rcu_read_unlock(); |
| 2448 | nfs_finish_clear_delegation_stateid(state); |
| 2449 | return; |
| 2450 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2451 | |
| 2452 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2453 | cred = get_rpccred(delegation->cred); |
| 2454 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame^] | 2455 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2456 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame^] | 2457 | if (status != NFS_OK) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2458 | nfs_finish_clear_delegation_stateid(state); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2459 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2460 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | /** |
| 2464 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2465 | * |
| 2466 | * @state: NFSv4 state for an inode |
| 2467 | * |
| 2468 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2469 | * Otherwise a negative NFS4ERR value is returned. |
| 2470 | */ |
| 2471 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2472 | { |
| 2473 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2474 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2475 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2476 | int status; |
| 2477 | |
| 2478 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2479 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2480 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2481 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2482 | return -NFS4ERR_BAD_STATEID; |
| 2483 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame^] | 2484 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2485 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2486 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2487 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2488 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2489 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2490 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2491 | } |
| 2492 | return status; |
| 2493 | } |
| 2494 | |
| 2495 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2496 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2497 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2498 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2499 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2500 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2501 | if (status != NFS_OK) |
| 2502 | status = nfs4_open_expired(sp, state); |
| 2503 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2504 | } |
| 2505 | #endif |
| 2506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2508 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2509 | * fields corresponding to attributes that were used to store the verifier. |
| 2510 | * Make sure we clobber those fields in the later setattr call |
| 2511 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2512 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2513 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2514 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2515 | const u32 *attrset = opendata->o_res.attrset; |
| 2516 | |
| 2517 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2518 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2519 | sattr->ia_valid |= ATTR_ATIME; |
| 2520 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2521 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2522 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2523 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2524 | |
| 2525 | /* Except MODE, it seems harmless of setting twice. */ |
| 2526 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2527 | sattr->ia_valid &= ~ATTR_MODE; |
| 2528 | |
| 2529 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2530 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2531 | } |
| 2532 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2533 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2534 | fmode_t fmode, |
| 2535 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2536 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2537 | { |
| 2538 | struct nfs4_state_owner *sp = opendata->owner; |
| 2539 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2540 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2541 | struct nfs4_state *state; |
| 2542 | unsigned int seq; |
| 2543 | int ret; |
| 2544 | |
| 2545 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2546 | |
| 2547 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2548 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2549 | goto out; |
| 2550 | |
| 2551 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2552 | ret = PTR_ERR(state); |
| 2553 | if (IS_ERR(state)) |
| 2554 | goto out; |
| 2555 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2556 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2557 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2558 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2559 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2560 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2561 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2562 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2563 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2564 | alias = d_exact_alias(dentry, state->inode); |
| 2565 | if (!alias) |
| 2566 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2567 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2568 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2569 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2570 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2571 | } |
| 2572 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2573 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2574 | } |
| 2575 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2576 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2577 | if (ret != 0) |
| 2578 | goto out; |
| 2579 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2580 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2581 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2582 | nfs_inode_attach_open_context(ctx); |
| 2583 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2584 | nfs4_schedule_stateid_recovery(server, state); |
| 2585 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2586 | out: |
| 2587 | return ret; |
| 2588 | } |
| 2589 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2590 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2591 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2593 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2594 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2595 | int flags, |
| 2596 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2597 | struct nfs4_label *label, |
| 2598 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | { |
| 2600 | struct nfs4_state_owner *sp; |
| 2601 | struct nfs4_state *state = NULL; |
| 2602 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2603 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2604 | struct dentry *dentry = ctx->dentry; |
| 2605 | struct rpc_cred *cred = ctx->cred; |
| 2606 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2607 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2608 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2609 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2610 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | |
| 2612 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2614 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2615 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2617 | goto out_err; |
| 2618 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2619 | status = nfs4_recover_expired_lease(server); |
| 2620 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2621 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2622 | if (d_really_is_positive(dentry)) |
| 2623 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2624 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2625 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2626 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2627 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2628 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2629 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2630 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2632 | if (label) { |
| 2633 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2634 | if (IS_ERR(olabel)) { |
| 2635 | status = PTR_ERR(olabel); |
| 2636 | goto err_opendata_put; |
| 2637 | } |
| 2638 | } |
| 2639 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2640 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2641 | if (!opendata->f_attr.mdsthreshold) { |
| 2642 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2643 | if (!opendata->f_attr.mdsthreshold) |
| 2644 | goto err_free_label; |
| 2645 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2646 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2647 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2648 | if (d_really_is_positive(dentry)) |
| 2649 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2650 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2651 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2652 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2653 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2654 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2655 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2656 | 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] | 2657 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2658 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2659 | /* |
| 2660 | * send create attributes which was not set by open |
| 2661 | * with an extra setattr. |
| 2662 | */ |
| 2663 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2664 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2665 | status = nfs4_do_setattr(state->inode, cred, |
| 2666 | opendata->o_res.f_attr, sattr, |
| 2667 | state, label, olabel); |
| 2668 | if (status == 0) { |
| 2669 | nfs_setattr_update_inode(state->inode, sattr, |
| 2670 | opendata->o_res.f_attr); |
| 2671 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2672 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2673 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2674 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2675 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2676 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2677 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2678 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2679 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2680 | opendata->f_attr.mdsthreshold = NULL; |
| 2681 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2682 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2683 | nfs4_label_free(olabel); |
| 2684 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2685 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2688 | err_free_label: |
| 2689 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2690 | err_opendata_put: |
| 2691 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2692 | err_put_state_owner: |
| 2693 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | return status; |
| 2696 | } |
| 2697 | |
| 2698 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2699 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2700 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2701 | int flags, |
| 2702 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2703 | struct nfs4_label *label, |
| 2704 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2706 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | struct nfs4_exception exception = { }; |
| 2708 | struct nfs4_state *res; |
| 2709 | int status; |
| 2710 | |
| 2711 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2712 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2713 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2714 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | if (status == 0) |
| 2716 | break; |
| 2717 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2718 | * book-keeping w.r.t. state-changing operations |
| 2719 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2720 | * It is actually a sign of a bug on the client or on the server. |
| 2721 | * |
| 2722 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2723 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | * have unhashed the old state_owner for us, and that we can |
| 2725 | * therefore safely retry using a new one. We should still warn |
| 2726 | * the user though... |
| 2727 | */ |
| 2728 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2729 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2730 | " returned a bad sequence-id error!\n", |
| 2731 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | exception.retry = 1; |
| 2733 | continue; |
| 2734 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2735 | /* |
| 2736 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2737 | * state before it received the OPEN_CONFIRM. |
| 2738 | * Recover by retrying the request as per the discussion |
| 2739 | * on Page 181 of RFC3530. |
| 2740 | */ |
| 2741 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2742 | exception.retry = 1; |
| 2743 | continue; |
| 2744 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2745 | if (status == -EAGAIN) { |
| 2746 | /* We must have found a delegation */ |
| 2747 | exception.retry = 1; |
| 2748 | continue; |
| 2749 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2750 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2751 | continue; |
| 2752 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | status, &exception)); |
| 2754 | } while (exception.retry); |
| 2755 | return res; |
| 2756 | } |
| 2757 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2758 | static int _nfs4_do_setattr(struct inode *inode, |
| 2759 | struct nfs_setattrargs *arg, |
| 2760 | struct nfs_setattrres *res, |
| 2761 | struct rpc_cred *cred, |
| 2762 | struct nfs4_state *state) |
| 2763 | { |
| 2764 | struct nfs_server *server = NFS_SERVER(inode); |
| 2765 | struct rpc_message msg = { |
| 2766 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2767 | .rpc_argp = arg, |
| 2768 | .rpc_resp = res, |
| 2769 | .rpc_cred = cred, |
| 2770 | }; |
| 2771 | struct rpc_cred *delegation_cred = NULL; |
| 2772 | unsigned long timestamp = jiffies; |
| 2773 | fmode_t fmode; |
| 2774 | bool truncate; |
| 2775 | int status; |
| 2776 | |
| 2777 | nfs_fattr_init(res->fattr); |
| 2778 | |
| 2779 | /* Servers should only apply open mode checks for file size changes */ |
| 2780 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2781 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2782 | |
| 2783 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2784 | /* Use that stateid */ |
| 2785 | } else if (truncate && state != NULL) { |
| 2786 | struct nfs_lockowner lockowner = { |
| 2787 | .l_owner = current->files, |
| 2788 | .l_pid = current->tgid, |
| 2789 | }; |
| 2790 | if (!nfs4_valid_open_stateid(state)) |
| 2791 | return -EBADF; |
| 2792 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2793 | &arg->stateid, &delegation_cred) == -EIO) |
| 2794 | return -EBADF; |
| 2795 | } else |
| 2796 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2797 | if (delegation_cred) |
| 2798 | msg.rpc_cred = delegation_cred; |
| 2799 | |
| 2800 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2801 | |
| 2802 | put_rpccred(delegation_cred); |
| 2803 | if (status == 0 && state != NULL) |
| 2804 | renew_lease(server, timestamp); |
| 2805 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2806 | return status; |
| 2807 | } |
| 2808 | |
| 2809 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2810 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2811 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2812 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2814 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2816 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | .iap = sattr, |
| 2818 | .server = server, |
| 2819 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2820 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | }; |
| 2822 | struct nfs_setattrres res = { |
| 2823 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2824 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | .server = server, |
| 2826 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2827 | struct nfs4_exception exception = { |
| 2828 | .state = state, |
| 2829 | .inode = inode, |
| 2830 | .stateid = &arg.stateid, |
| 2831 | }; |
| 2832 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2834 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2835 | if (ilabel) |
| 2836 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2839 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2840 | switch (err) { |
| 2841 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2842 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2843 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2844 | "applying open mode checks to " |
| 2845 | "a SETATTR that is not " |
| 2846 | "changing file size.\n", |
| 2847 | server->nfs_client->cl_hostname); |
| 2848 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2849 | if (state && !(state->state & FMODE_WRITE)) { |
| 2850 | err = -EBADF; |
| 2851 | if (sattr->ia_valid & ATTR_OPEN) |
| 2852 | err = -EACCES; |
| 2853 | goto out; |
| 2854 | } |
| 2855 | } |
| 2856 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2858 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | return err; |
| 2860 | } |
| 2861 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2862 | static bool |
| 2863 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2864 | { |
| 2865 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2866 | return false; |
| 2867 | |
| 2868 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2869 | } |
| 2870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | struct nfs4_closedata { |
| 2872 | struct inode *inode; |
| 2873 | struct nfs4_state *state; |
| 2874 | struct nfs_closeargs arg; |
| 2875 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2876 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2877 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2878 | bool roc; |
| 2879 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | }; |
| 2881 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2882 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2883 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2884 | struct nfs4_closedata *calldata = data; |
| 2885 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2886 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2887 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2888 | if (calldata->roc) |
| 2889 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2890 | nfs4_put_open_state(calldata->state); |
| 2891 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2892 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2893 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2894 | kfree(calldata); |
| 2895 | } |
| 2896 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2897 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2899 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2902 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2904 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2905 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2906 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2907 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | /* hmm. we are done with the inode, and in the process of freeing |
| 2909 | * the state_owner. we keep this around to process errors |
| 2910 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | switch (task->tk_status) { |
| 2912 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2913 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2914 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2915 | pnfs_roc_set_barrier(state->inode, |
| 2916 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2917 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2918 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2919 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2921 | case -NFS4ERR_OLD_STATEID: |
| 2922 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2924 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2925 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2926 | rpc_restart_call_prepare(task); |
| 2927 | goto out_release; |
| 2928 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2929 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2930 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2932 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2933 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2934 | goto out_release; |
| 2935 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2937 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2938 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2939 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2940 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2941 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2942 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2945 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2947 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2948 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2949 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2950 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2951 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2952 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2953 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2954 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2955 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2956 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2957 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2958 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2959 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2960 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2961 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2962 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2963 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2964 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2965 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2966 | if (state->n_rdonly == 0) |
| 2967 | call_close |= is_rdonly; |
| 2968 | else if (is_rdonly) |
| 2969 | calldata->arg.fmode |= FMODE_READ; |
| 2970 | if (state->n_wronly == 0) |
| 2971 | call_close |= is_wronly; |
| 2972 | else if (is_wronly) |
| 2973 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2974 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2975 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2976 | } else if (is_rdwr) |
| 2977 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2978 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2979 | if (!nfs4_valid_open_stateid(state)) |
| 2980 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2981 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2982 | |
| 2983 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2984 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2985 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2986 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2987 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2988 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2989 | nfs_release_seqid(calldata->arg.seqid); |
| 2990 | goto out_wait; |
| 2991 | } |
| 2992 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2993 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2994 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2995 | if (calldata->roc) |
| 2996 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2997 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2998 | calldata->arg.share_access = |
| 2999 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3000 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3001 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3002 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3003 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3004 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3005 | &calldata->arg.seq_args, |
| 3006 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3007 | task) != 0) |
| 3008 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3009 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3010 | return; |
| 3011 | out_no_action: |
| 3012 | task->tk_action = NULL; |
| 3013 | out_wait: |
| 3014 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3017 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3018 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3019 | .rpc_call_done = nfs4_close_done, |
| 3020 | .rpc_release = nfs4_free_closedata, |
| 3021 | }; |
| 3022 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3023 | static bool nfs4_roc(struct inode *inode) |
| 3024 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3025 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3026 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3027 | return pnfs_roc(inode); |
| 3028 | } |
| 3029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | /* |
| 3031 | * It is possible for data to be read/written from a mem-mapped file |
| 3032 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3033 | * This means that we can't safely call nfsv4 close on a file until |
| 3034 | * the inode is cleared. This in turn means that we are not good |
| 3035 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3036 | * share state even when we are done with one of the three share |
| 3037 | * stateid's in the inode. |
| 3038 | * |
| 3039 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3040 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3041 | 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] | 3042 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3043 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3044 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3046 | struct nfs4_state_owner *sp = state->owner; |
| 3047 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3048 | struct rpc_message msg = { |
| 3049 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3050 | .rpc_cred = state->owner->so_cred, |
| 3051 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3052 | struct rpc_task_setup task_setup_data = { |
| 3053 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3054 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3055 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3056 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3057 | .flags = RPC_TASK_ASYNC, |
| 3058 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3059 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3061 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3062 | &task_setup_data.rpc_client, &msg); |
| 3063 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3064 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3066 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3067 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3068 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3070 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3072 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3073 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3074 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3075 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3076 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3077 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3078 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3079 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3080 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3081 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3082 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3083 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3084 | msg.rpc_argp = &calldata->arg; |
| 3085 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3086 | task_setup_data.callback_data = calldata; |
| 3087 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3088 | if (IS_ERR(task)) |
| 3089 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3090 | status = 0; |
| 3091 | if (wait) |
| 3092 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3093 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3094 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3095 | out_free_calldata: |
| 3096 | kfree(calldata); |
| 3097 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3098 | nfs4_put_open_state(state); |
| 3099 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3100 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3103 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3104 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3105 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3108 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3109 | |
| 3110 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3112 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3113 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3114 | |
| 3115 | nfs4_label_release_security(label); |
| 3116 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3117 | if (IS_ERR(state)) |
| 3118 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3119 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3122 | 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] | 3123 | { |
| 3124 | if (ctx->state == NULL) |
| 3125 | return; |
| 3126 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3127 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3128 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3129 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3132 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3133 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3134 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3137 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3138 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3139 | struct nfs4_server_caps_arg args = { |
| 3140 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3141 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3142 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | struct nfs4_server_caps_res res = {}; |
| 3144 | struct rpc_message msg = { |
| 3145 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3146 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | .rpc_resp = &res, |
| 3148 | }; |
| 3149 | int status; |
| 3150 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3151 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3152 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3153 | FATTR4_WORD0_LINK_SUPPORT | |
| 3154 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3155 | FATTR4_WORD0_ACLSUPPORT; |
| 3156 | if (minorversion) |
| 3157 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3158 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3159 | 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] | 3160 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3161 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3162 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3163 | case 0: |
| 3164 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3165 | res.attr_bitmask[2] = 0; |
| 3166 | break; |
| 3167 | case 1: |
| 3168 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3169 | break; |
| 3170 | case 2: |
| 3171 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3174 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3175 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3176 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3177 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3178 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3179 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3180 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3181 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | server->caps |= NFS_CAP_ACLS; |
| 3183 | if (res.has_links != 0) |
| 3184 | server->caps |= NFS_CAP_HARDLINKS; |
| 3185 | if (res.has_symlinks != 0) |
| 3186 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3187 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3188 | server->caps |= NFS_CAP_FILEID; |
| 3189 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3190 | server->caps |= NFS_CAP_MODE; |
| 3191 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3192 | server->caps |= NFS_CAP_NLINK; |
| 3193 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3194 | server->caps |= NFS_CAP_OWNER; |
| 3195 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3196 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3197 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3198 | server->caps |= NFS_CAP_ATIME; |
| 3199 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3200 | server->caps |= NFS_CAP_CTIME; |
| 3201 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3202 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3203 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3204 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3205 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3206 | #endif |
| 3207 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3208 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3209 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3210 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3211 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3212 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3213 | 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] | 3214 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3215 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3216 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3218 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | return status; |
| 3222 | } |
| 3223 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3224 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | { |
| 3226 | struct nfs4_exception exception = { }; |
| 3227 | int err; |
| 3228 | do { |
| 3229 | err = nfs4_handle_exception(server, |
| 3230 | _nfs4_server_capabilities(server, fhandle), |
| 3231 | &exception); |
| 3232 | } while (exception.retry); |
| 3233 | return err; |
| 3234 | } |
| 3235 | |
| 3236 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3237 | struct nfs_fsinfo *info) |
| 3238 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3239 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3241 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | }; |
| 3243 | struct nfs4_lookup_res res = { |
| 3244 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3245 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | .fh = fhandle, |
| 3247 | }; |
| 3248 | struct rpc_message msg = { |
| 3249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3250 | .rpc_argp = &args, |
| 3251 | .rpc_resp = &res, |
| 3252 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3253 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3254 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3255 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3256 | /* |
| 3257 | * Process the label in the upcoming getfattr |
| 3258 | */ |
| 3259 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3260 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3261 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3262 | 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] | 3263 | } |
| 3264 | |
| 3265 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3266 | struct nfs_fsinfo *info) |
| 3267 | { |
| 3268 | struct nfs4_exception exception = { }; |
| 3269 | int err; |
| 3270 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3271 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3272 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3273 | switch (err) { |
| 3274 | case 0: |
| 3275 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3276 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3277 | default: |
| 3278 | err = nfs4_handle_exception(server, err, &exception); |
| 3279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3281 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | return err; |
| 3283 | } |
| 3284 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3285 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3286 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3287 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3288 | struct rpc_auth_create_args auth_args = { |
| 3289 | .pseudoflavor = flavor, |
| 3290 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3291 | struct rpc_auth *auth; |
| 3292 | int ret; |
| 3293 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3294 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3295 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3296 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3297 | goto out; |
| 3298 | } |
| 3299 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3300 | out: |
| 3301 | return ret; |
| 3302 | } |
| 3303 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3304 | /* |
| 3305 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3306 | * |
| 3307 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3308 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3309 | * |
| 3310 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3311 | * negative errno value. |
| 3312 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3313 | 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] | 3314 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3316 | /* Per 3530bis 15.33.5 */ |
| 3317 | static const rpc_authflavor_t flav_array[] = { |
| 3318 | RPC_AUTH_GSS_KRB5P, |
| 3319 | RPC_AUTH_GSS_KRB5I, |
| 3320 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3321 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3322 | RPC_AUTH_NULL, |
| 3323 | }; |
| 3324 | int status = -EPERM; |
| 3325 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3327 | if (server->auth_info.flavor_len > 0) { |
| 3328 | /* try each flavor specified by user */ |
| 3329 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3330 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3331 | server->auth_info.flavors[i]); |
| 3332 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3333 | continue; |
| 3334 | break; |
| 3335 | } |
| 3336 | } else { |
| 3337 | /* no flavors specified by user, try default list */ |
| 3338 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3339 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3340 | flav_array[i]); |
| 3341 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3342 | continue; |
| 3343 | break; |
| 3344 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3345 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3346 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3347 | /* |
| 3348 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3349 | * to access the mount. It could also mean that we tried to mount |
| 3350 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3351 | * existing mount programs don't handle -EACCES very well so it should |
| 3352 | * be mapped to -EPERM instead. |
| 3353 | */ |
| 3354 | if (status == -EACCES) |
| 3355 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3356 | return status; |
| 3357 | } |
| 3358 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3359 | /** |
| 3360 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3361 | * @server: initialized nfs_server handle |
| 3362 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3363 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3364 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3365 | * |
| 3366 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3367 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3368 | 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] | 3369 | struct nfs_fsinfo *info, |
| 3370 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3371 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3372 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3373 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3374 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3375 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3376 | |
| 3377 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3378 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3379 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | if (status == 0) |
| 3382 | status = nfs4_server_capabilities(server, fhandle); |
| 3383 | if (status == 0) |
| 3384 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3385 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3386 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3389 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3390 | struct nfs_fsinfo *info) |
| 3391 | { |
| 3392 | int error; |
| 3393 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3394 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3395 | |
| 3396 | error = nfs4_server_capabilities(server, mntfh); |
| 3397 | if (error < 0) { |
| 3398 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3399 | return error; |
| 3400 | } |
| 3401 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3402 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3403 | if (IS_ERR(label)) |
| 3404 | return PTR_ERR(label); |
| 3405 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3406 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3407 | if (error < 0) { |
| 3408 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3409 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3413 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3414 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3415 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3416 | err_free_label: |
| 3417 | nfs4_label_free(label); |
| 3418 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3419 | return error; |
| 3420 | } |
| 3421 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3422 | /* |
| 3423 | * Get locations and (maybe) other attributes of a referral. |
| 3424 | * Note that we'll actually follow the referral later when |
| 3425 | * we detect fsid mismatch in inode revalidation |
| 3426 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3427 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3428 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3429 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3430 | { |
| 3431 | int status = -ENOMEM; |
| 3432 | struct page *page = NULL; |
| 3433 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3434 | |
| 3435 | page = alloc_page(GFP_KERNEL); |
| 3436 | if (page == NULL) |
| 3437 | goto out; |
| 3438 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3439 | if (locations == NULL) |
| 3440 | goto out; |
| 3441 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3442 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3443 | if (status != 0) |
| 3444 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3445 | |
| 3446 | /* |
| 3447 | * If the fsid didn't change, this is a migration event, not a |
| 3448 | * referral. Cause us to drop into the exception handler, which |
| 3449 | * will kick off migration recovery. |
| 3450 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3451 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3452 | dprintk("%s: server did not return a different fsid for" |
| 3453 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3454 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3455 | goto out; |
| 3456 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3457 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3458 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3459 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3460 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3461 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3462 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3463 | out: |
| 3464 | if (page) |
| 3465 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3466 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3467 | return status; |
| 3468 | } |
| 3469 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3470 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3471 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | { |
| 3473 | struct nfs4_getattr_arg args = { |
| 3474 | .fh = fhandle, |
| 3475 | .bitmask = server->attr_bitmask, |
| 3476 | }; |
| 3477 | struct nfs4_getattr_res res = { |
| 3478 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3479 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | .server = server, |
| 3481 | }; |
| 3482 | struct rpc_message msg = { |
| 3483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3484 | .rpc_argp = &args, |
| 3485 | .rpc_resp = &res, |
| 3486 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3487 | |
| 3488 | args.bitmask = nfs4_bitmask(server, label); |
| 3489 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3490 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3491 | 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] | 3492 | } |
| 3493 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3494 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3495 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | { |
| 3497 | struct nfs4_exception exception = { }; |
| 3498 | int err; |
| 3499 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3500 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3501 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3502 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | &exception); |
| 3504 | } while (exception.retry); |
| 3505 | return err; |
| 3506 | } |
| 3507 | |
| 3508 | /* |
| 3509 | * The file is not closed if it is opened due to the a request to change |
| 3510 | * the size of the file. The open call will not be needed once the |
| 3511 | * VFS layer lookup-intents are implemented. |
| 3512 | * |
| 3513 | * Close is called when the inode is destroyed. |
| 3514 | * If we haven't opened the file for O_WRONLY, we |
| 3515 | * need to in the size_change case to obtain a stateid. |
| 3516 | * |
| 3517 | * Got race? |
| 3518 | * Because OPEN is always done by name in nfsv4, it is |
| 3519 | * possible that we opened a different file by the same |
| 3520 | * name. We can recognize this race condition, but we |
| 3521 | * can't do anything about it besides returning an error. |
| 3522 | * |
| 3523 | * This will be fixed with VFS changes (lookup-intent). |
| 3524 | */ |
| 3525 | static int |
| 3526 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3527 | struct iattr *sattr) |
| 3528 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3529 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3530 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3531 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3532 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | int status; |
| 3534 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3535 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3536 | sattr->ia_valid & ATTR_SIZE && |
| 3537 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3538 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3539 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3540 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3542 | /* Deal with open(O_TRUNC) */ |
| 3543 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3544 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3545 | |
| 3546 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3547 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3548 | return 0; |
| 3549 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3550 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3551 | if (sattr->ia_valid & ATTR_FILE) { |
| 3552 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3553 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3554 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3555 | if (ctx) { |
| 3556 | cred = ctx->cred; |
| 3557 | state = ctx->state; |
| 3558 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3559 | } |
| 3560 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3561 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3562 | if (IS_ERR(label)) |
| 3563 | return PTR_ERR(label); |
| 3564 | |
| 3565 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3566 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3567 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3568 | nfs_setsecurity(inode, fattr, label); |
| 3569 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3570 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | return status; |
| 3572 | } |
| 3573 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3574 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3575 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3576 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3577 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3578 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3579 | int status; |
| 3580 | struct nfs4_lookup_arg args = { |
| 3581 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3582 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3583 | .name = name, |
| 3584 | }; |
| 3585 | struct nfs4_lookup_res res = { |
| 3586 | .server = server, |
| 3587 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3588 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3589 | .fh = fhandle, |
| 3590 | }; |
| 3591 | struct rpc_message msg = { |
| 3592 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3593 | .rpc_argp = &args, |
| 3594 | .rpc_resp = &res, |
| 3595 | }; |
| 3596 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3597 | args.bitmask = nfs4_bitmask(server, label); |
| 3598 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3599 | nfs_fattr_init(fattr); |
| 3600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3602 | 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] | 3603 | dprintk("NFS reply lookup: %d\n", status); |
| 3604 | return status; |
| 3605 | } |
| 3606 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3607 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3608 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3609 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3610 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3611 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3612 | fattr->nlink = 2; |
| 3613 | } |
| 3614 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3615 | 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] | 3616 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3617 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3618 | { |
| 3619 | struct nfs4_exception exception = { }; |
| 3620 | struct rpc_clnt *client = *clnt; |
| 3621 | int err; |
| 3622 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3623 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3624 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3625 | switch (err) { |
| 3626 | case -NFS4ERR_BADNAME: |
| 3627 | err = -ENOENT; |
| 3628 | goto out; |
| 3629 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3630 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3631 | if (err == -NFS4ERR_MOVED) |
| 3632 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3633 | goto out; |
| 3634 | case -NFS4ERR_WRONGSEC: |
| 3635 | err = -EPERM; |
| 3636 | if (client != *clnt) |
| 3637 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3638 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3639 | if (IS_ERR(client)) |
| 3640 | return PTR_ERR(client); |
| 3641 | |
| 3642 | exception.retry = 1; |
| 3643 | break; |
| 3644 | default: |
| 3645 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3646 | } |
| 3647 | } while (exception.retry); |
| 3648 | |
| 3649 | out: |
| 3650 | if (err == 0) |
| 3651 | *clnt = client; |
| 3652 | else if (client != *clnt) |
| 3653 | rpc_shutdown_client(client); |
| 3654 | |
| 3655 | return err; |
| 3656 | } |
| 3657 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3658 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3659 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3660 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3662 | int status; |
| 3663 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3664 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3665 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3666 | if (client != NFS_CLIENT(dir)) { |
| 3667 | rpc_shutdown_client(client); |
| 3668 | nfs_fixup_secinfo_attributes(fattr); |
| 3669 | } |
| 3670 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3673 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3674 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3675 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3676 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3677 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3678 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3679 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3680 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3681 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3682 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3683 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3687 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3688 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | struct nfs4_accessargs args = { |
| 3690 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3691 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3693 | struct nfs4_accessres res = { |
| 3694 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3695 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | struct rpc_message msg = { |
| 3697 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3698 | .rpc_argp = &args, |
| 3699 | .rpc_resp = &res, |
| 3700 | .rpc_cred = entry->cred, |
| 3701 | }; |
| 3702 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3703 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | |
| 3705 | /* |
| 3706 | * Determine which access bits we want to ask for... |
| 3707 | */ |
| 3708 | if (mode & MAY_READ) |
| 3709 | args.access |= NFS4_ACCESS_READ; |
| 3710 | if (S_ISDIR(inode->i_mode)) { |
| 3711 | if (mode & MAY_WRITE) |
| 3712 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3713 | if (mode & MAY_EXEC) |
| 3714 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3715 | } else { |
| 3716 | if (mode & MAY_WRITE) |
| 3717 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3718 | if (mode & MAY_EXEC) |
| 3719 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3720 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3721 | |
| 3722 | res.fattr = nfs_alloc_fattr(); |
| 3723 | if (res.fattr == NULL) |
| 3724 | return -ENOMEM; |
| 3725 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3726 | 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] | 3727 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3728 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3729 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3731 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | return status; |
| 3733 | } |
| 3734 | |
| 3735 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3736 | { |
| 3737 | struct nfs4_exception exception = { }; |
| 3738 | int err; |
| 3739 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3740 | err = _nfs4_proc_access(inode, entry); |
| 3741 | trace_nfs4_access(inode, err); |
| 3742 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | &exception); |
| 3744 | } while (exception.retry); |
| 3745 | return err; |
| 3746 | } |
| 3747 | |
| 3748 | /* |
| 3749 | * TODO: For the time being, we don't try to get any attributes |
| 3750 | * along with any of the zero-copy operations READ, READDIR, |
| 3751 | * READLINK, WRITE. |
| 3752 | * |
| 3753 | * In the case of the first three, we want to put the GETATTR |
| 3754 | * after the read-type operation -- this is because it is hard |
| 3755 | * to predict the length of a GETATTR response in v4, and thus |
| 3756 | * align the READ data correctly. This means that the GETATTR |
| 3757 | * may end up partially falling into the page cache, and we should |
| 3758 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3759 | * To do this efficiently, we need to know the total length |
| 3760 | * of data received, which doesn't seem to be available outside |
| 3761 | * of the RPC layer. |
| 3762 | * |
| 3763 | * In the case of WRITE, we also want to put the GETATTR after |
| 3764 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3765 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | * |
| 3767 | * Both of these changes to the XDR layer would in fact be quite |
| 3768 | * minor, but I decided to leave them for a subsequent patch. |
| 3769 | */ |
| 3770 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3771 | unsigned int pgbase, unsigned int pglen) |
| 3772 | { |
| 3773 | struct nfs4_readlink args = { |
| 3774 | .fh = NFS_FH(inode), |
| 3775 | .pgbase = pgbase, |
| 3776 | .pglen = pglen, |
| 3777 | .pages = &page, |
| 3778 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3779 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | struct rpc_message msg = { |
| 3781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3782 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3783 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | }; |
| 3785 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3786 | 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] | 3787 | } |
| 3788 | |
| 3789 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3790 | unsigned int pgbase, unsigned int pglen) |
| 3791 | { |
| 3792 | struct nfs4_exception exception = { }; |
| 3793 | int err; |
| 3794 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3795 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3796 | trace_nfs4_readlink(inode, err); |
| 3797 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | &exception); |
| 3799 | } while (exception.retry); |
| 3800 | return err; |
| 3801 | } |
| 3802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3804 | * 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] | 3805 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | static int |
| 3807 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3808 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3810 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3811 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | int status = 0; |
| 3814 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3815 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3816 | if (IS_ERR(ctx)) |
| 3817 | return PTR_ERR(ctx); |
| 3818 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3819 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3820 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3821 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3822 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | if (IS_ERR(state)) { |
| 3824 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3825 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3828 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3829 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | return status; |
| 3831 | } |
| 3832 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3833 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3835 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3836 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3838 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3840 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3841 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3842 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3844 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3845 | .rpc_argp = &args, |
| 3846 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3848 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3849 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3850 | 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] | 3851 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3852 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | return status; |
| 3854 | } |
| 3855 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3856 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | { |
| 3858 | struct nfs4_exception exception = { }; |
| 3859 | int err; |
| 3860 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3861 | err = _nfs4_proc_remove(dir, name); |
| 3862 | trace_nfs4_remove(dir, name, err); |
| 3863 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | &exception); |
| 3865 | } while (exception.retry); |
| 3866 | return err; |
| 3867 | } |
| 3868 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3869 | 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] | 3870 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3871 | struct nfs_server *server = NFS_SERVER(dir); |
| 3872 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3873 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3875 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3877 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3878 | |
| 3879 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | } |
| 3881 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3882 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3883 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3884 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3885 | &data->args.seq_args, |
| 3886 | &data->res.seq_res, |
| 3887 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3890 | 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] | 3891 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3892 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3893 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3894 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3895 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3896 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3897 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3898 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3899 | return 0; |
| 3900 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3901 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3904 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3905 | { |
| 3906 | struct nfs_server *server = NFS_SERVER(dir); |
| 3907 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3908 | struct nfs_renameres *res = msg->rpc_resp; |
| 3909 | |
| 3910 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3911 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3912 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3913 | } |
| 3914 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3915 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3916 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3917 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3918 | &data->args.seq_args, |
| 3919 | &data->res.seq_res, |
| 3920 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3924 | struct inode *new_dir) |
| 3925 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3926 | struct nfs_renamedata *data = task->tk_calldata; |
| 3927 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3928 | |
| 3929 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3930 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3931 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3932 | return 0; |
| 3933 | |
| 3934 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3935 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3936 | return 1; |
| 3937 | } |
| 3938 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3939 | 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] | 3940 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3941 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | struct nfs4_link_arg arg = { |
| 3943 | .fh = NFS_FH(inode), |
| 3944 | .dir_fh = NFS_FH(dir), |
| 3945 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3946 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3948 | struct nfs4_link_res res = { |
| 3949 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3950 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3951 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | struct rpc_message msg = { |
| 3953 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3954 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3955 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3957 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3959 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3960 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3961 | goto out; |
| 3962 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3963 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3964 | if (IS_ERR(res.label)) { |
| 3965 | status = PTR_ERR(res.label); |
| 3966 | goto out; |
| 3967 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3968 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3969 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3970 | 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] | 3971 | if (!status) { |
| 3972 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3973 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3974 | if (!status) |
| 3975 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3976 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3977 | |
| 3978 | |
| 3979 | nfs4_label_free(res.label); |
| 3980 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3981 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3982 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | return status; |
| 3984 | } |
| 3985 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3986 | 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] | 3987 | { |
| 3988 | struct nfs4_exception exception = { }; |
| 3989 | int err; |
| 3990 | do { |
| 3991 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3992 | _nfs4_proc_link(inode, dir, name), |
| 3993 | &exception); |
| 3994 | } while (exception.retry); |
| 3995 | return err; |
| 3996 | } |
| 3997 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3998 | struct nfs4_createdata { |
| 3999 | struct rpc_message msg; |
| 4000 | struct nfs4_create_arg arg; |
| 4001 | struct nfs4_create_res res; |
| 4002 | struct nfs_fh fh; |
| 4003 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4004 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4005 | }; |
| 4006 | |
| 4007 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4008 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4009 | { |
| 4010 | struct nfs4_createdata *data; |
| 4011 | |
| 4012 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4013 | if (data != NULL) { |
| 4014 | struct nfs_server *server = NFS_SERVER(dir); |
| 4015 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4016 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4017 | if (IS_ERR(data->label)) |
| 4018 | goto out_free; |
| 4019 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4020 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4021 | data->msg.rpc_argp = &data->arg; |
| 4022 | data->msg.rpc_resp = &data->res; |
| 4023 | data->arg.dir_fh = NFS_FH(dir); |
| 4024 | data->arg.server = server; |
| 4025 | data->arg.name = name; |
| 4026 | data->arg.attrs = sattr; |
| 4027 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4028 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4029 | data->res.server = server; |
| 4030 | data->res.fh = &data->fh; |
| 4031 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4032 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4033 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4034 | } |
| 4035 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4036 | out_free: |
| 4037 | kfree(data); |
| 4038 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4042 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4043 | 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] | 4044 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4045 | if (status == 0) { |
| 4046 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4047 | 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] | 4048 | } |
| 4049 | return status; |
| 4050 | } |
| 4051 | |
| 4052 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4053 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4054 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4055 | kfree(data); |
| 4056 | } |
| 4057 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4058 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4059 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4060 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4062 | struct nfs4_createdata *data; |
| 4063 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4065 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4066 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4067 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4068 | status = -ENOMEM; |
| 4069 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4070 | if (data == NULL) |
| 4071 | goto out; |
| 4072 | |
| 4073 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4074 | data->arg.u.symlink.pages = &page; |
| 4075 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4076 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4078 | status = nfs4_do_create(dir, dentry, data); |
| 4079 | |
| 4080 | nfs4_free_createdata(data); |
| 4081 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | return status; |
| 4083 | } |
| 4084 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4085 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4086 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | { |
| 4088 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4089 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4091 | |
| 4092 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4095 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4096 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4097 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | &exception); |
| 4099 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4100 | |
| 4101 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | return err; |
| 4103 | } |
| 4104 | |
| 4105 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4106 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4108 | struct nfs4_createdata *data; |
| 4109 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4111 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4112 | if (data == NULL) |
| 4113 | goto out; |
| 4114 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4115 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4116 | status = nfs4_do_create(dir, dentry, data); |
| 4117 | |
| 4118 | nfs4_free_createdata(data); |
| 4119 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | return status; |
| 4121 | } |
| 4122 | |
| 4123 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4124 | struct iattr *sattr) |
| 4125 | { |
| 4126 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4127 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4129 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4130 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4131 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4132 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4134 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4135 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4136 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | &exception); |
| 4138 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4139 | nfs4_label_release_security(label); |
| 4140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | return err; |
| 4142 | } |
| 4143 | |
| 4144 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4145 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4147 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | struct nfs4_readdir_arg args = { |
| 4149 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4150 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | .pgbase = 0, |
| 4152 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4153 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4154 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | }; |
| 4156 | struct nfs4_readdir_res res; |
| 4157 | struct rpc_message msg = { |
| 4158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4159 | .rpc_argp = &args, |
| 4160 | .rpc_resp = &res, |
| 4161 | .rpc_cred = cred, |
| 4162 | }; |
| 4163 | int status; |
| 4164 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4165 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4166 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4167 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4168 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4170 | 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] | 4171 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4172 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4173 | status += args.pgbase; |
| 4174 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4175 | |
| 4176 | nfs_invalidate_atime(dir); |
| 4177 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4178 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | return status; |
| 4180 | } |
| 4181 | |
| 4182 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4183 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | { |
| 4185 | struct nfs4_exception exception = { }; |
| 4186 | int err; |
| 4187 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4188 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4189 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4190 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4191 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | &exception); |
| 4193 | } while (exception.retry); |
| 4194 | return err; |
| 4195 | } |
| 4196 | |
| 4197 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4198 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4200 | struct nfs4_createdata *data; |
| 4201 | int mode = sattr->ia_mode; |
| 4202 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4204 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4205 | if (data == NULL) |
| 4206 | goto out; |
| 4207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4209 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | data->arg.ftype = NF4BLK; |
| 4212 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4213 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | } |
| 4215 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4216 | data->arg.ftype = NF4CHR; |
| 4217 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4218 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4219 | } else if (!S_ISSOCK(mode)) { |
| 4220 | status = -EINVAL; |
| 4221 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4223 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4224 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4225 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4226 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4227 | nfs4_free_createdata(data); |
| 4228 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | return status; |
| 4230 | } |
| 4231 | |
| 4232 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4233 | struct iattr *sattr, dev_t rdev) |
| 4234 | { |
| 4235 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4236 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4238 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4239 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4240 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4241 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4243 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4244 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4245 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | &exception); |
| 4247 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4248 | |
| 4249 | nfs4_label_release_security(label); |
| 4250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | return err; |
| 4252 | } |
| 4253 | |
| 4254 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4255 | struct nfs_fsstat *fsstat) |
| 4256 | { |
| 4257 | struct nfs4_statfs_arg args = { |
| 4258 | .fh = fhandle, |
| 4259 | .bitmask = server->attr_bitmask, |
| 4260 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4261 | struct nfs4_statfs_res res = { |
| 4262 | .fsstat = fsstat, |
| 4263 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | struct rpc_message msg = { |
| 4265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4266 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4267 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | }; |
| 4269 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4270 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4271 | 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] | 4272 | } |
| 4273 | |
| 4274 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4275 | { |
| 4276 | struct nfs4_exception exception = { }; |
| 4277 | int err; |
| 4278 | do { |
| 4279 | err = nfs4_handle_exception(server, |
| 4280 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4281 | &exception); |
| 4282 | } while (exception.retry); |
| 4283 | return err; |
| 4284 | } |
| 4285 | |
| 4286 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4287 | struct nfs_fsinfo *fsinfo) |
| 4288 | { |
| 4289 | struct nfs4_fsinfo_arg args = { |
| 4290 | .fh = fhandle, |
| 4291 | .bitmask = server->attr_bitmask, |
| 4292 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4293 | struct nfs4_fsinfo_res res = { |
| 4294 | .fsinfo = fsinfo, |
| 4295 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | struct rpc_message msg = { |
| 4297 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4298 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4299 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | }; |
| 4301 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4302 | 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] | 4303 | } |
| 4304 | |
| 4305 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4306 | { |
| 4307 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4308 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | int err; |
| 4310 | |
| 4311 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4312 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4313 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4314 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4315 | nfs4_set_lease_period(server->nfs_client, |
| 4316 | fsinfo->lease_time * HZ, |
| 4317 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4318 | break; |
| 4319 | } |
| 4320 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | } while (exception.retry); |
| 4322 | return err; |
| 4323 | } |
| 4324 | |
| 4325 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4326 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4327 | int error; |
| 4328 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4329 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4330 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4331 | if (error == 0) { |
| 4332 | /* block layout checks this! */ |
| 4333 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4334 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4335 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4336 | |
| 4337 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4341 | struct nfs_pathconf *pathconf) |
| 4342 | { |
| 4343 | struct nfs4_pathconf_arg args = { |
| 4344 | .fh = fhandle, |
| 4345 | .bitmask = server->attr_bitmask, |
| 4346 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4347 | struct nfs4_pathconf_res res = { |
| 4348 | .pathconf = pathconf, |
| 4349 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | struct rpc_message msg = { |
| 4351 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4352 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4353 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | }; |
| 4355 | |
| 4356 | /* None of the pathconf attributes are mandatory to implement */ |
| 4357 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4358 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4359 | return 0; |
| 4360 | } |
| 4361 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4362 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4363 | 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] | 4364 | } |
| 4365 | |
| 4366 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4367 | struct nfs_pathconf *pathconf) |
| 4368 | { |
| 4369 | struct nfs4_exception exception = { }; |
| 4370 | int err; |
| 4371 | |
| 4372 | do { |
| 4373 | err = nfs4_handle_exception(server, |
| 4374 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4375 | &exception); |
| 4376 | } while (exception.retry); |
| 4377 | return err; |
| 4378 | } |
| 4379 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4380 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4381 | const struct nfs_open_context *ctx, |
| 4382 | const struct nfs_lock_context *l_ctx, |
| 4383 | fmode_t fmode) |
| 4384 | { |
| 4385 | const struct nfs_lockowner *lockowner = NULL; |
| 4386 | |
| 4387 | if (l_ctx != NULL) |
| 4388 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4389 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4390 | } |
| 4391 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4392 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4393 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4394 | const struct nfs_open_context *ctx, |
| 4395 | const struct nfs_lock_context *l_ctx, |
| 4396 | fmode_t fmode) |
| 4397 | { |
| 4398 | nfs4_stateid current_stateid; |
| 4399 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4400 | /* If the current stateid represents a lost lock, then exit */ |
| 4401 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4402 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4403 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4404 | } |
| 4405 | |
| 4406 | static bool nfs4_error_stateid_expired(int err) |
| 4407 | { |
| 4408 | switch (err) { |
| 4409 | case -NFS4ERR_DELEG_REVOKED: |
| 4410 | case -NFS4ERR_ADMIN_REVOKED: |
| 4411 | case -NFS4ERR_BAD_STATEID: |
| 4412 | case -NFS4ERR_STALE_STATEID: |
| 4413 | case -NFS4ERR_OLD_STATEID: |
| 4414 | case -NFS4ERR_OPENMODE: |
| 4415 | case -NFS4ERR_EXPIRED: |
| 4416 | return true; |
| 4417 | } |
| 4418 | return false; |
| 4419 | } |
| 4420 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4421 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4422 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4423 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4424 | } |
| 4425 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4426 | 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] | 4427 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4428 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4430 | trace_nfs4_read(hdr, task->tk_status); |
| 4431 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4432 | hdr->args.context->state, |
| 4433 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4434 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4435 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4437 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4438 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4440 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4441 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4444 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4445 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4446 | { |
| 4447 | |
| 4448 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4449 | nfs4_stateid_is_current(&args->stateid, |
| 4450 | args->context, |
| 4451 | args->lock_context, |
| 4452 | FMODE_READ)) |
| 4453 | return false; |
| 4454 | rpc_restart_call_prepare(task); |
| 4455 | return true; |
| 4456 | } |
| 4457 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4458 | 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] | 4459 | { |
| 4460 | |
| 4461 | dprintk("--> %s\n", __func__); |
| 4462 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4463 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4464 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4465 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4466 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4467 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4468 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4469 | } |
| 4470 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4471 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4472 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4474 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4475 | if (!hdr->pgio_done_cb) |
| 4476 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4477 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4478 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4481 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4482 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4483 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4484 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4485 | &hdr->args.seq_args, |
| 4486 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4487 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4488 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4489 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4490 | hdr->args.lock_context, |
| 4491 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4492 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4493 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4494 | return -EIO; |
| 4495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4498 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4499 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4501 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4502 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4503 | trace_nfs4_write(hdr, task->tk_status); |
| 4504 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4505 | hdr->args.context->state, |
| 4506 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4507 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4508 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4510 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4511 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4512 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4513 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4514 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | } |
| 4516 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4517 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4518 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4519 | { |
| 4520 | |
| 4521 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4522 | nfs4_stateid_is_current(&args->stateid, |
| 4523 | args->context, |
| 4524 | args->lock_context, |
| 4525 | FMODE_WRITE)) |
| 4526 | return false; |
| 4527 | rpc_restart_call_prepare(task); |
| 4528 | return true; |
| 4529 | } |
| 4530 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4531 | 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] | 4532 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4533 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4534 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4535 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4536 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4537 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4538 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4541 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4542 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4543 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4544 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4545 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4546 | return false; |
| 4547 | /* Otherwise, request attributes if and only if we don't hold |
| 4548 | * a delegation |
| 4549 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4550 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4551 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4552 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4553 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4554 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4556 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4557 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4558 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4559 | hdr->args.bitmask = NULL; |
| 4560 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4561 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4562 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4563 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4564 | if (!hdr->pgio_done_cb) |
| 4565 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4566 | hdr->res.server = server; |
| 4567 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4569 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4570 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | } |
| 4572 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4573 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4574 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4575 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4576 | &data->args.seq_args, |
| 4577 | &data->res.seq_res, |
| 4578 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4581 | 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] | 4582 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4584 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4585 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4586 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4587 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4588 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4589 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4591 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4594 | 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] | 4595 | { |
| 4596 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4597 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4598 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4601 | 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] | 4602 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4603 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4604 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4605 | if (data->commit_done_cb == NULL) |
| 4606 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4607 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4608 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4609 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4612 | struct nfs4_renewdata { |
| 4613 | struct nfs_client *client; |
| 4614 | unsigned long timestamp; |
| 4615 | }; |
| 4616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | /* |
| 4618 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4619 | * standalone procedure for queueing an asynchronous RENEW. |
| 4620 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4621 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4622 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4623 | struct nfs4_renewdata *data = calldata; |
| 4624 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4625 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4626 | if (atomic_read(&clp->cl_count) > 1) |
| 4627 | nfs4_schedule_state_renewal(clp); |
| 4628 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4629 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4630 | } |
| 4631 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4632 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4634 | struct nfs4_renewdata *data = calldata; |
| 4635 | struct nfs_client *clp = data->client; |
| 4636 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4638 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4639 | switch (task->tk_status) { |
| 4640 | case 0: |
| 4641 | break; |
| 4642 | case -NFS4ERR_LEASE_MOVED: |
| 4643 | nfs4_schedule_lease_moved_recovery(clp); |
| 4644 | break; |
| 4645 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4646 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4647 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4648 | return; |
| 4649 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4650 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4651 | return; |
| 4652 | } |
| 4653 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4655 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4658 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4659 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4660 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4661 | }; |
| 4662 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4663 | 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] | 4664 | { |
| 4665 | struct rpc_message msg = { |
| 4666 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4667 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4668 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4670 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4672 | if (renew_flags == 0) |
| 4673 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4674 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4675 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4676 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4677 | if (data == NULL) |
| 4678 | return -ENOMEM; |
| 4679 | data->client = clp; |
| 4680 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4681 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4682 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4685 | 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] | 4686 | { |
| 4687 | struct rpc_message msg = { |
| 4688 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4689 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4690 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | }; |
| 4692 | unsigned long now = jiffies; |
| 4693 | int status; |
| 4694 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4695 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | if (status < 0) |
| 4697 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4698 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | return 0; |
| 4700 | } |
| 4701 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4702 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4703 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4704 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4707 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4708 | * 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] | 4709 | * the stack. |
| 4710 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4711 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4712 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4713 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4714 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4715 | { |
| 4716 | struct page *newpage, **spages; |
| 4717 | int rc = 0; |
| 4718 | size_t len; |
| 4719 | spages = pages; |
| 4720 | |
| 4721 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4722 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4723 | newpage = alloc_page(GFP_KERNEL); |
| 4724 | |
| 4725 | if (newpage == NULL) |
| 4726 | goto unwind; |
| 4727 | memcpy(page_address(newpage), buf, len); |
| 4728 | buf += len; |
| 4729 | buflen -= len; |
| 4730 | *pages++ = newpage; |
| 4731 | rc++; |
| 4732 | } while (buflen != 0); |
| 4733 | |
| 4734 | return rc; |
| 4735 | |
| 4736 | unwind: |
| 4737 | for(; rc > 0; rc--) |
| 4738 | __free_page(spages[rc-1]); |
| 4739 | return -ENOMEM; |
| 4740 | } |
| 4741 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4742 | struct nfs4_cached_acl { |
| 4743 | int cached; |
| 4744 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4745 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4746 | }; |
| 4747 | |
| 4748 | 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] | 4749 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4750 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4751 | |
| 4752 | spin_lock(&inode->i_lock); |
| 4753 | kfree(nfsi->nfs4_acl); |
| 4754 | nfsi->nfs4_acl = acl; |
| 4755 | spin_unlock(&inode->i_lock); |
| 4756 | } |
| 4757 | |
| 4758 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4759 | { |
| 4760 | nfs4_set_cached_acl(inode, NULL); |
| 4761 | } |
| 4762 | |
| 4763 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4764 | { |
| 4765 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4766 | struct nfs4_cached_acl *acl; |
| 4767 | int ret = -ENOENT; |
| 4768 | |
| 4769 | spin_lock(&inode->i_lock); |
| 4770 | acl = nfsi->nfs4_acl; |
| 4771 | if (acl == NULL) |
| 4772 | goto out; |
| 4773 | if (buf == NULL) /* user is just asking for length */ |
| 4774 | goto out_len; |
| 4775 | if (acl->cached == 0) |
| 4776 | goto out; |
| 4777 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4778 | if (acl->len > buflen) |
| 4779 | goto out; |
| 4780 | memcpy(buf, acl->data, acl->len); |
| 4781 | out_len: |
| 4782 | ret = acl->len; |
| 4783 | out: |
| 4784 | spin_unlock(&inode->i_lock); |
| 4785 | return ret; |
| 4786 | } |
| 4787 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4788 | 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] | 4789 | { |
| 4790 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4791 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4792 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4793 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4794 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4795 | if (acl == NULL) |
| 4796 | goto out; |
| 4797 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4798 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4799 | } else { |
| 4800 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4801 | if (acl == NULL) |
| 4802 | goto out; |
| 4803 | acl->cached = 0; |
| 4804 | } |
| 4805 | acl->len = acl_len; |
| 4806 | out: |
| 4807 | nfs4_set_cached_acl(inode, acl); |
| 4808 | } |
| 4809 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4810 | /* |
| 4811 | * The getxattr API returns the required buffer length when called with a |
| 4812 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4813 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4814 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4815 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4816 | * the cache. If not so, we throw away the page, and cache the required |
| 4817 | * length. The next getxattr call will then produce another round trip to |
| 4818 | * the server, this time with the input buf of the required size. |
| 4819 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4820 | 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] | 4821 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4822 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4823 | struct nfs_getaclargs args = { |
| 4824 | .fh = NFS_FH(inode), |
| 4825 | .acl_pages = pages, |
| 4826 | .acl_len = buflen, |
| 4827 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4828 | struct nfs_getaclres res = { |
| 4829 | .acl_len = buflen, |
| 4830 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4831 | struct rpc_message msg = { |
| 4832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4833 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4834 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4835 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4836 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4837 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4838 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4839 | /* As long as we're doing a round trip to the server anyway, |
| 4840 | * let's be prepared for a page of acl data. */ |
| 4841 | if (npages == 0) |
| 4842 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4843 | if (npages > ARRAY_SIZE(pages)) |
| 4844 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4845 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4846 | for (i = 0; i < npages; i++) { |
| 4847 | pages[i] = alloc_page(GFP_KERNEL); |
| 4848 | if (!pages[i]) |
| 4849 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4850 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4851 | |
| 4852 | /* for decoding across pages */ |
| 4853 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4854 | if (!res.acl_scratch) |
| 4855 | goto out_free; |
| 4856 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4857 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4858 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4859 | 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] | 4860 | __func__, buf, buflen, npages, args.acl_len); |
| 4861 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4862 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4863 | if (ret) |
| 4864 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4865 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4866 | /* Handle the case where the passed-in buffer is too short */ |
| 4867 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4868 | /* Did the user only issue a request for the acl length? */ |
| 4869 | if (buf == NULL) |
| 4870 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4871 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4872 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4873 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4874 | 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] | 4875 | if (buf) { |
| 4876 | if (res.acl_len > buflen) { |
| 4877 | ret = -ERANGE; |
| 4878 | goto out_free; |
| 4879 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4880 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4881 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4882 | out_ok: |
| 4883 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4884 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4885 | for (i = 0; i < npages; i++) |
| 4886 | if (pages[i]) |
| 4887 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4888 | if (res.acl_scratch) |
| 4889 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4890 | return ret; |
| 4891 | } |
| 4892 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4893 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4894 | { |
| 4895 | struct nfs4_exception exception = { }; |
| 4896 | ssize_t ret; |
| 4897 | do { |
| 4898 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4899 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4900 | if (ret >= 0) |
| 4901 | break; |
| 4902 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4903 | } while (exception.retry); |
| 4904 | return ret; |
| 4905 | } |
| 4906 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4907 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4908 | { |
| 4909 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4910 | int ret; |
| 4911 | |
| 4912 | if (!nfs4_server_supports_acls(server)) |
| 4913 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4914 | ret = nfs_revalidate_inode(server, inode); |
| 4915 | if (ret < 0) |
| 4916 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4917 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4918 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4919 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4920 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4921 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4922 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4923 | return ret; |
| 4924 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4927 | 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] | 4928 | { |
| 4929 | struct nfs_server *server = NFS_SERVER(inode); |
| 4930 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4931 | struct nfs_setaclargs arg = { |
| 4932 | .fh = NFS_FH(inode), |
| 4933 | .acl_pages = pages, |
| 4934 | .acl_len = buflen, |
| 4935 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4936 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4937 | struct rpc_message msg = { |
| 4938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4939 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4940 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4941 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4942 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4943 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4944 | |
| 4945 | if (!nfs4_server_supports_acls(server)) |
| 4946 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4947 | if (npages > ARRAY_SIZE(pages)) |
| 4948 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4949 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4950 | if (i < 0) |
| 4951 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4952 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4953 | 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] | 4954 | |
| 4955 | /* |
| 4956 | * Free each page after tx, so the only ref left is |
| 4957 | * held by the network stack |
| 4958 | */ |
| 4959 | for (; i > 0; i--) |
| 4960 | put_page(pages[i-1]); |
| 4961 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4962 | /* |
| 4963 | * Acl update can result in inode attribute update. |
| 4964 | * so mark the attribute cache invalid. |
| 4965 | */ |
| 4966 | spin_lock(&inode->i_lock); |
| 4967 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4968 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4969 | nfs_access_zap_cache(inode); |
| 4970 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4971 | return ret; |
| 4972 | } |
| 4973 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4974 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4975 | { |
| 4976 | struct nfs4_exception exception = { }; |
| 4977 | int err; |
| 4978 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4979 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4980 | trace_nfs4_set_acl(inode, err); |
| 4981 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4982 | &exception); |
| 4983 | } while (exception.retry); |
| 4984 | return err; |
| 4985 | } |
| 4986 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4987 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4988 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4989 | size_t buflen) |
| 4990 | { |
| 4991 | struct nfs_server *server = NFS_SERVER(inode); |
| 4992 | struct nfs_fattr fattr; |
| 4993 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4994 | |
| 4995 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4996 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4997 | .fh = NFS_FH(inode), |
| 4998 | .bitmask = bitmask, |
| 4999 | }; |
| 5000 | struct nfs4_getattr_res res = { |
| 5001 | .fattr = &fattr, |
| 5002 | .label = &label, |
| 5003 | .server = server, |
| 5004 | }; |
| 5005 | struct rpc_message msg = { |
| 5006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5007 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5008 | .rpc_resp = &res, |
| 5009 | }; |
| 5010 | int ret; |
| 5011 | |
| 5012 | nfs_fattr_init(&fattr); |
| 5013 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5014 | 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] | 5015 | if (ret) |
| 5016 | return ret; |
| 5017 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5018 | return -ENOENT; |
| 5019 | if (buflen < label.len) |
| 5020 | return -ERANGE; |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
| 5024 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5025 | size_t buflen) |
| 5026 | { |
| 5027 | struct nfs4_exception exception = { }; |
| 5028 | int err; |
| 5029 | |
| 5030 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5031 | return -EOPNOTSUPP; |
| 5032 | |
| 5033 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5034 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5035 | trace_nfs4_get_security_label(inode, err); |
| 5036 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5037 | &exception); |
| 5038 | } while (exception.retry); |
| 5039 | return err; |
| 5040 | } |
| 5041 | |
| 5042 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5043 | struct nfs4_label *ilabel, |
| 5044 | struct nfs_fattr *fattr, |
| 5045 | struct nfs4_label *olabel) |
| 5046 | { |
| 5047 | |
| 5048 | struct iattr sattr = {0}; |
| 5049 | struct nfs_server *server = NFS_SERVER(inode); |
| 5050 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5051 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5052 | .fh = NFS_FH(inode), |
| 5053 | .iap = &sattr, |
| 5054 | .server = server, |
| 5055 | .bitmask = bitmask, |
| 5056 | .label = ilabel, |
| 5057 | }; |
| 5058 | struct nfs_setattrres res = { |
| 5059 | .fattr = fattr, |
| 5060 | .label = olabel, |
| 5061 | .server = server, |
| 5062 | }; |
| 5063 | struct rpc_message msg = { |
| 5064 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5065 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5066 | .rpc_resp = &res, |
| 5067 | }; |
| 5068 | int status; |
| 5069 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5070 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5071 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5072 | 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] | 5073 | if (status) |
| 5074 | dprintk("%s failed: %d\n", __func__, status); |
| 5075 | |
| 5076 | return status; |
| 5077 | } |
| 5078 | |
| 5079 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5080 | struct nfs4_label *ilabel, |
| 5081 | struct nfs_fattr *fattr, |
| 5082 | struct nfs4_label *olabel) |
| 5083 | { |
| 5084 | struct nfs4_exception exception = { }; |
| 5085 | int err; |
| 5086 | |
| 5087 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5088 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5089 | fattr, olabel); |
| 5090 | trace_nfs4_set_security_label(inode, err); |
| 5091 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5092 | &exception); |
| 5093 | } while (exception.retry); |
| 5094 | return err; |
| 5095 | } |
| 5096 | |
| 5097 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5098 | 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] | 5099 | { |
| 5100 | struct nfs4_label ilabel, *olabel = NULL; |
| 5101 | struct nfs_fattr fattr; |
| 5102 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5103 | int status; |
| 5104 | |
| 5105 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5106 | return -EOPNOTSUPP; |
| 5107 | |
| 5108 | nfs_fattr_init(&fattr); |
| 5109 | |
| 5110 | ilabel.pi = 0; |
| 5111 | ilabel.lfs = 0; |
| 5112 | ilabel.label = (char *)buf; |
| 5113 | ilabel.len = buflen; |
| 5114 | |
| 5115 | cred = rpc_lookup_cred(); |
| 5116 | if (IS_ERR(cred)) |
| 5117 | return PTR_ERR(cred); |
| 5118 | |
| 5119 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5120 | if (IS_ERR(olabel)) { |
| 5121 | status = -PTR_ERR(olabel); |
| 5122 | goto out; |
| 5123 | } |
| 5124 | |
| 5125 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5126 | if (status == 0) |
| 5127 | nfs_setsecurity(inode, &fattr, olabel); |
| 5128 | |
| 5129 | nfs4_label_free(olabel); |
| 5130 | out: |
| 5131 | put_rpccred(cred); |
| 5132 | return status; |
| 5133 | } |
| 5134 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5135 | |
| 5136 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5137 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5138 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5139 | { |
| 5140 | __be32 verf[2]; |
| 5141 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5142 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5143 | /* An impossible timestamp guarantees this value |
| 5144 | * will never match a generated boot time. */ |
| 5145 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5146 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5147 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5148 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5149 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5150 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5151 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5152 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5153 | } |
| 5154 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5155 | static int |
| 5156 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5157 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5158 | size_t len; |
| 5159 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5160 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5161 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5162 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5163 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5164 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5165 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5166 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5167 | 1 + |
| 5168 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5169 | 1; |
| 5170 | rcu_read_unlock(); |
| 5171 | |
| 5172 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5173 | return -EINVAL; |
| 5174 | |
| 5175 | /* |
| 5176 | * Since this string is allocated at mount time, and held until the |
| 5177 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5178 | * about a memory-reclaim deadlock. |
| 5179 | */ |
| 5180 | str = kmalloc(len, GFP_KERNEL); |
| 5181 | if (!str) |
| 5182 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5183 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5184 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5185 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5186 | clp->cl_ipaddr, |
| 5187 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5188 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5189 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5190 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5191 | clp->cl_owner_id = str; |
| 5192 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5193 | } |
| 5194 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5195 | static int |
| 5196 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5197 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5198 | size_t len; |
| 5199 | char *str; |
| 5200 | |
| 5201 | len = 10 + 10 + 1 + 10 + 1 + |
| 5202 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5203 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5204 | |
| 5205 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5206 | return -EINVAL; |
| 5207 | |
| 5208 | /* |
| 5209 | * Since this string is allocated at mount time, and held until the |
| 5210 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5211 | * about a memory-reclaim deadlock. |
| 5212 | */ |
| 5213 | str = kmalloc(len, GFP_KERNEL); |
| 5214 | if (!str) |
| 5215 | return -ENOMEM; |
| 5216 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5217 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5218 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5219 | nfs4_client_id_uniquifier, |
| 5220 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5221 | clp->cl_owner_id = str; |
| 5222 | return 0; |
| 5223 | } |
| 5224 | |
| 5225 | static int |
| 5226 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5227 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5228 | size_t len; |
| 5229 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5230 | |
| 5231 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5232 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5233 | |
| 5234 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5235 | return nfs4_init_uniquifier_client_string(clp); |
| 5236 | |
| 5237 | len = 10 + 10 + 1 + 10 + 1 + |
| 5238 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5239 | |
| 5240 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5241 | return -EINVAL; |
| 5242 | |
| 5243 | /* |
| 5244 | * Since this string is allocated at mount time, and held until the |
| 5245 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5246 | * about a memory-reclaim deadlock. |
| 5247 | */ |
| 5248 | str = kmalloc(len, GFP_KERNEL); |
| 5249 | if (!str) |
| 5250 | return -ENOMEM; |
| 5251 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5252 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5253 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5254 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5255 | clp->cl_owner_id = str; |
| 5256 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5257 | } |
| 5258 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5259 | /* |
| 5260 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5261 | * services. Advertise one based on the address family of the |
| 5262 | * clientaddr. |
| 5263 | */ |
| 5264 | static unsigned int |
| 5265 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5266 | { |
| 5267 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5268 | return scnprintf(buf, len, "tcp6"); |
| 5269 | else |
| 5270 | return scnprintf(buf, len, "tcp"); |
| 5271 | } |
| 5272 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5273 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5274 | { |
| 5275 | struct nfs4_setclientid *sc = calldata; |
| 5276 | |
| 5277 | if (task->tk_status == 0) |
| 5278 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5279 | } |
| 5280 | |
| 5281 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5282 | .rpc_call_done = nfs4_setclientid_done, |
| 5283 | }; |
| 5284 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5285 | /** |
| 5286 | * nfs4_proc_setclientid - Negotiate client ID |
| 5287 | * @clp: state data structure |
| 5288 | * @program: RPC program for NFSv4 callback service |
| 5289 | * @port: IP port number for NFS4 callback service |
| 5290 | * @cred: RPC credential to use for this call |
| 5291 | * @res: where to place the result |
| 5292 | * |
| 5293 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5294 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5295 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5296 | unsigned short port, struct rpc_cred *cred, |
| 5297 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | { |
| 5299 | nfs4_verifier sc_verifier; |
| 5300 | struct nfs4_setclientid setclientid = { |
| 5301 | .sc_verifier = &sc_verifier, |
| 5302 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5303 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | }; |
| 5305 | struct rpc_message msg = { |
| 5306 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5307 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5308 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5309 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5311 | struct rpc_task *task; |
| 5312 | struct rpc_task_setup task_setup_data = { |
| 5313 | .rpc_client = clp->cl_rpcclient, |
| 5314 | .rpc_message = &msg, |
| 5315 | .callback_ops = &nfs4_setclientid_ops, |
| 5316 | .callback_data = &setclientid, |
| 5317 | .flags = RPC_TASK_TIMEOUT, |
| 5318 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5319 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5321 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5322 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5323 | |
| 5324 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5325 | status = nfs4_init_uniform_client_string(clp); |
| 5326 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5327 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5328 | |
| 5329 | if (status) |
| 5330 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5331 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5332 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5333 | setclientid.sc_netid_len = |
| 5334 | nfs4_init_callback_netid(clp, |
| 5335 | setclientid.sc_netid, |
| 5336 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5337 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5338 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5339 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5340 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5341 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5342 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5343 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5344 | task = rpc_run_task(&task_setup_data); |
| 5345 | if (IS_ERR(task)) { |
| 5346 | status = PTR_ERR(task); |
| 5347 | goto out; |
| 5348 | } |
| 5349 | status = task->tk_status; |
| 5350 | if (setclientid.sc_cred) { |
| 5351 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5352 | put_rpccred(setclientid.sc_cred); |
| 5353 | } |
| 5354 | rpc_put_task(task); |
| 5355 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5356 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5357 | dprintk("NFS reply setclientid: %d\n", status); |
| 5358 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5361 | /** |
| 5362 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5363 | * @clp: state data structure |
| 5364 | * @res: result of a previous SETCLIENTID |
| 5365 | * @cred: RPC credential to use for this call |
| 5366 | * |
| 5367 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5368 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5369 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5370 | struct nfs4_setclientid_res *arg, |
| 5371 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | struct rpc_message msg = { |
| 5374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5375 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5376 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | int status; |
| 5379 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5380 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5381 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5382 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5383 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5384 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5385 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | return status; |
| 5387 | } |
| 5388 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5389 | struct nfs4_delegreturndata { |
| 5390 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5391 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5392 | struct nfs_fh fh; |
| 5393 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5394 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5395 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5396 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5397 | struct inode *inode; |
| 5398 | bool roc; |
| 5399 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5400 | }; |
| 5401 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5402 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5403 | { |
| 5404 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5405 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5406 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5407 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5408 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5409 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5410 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5411 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5412 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5413 | case -NFS4ERR_ADMIN_REVOKED: |
| 5414 | case -NFS4ERR_DELEG_REVOKED: |
| 5415 | case -NFS4ERR_BAD_STATEID: |
| 5416 | case -NFS4ERR_OLD_STATEID: |
| 5417 | case -NFS4ERR_STALE_STATEID: |
| 5418 | case -NFS4ERR_EXPIRED: |
| 5419 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5420 | if (data->roc) |
| 5421 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5422 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5423 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5424 | if (nfs4_async_handle_error(task, data->res.server, |
| 5425 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5426 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5427 | return; |
| 5428 | } |
| 5429 | } |
| 5430 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | static void nfs4_delegreturn_release(void *calldata) |
| 5434 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5435 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5436 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5437 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5438 | if (inode) { |
| 5439 | if (data->roc) |
| 5440 | pnfs_roc_release(inode); |
| 5441 | nfs_iput_and_deactive(inode); |
| 5442 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5443 | kfree(calldata); |
| 5444 | } |
| 5445 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5446 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5447 | { |
| 5448 | struct nfs4_delegreturndata *d_data; |
| 5449 | |
| 5450 | d_data = (struct nfs4_delegreturndata *)data; |
| 5451 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5452 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5453 | return; |
| 5454 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5455 | if (d_data->roc) |
| 5456 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5457 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5458 | nfs4_setup_sequence(d_data->res.server, |
| 5459 | &d_data->args.seq_args, |
| 5460 | &d_data->res.seq_res, |
| 5461 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5462 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5463 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5464 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5465 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5466 | .rpc_call_done = nfs4_delegreturn_done, |
| 5467 | .rpc_release = nfs4_delegreturn_release, |
| 5468 | }; |
| 5469 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5470 | 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] | 5471 | { |
| 5472 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5473 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5474 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5475 | struct rpc_message msg = { |
| 5476 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5477 | .rpc_cred = cred, |
| 5478 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5479 | struct rpc_task_setup task_setup_data = { |
| 5480 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5481 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5482 | .callback_ops = &nfs4_delegreturn_ops, |
| 5483 | .flags = RPC_TASK_ASYNC, |
| 5484 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5485 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5486 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5487 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5488 | if (data == NULL) |
| 5489 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5490 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5491 | |
| 5492 | nfs4_state_protect(server->nfs_client, |
| 5493 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5494 | &task_setup_data.rpc_client, &msg); |
| 5495 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5496 | data->args.fhandle = &data->fh; |
| 5497 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5498 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5499 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5500 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5501 | data->res.fattr = &data->fattr; |
| 5502 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5503 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5504 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5505 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5506 | data->inode = nfs_igrab_and_active(inode); |
| 5507 | if (data->inode) |
| 5508 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5509 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5510 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5511 | msg.rpc_argp = &data->args; |
| 5512 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5513 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5514 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5515 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5516 | if (!issync) |
| 5517 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5518 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5519 | if (status != 0) |
| 5520 | goto out; |
| 5521 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5522 | if (status == 0) |
| 5523 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5524 | else |
| 5525 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5526 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5527 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5528 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | } |
| 5530 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5531 | 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] | 5532 | { |
| 5533 | struct nfs_server *server = NFS_SERVER(inode); |
| 5534 | struct nfs4_exception exception = { }; |
| 5535 | int err; |
| 5536 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5537 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5538 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | switch (err) { |
| 5540 | case -NFS4ERR_STALE_STATEID: |
| 5541 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | case 0: |
| 5543 | return 0; |
| 5544 | } |
| 5545 | err = nfs4_handle_exception(server, err, &exception); |
| 5546 | } while (exception.retry); |
| 5547 | return err; |
| 5548 | } |
| 5549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5550 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5551 | { |
| 5552 | struct inode *inode = state->inode; |
| 5553 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5554 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5555 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5557 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5559 | struct nfs_lockt_res res = { |
| 5560 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5561 | }; |
| 5562 | struct rpc_message msg = { |
| 5563 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5564 | .rpc_argp = &arg, |
| 5565 | .rpc_resp = &res, |
| 5566 | .rpc_cred = state->owner->so_cred, |
| 5567 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | struct nfs4_lock_state *lsp; |
| 5569 | int status; |
| 5570 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5571 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5572 | status = nfs4_set_lock_state(state, request); |
| 5573 | if (status != 0) |
| 5574 | goto out; |
| 5575 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5576 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5577 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5578 | 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] | 5579 | switch (status) { |
| 5580 | case 0: |
| 5581 | request->fl_type = F_UNLCK; |
| 5582 | break; |
| 5583 | case -NFS4ERR_DENIED: |
| 5584 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5585 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5586 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5587 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5588 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | return status; |
| 5590 | } |
| 5591 | |
| 5592 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5593 | { |
| 5594 | struct nfs4_exception exception = { }; |
| 5595 | int err; |
| 5596 | |
| 5597 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5598 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5599 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5600 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | &exception); |
| 5602 | } while (exception.retry); |
| 5603 | return err; |
| 5604 | } |
| 5605 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5606 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5607 | struct nfs_locku_args arg; |
| 5608 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5609 | struct nfs4_lock_state *lsp; |
| 5610 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5611 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5612 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5613 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5614 | }; |
| 5615 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5616 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5617 | struct nfs_open_context *ctx, |
| 5618 | struct nfs4_lock_state *lsp, |
| 5619 | struct nfs_seqid *seqid) |
| 5620 | { |
| 5621 | struct nfs4_unlockdata *p; |
| 5622 | struct inode *inode = lsp->ls_state->inode; |
| 5623 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5624 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5625 | if (p == NULL) |
| 5626 | return NULL; |
| 5627 | p->arg.fh = NFS_FH(inode); |
| 5628 | p->arg.fl = &p->fl; |
| 5629 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5630 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5631 | p->lsp = lsp; |
| 5632 | atomic_inc(&lsp->ls_count); |
| 5633 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5634 | p->ctx = get_nfs_open_context(ctx); |
| 5635 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5636 | p->server = NFS_SERVER(inode); |
| 5637 | return p; |
| 5638 | } |
| 5639 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5640 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5641 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5642 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5643 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5644 | nfs4_put_lock_state(calldata->lsp); |
| 5645 | put_nfs_open_context(calldata->ctx); |
| 5646 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5649 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5650 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5651 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5652 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5653 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5654 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5655 | switch (task->tk_status) { |
| 5656 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5657 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5658 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5659 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5660 | &calldata->res.stateid)) |
| 5661 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5662 | case -NFS4ERR_BAD_STATEID: |
| 5663 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5664 | case -NFS4ERR_STALE_STATEID: |
| 5665 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5666 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5667 | &calldata->lsp->ls_stateid)) |
| 5668 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5669 | break; |
| 5670 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5671 | if (nfs4_async_handle_error(task, calldata->server, |
| 5672 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5673 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5674 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5675 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5678 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5679 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5680 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5682 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5683 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5684 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5685 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5686 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5687 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5688 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5689 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5690 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5691 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5692 | &calldata->res.seq_res, |
| 5693 | task) != 0) |
| 5694 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5695 | return; |
| 5696 | out_no_action: |
| 5697 | task->tk_action = NULL; |
| 5698 | out_wait: |
| 5699 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | } |
| 5701 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5702 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5703 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5704 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5705 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5706 | }; |
| 5707 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5708 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5709 | struct nfs_open_context *ctx, |
| 5710 | struct nfs4_lock_state *lsp, |
| 5711 | struct nfs_seqid *seqid) |
| 5712 | { |
| 5713 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5714 | struct rpc_message msg = { |
| 5715 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5716 | .rpc_cred = ctx->cred, |
| 5717 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5718 | struct rpc_task_setup task_setup_data = { |
| 5719 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5720 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5721 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5722 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5723 | .flags = RPC_TASK_ASYNC, |
| 5724 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5725 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5726 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5727 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5728 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5729 | /* Ensure this is an unlock - when canceling a lock, the |
| 5730 | * canceled lock is passed in, and it won't be an unlock. |
| 5731 | */ |
| 5732 | fl->fl_type = F_UNLCK; |
| 5733 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5734 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5735 | if (data == NULL) { |
| 5736 | nfs_free_seqid(seqid); |
| 5737 | return ERR_PTR(-ENOMEM); |
| 5738 | } |
| 5739 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5740 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5741 | msg.rpc_argp = &data->arg; |
| 5742 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5743 | task_setup_data.callback_data = data; |
| 5744 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5745 | } |
| 5746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5748 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5749 | struct inode *inode = state->inode; |
| 5750 | struct nfs4_state_owner *sp = state->owner; |
| 5751 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5752 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5753 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5754 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5755 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5756 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5757 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5759 | status = nfs4_set_lock_state(state, request); |
| 5760 | /* Unlock _before_ we do the RPC call */ |
| 5761 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5762 | /* Exclude nfs_delegation_claim_locks() */ |
| 5763 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5764 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5765 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5766 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5767 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5768 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5769 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5770 | } |
| 5771 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5772 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5773 | if (status != 0) |
| 5774 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5775 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5776 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5777 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5778 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5779 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5780 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5781 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5782 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5783 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5784 | 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] | 5785 | status = PTR_ERR(task); |
| 5786 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5787 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5788 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5789 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5790 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5791 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5792 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5793 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5796 | struct nfs4_lockdata { |
| 5797 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5798 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5799 | struct nfs4_lock_state *lsp; |
| 5800 | struct nfs_open_context *ctx; |
| 5801 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5802 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5803 | int rpc_status; |
| 5804 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5805 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5806 | }; |
| 5807 | |
| 5808 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5809 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5810 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5811 | { |
| 5812 | struct nfs4_lockdata *p; |
| 5813 | struct inode *inode = lsp->ls_state->inode; |
| 5814 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5815 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5816 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5817 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5818 | if (p == NULL) |
| 5819 | return NULL; |
| 5820 | |
| 5821 | p->arg.fh = NFS_FH(inode); |
| 5822 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5823 | 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] | 5824 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5825 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5826 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5827 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5828 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5829 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5830 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5831 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5832 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5833 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5834 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5835 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5836 | atomic_inc(&lsp->ls_count); |
| 5837 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5838 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5839 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5840 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5841 | out_free_seqid: |
| 5842 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5843 | out_free: |
| 5844 | kfree(p); |
| 5845 | return NULL; |
| 5846 | } |
| 5847 | |
| 5848 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5849 | { |
| 5850 | struct nfs4_lockdata *data = calldata; |
| 5851 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5853 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5854 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5855 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5856 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5857 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5858 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5859 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5860 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5861 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5862 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5863 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5864 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5865 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5866 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5867 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5868 | &data->lsp->ls_stateid); |
| 5869 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5870 | if (!nfs4_valid_open_stateid(state)) { |
| 5871 | data->rpc_status = -EBADF; |
| 5872 | task->tk_action = NULL; |
| 5873 | goto out_release_open_seqid; |
| 5874 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5875 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5876 | if (nfs4_setup_sequence(data->server, |
| 5877 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5878 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5879 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5880 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5881 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5882 | nfs_release_seqid(data->arg.open_seqid); |
| 5883 | out_release_lock_seqid: |
| 5884 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5885 | out_wait: |
| 5886 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5887 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5888 | } |
| 5889 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5890 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5891 | { |
| 5892 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5893 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5894 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5895 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5896 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5897 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5898 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5899 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5900 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5901 | switch (task->tk_status) { |
| 5902 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5903 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5904 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5905 | if (data->arg.new_lock) { |
| 5906 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5907 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5908 | rpc_restart_call_prepare(task); |
| 5909 | break; |
| 5910 | } |
| 5911 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5912 | if (data->arg.new_lock_owner != 0) { |
| 5913 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5914 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5915 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5916 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5917 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5918 | break; |
| 5919 | case -NFS4ERR_BAD_STATEID: |
| 5920 | case -NFS4ERR_OLD_STATEID: |
| 5921 | case -NFS4ERR_STALE_STATEID: |
| 5922 | case -NFS4ERR_EXPIRED: |
| 5923 | if (data->arg.new_lock_owner != 0) { |
| 5924 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5925 | &lsp->ls_state->open_stateid)) |
| 5926 | rpc_restart_call_prepare(task); |
| 5927 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5928 | &lsp->ls_stateid)) |
| 5929 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5930 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5931 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | static void nfs4_lock_release(void *calldata) |
| 5935 | { |
| 5936 | struct nfs4_lockdata *data = calldata; |
| 5937 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5938 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5939 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5940 | if (data->cancelled != 0) { |
| 5941 | struct rpc_task *task; |
| 5942 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5943 | data->arg.lock_seqid); |
| 5944 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5945 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5946 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5947 | } else |
| 5948 | nfs_free_seqid(data->arg.lock_seqid); |
| 5949 | nfs4_put_lock_state(data->lsp); |
| 5950 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5951 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5952 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5953 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5957 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5958 | .rpc_call_done = nfs4_lock_done, |
| 5959 | .rpc_release = nfs4_lock_release, |
| 5960 | }; |
| 5961 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5962 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5963 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5964 | switch (error) { |
| 5965 | case -NFS4ERR_ADMIN_REVOKED: |
| 5966 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5967 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5968 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5969 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5970 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5971 | break; |
| 5972 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5973 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5974 | case -NFS4ERR_EXPIRED: |
| 5975 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5976 | }; |
| 5977 | } |
| 5978 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5979 | 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] | 5980 | { |
| 5981 | struct nfs4_lockdata *data; |
| 5982 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5983 | struct rpc_message msg = { |
| 5984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5985 | .rpc_cred = state->owner->so_cred, |
| 5986 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5987 | struct rpc_task_setup task_setup_data = { |
| 5988 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5989 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5990 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5991 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5992 | .flags = RPC_TASK_ASYNC, |
| 5993 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5994 | int ret; |
| 5995 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5996 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5997 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5998 | fl->fl_u.nfs4_fl.owner, |
| 5999 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6000 | if (data == NULL) |
| 6001 | return -ENOMEM; |
| 6002 | if (IS_SETLKW(cmd)) |
| 6003 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6004 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6005 | msg.rpc_argp = &data->arg; |
| 6006 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6007 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6008 | if (recovery_type > NFS_LOCK_NEW) { |
| 6009 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6010 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6011 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6012 | } else |
| 6013 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6014 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6015 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6016 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6017 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6018 | if (ret == 0) { |
| 6019 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6020 | if (ret) |
| 6021 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6022 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6023 | } else |
| 6024 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6025 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6026 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6027 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6028 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | } |
| 6030 | |
| 6031 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6032 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6033 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6034 | struct nfs4_exception exception = { |
| 6035 | .inode = state->inode, |
| 6036 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6037 | int err; |
| 6038 | |
| 6039 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6040 | /* Cache the lock if possible... */ |
| 6041 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6042 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6043 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6044 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6045 | break; |
| 6046 | nfs4_handle_exception(server, err, &exception); |
| 6047 | } while (exception.retry); |
| 6048 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6052 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6053 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6054 | struct nfs4_exception exception = { |
| 6055 | .inode = state->inode, |
| 6056 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6057 | int err; |
| 6058 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6059 | err = nfs4_set_lock_state(state, request); |
| 6060 | if (err != 0) |
| 6061 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6062 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6063 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6064 | return 0; |
| 6065 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6066 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6067 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6068 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6069 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6070 | switch (err) { |
| 6071 | default: |
| 6072 | goto out; |
| 6073 | case -NFS4ERR_GRACE: |
| 6074 | case -NFS4ERR_DELAY: |
| 6075 | nfs4_handle_exception(server, err, &exception); |
| 6076 | err = 0; |
| 6077 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6078 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6079 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6080 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6083 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6084 | /** |
| 6085 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6086 | * |
| 6087 | * @state: NFSv4 state for an inode |
| 6088 | * |
| 6089 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6090 | * Otherwise a negative NFS4ERR value is returned. |
| 6091 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6092 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6093 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6094 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6095 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6096 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6097 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6098 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6099 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6100 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6101 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame^] | 6102 | status = nfs41_test_and_free_expired_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6103 | &lsp->ls_stateid, |
| 6104 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6105 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6106 | if (status != NFS_OK) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6107 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6108 | ret = status; |
| 6109 | } |
| 6110 | } |
| 6111 | }; |
| 6112 | |
| 6113 | return ret; |
| 6114 | } |
| 6115 | |
| 6116 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6117 | { |
| 6118 | int status = NFS_OK; |
| 6119 | |
| 6120 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6121 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6122 | if (status != NFS_OK) |
| 6123 | status = nfs4_lock_expired(state, request); |
| 6124 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6125 | } |
| 6126 | #endif |
| 6127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6129 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6130 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6131 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6132 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6133 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6135 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6136 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6137 | if (status < 0) |
| 6138 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6139 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6140 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6141 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6142 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6143 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6144 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6145 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6146 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6147 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6148 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6149 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6150 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6151 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6152 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6153 | out: |
| 6154 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | return status; |
| 6156 | } |
| 6157 | |
| 6158 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6159 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6160 | struct nfs4_exception exception = { |
| 6161 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6162 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6163 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6164 | int err; |
| 6165 | |
| 6166 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6167 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6168 | if (err == -NFS4ERR_DENIED) |
| 6169 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6171 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | } while (exception.retry); |
| 6173 | return err; |
| 6174 | } |
| 6175 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6176 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6177 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6178 | |
| 6179 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6180 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6181 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6182 | { |
| 6183 | int status = -ERESTARTSYS; |
| 6184 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6185 | |
| 6186 | while(!signalled()) { |
| 6187 | status = nfs4_proc_setlk(state, cmd, request); |
| 6188 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6189 | break; |
| 6190 | freezable_schedule_timeout_interruptible(timeout); |
| 6191 | timeout *= 2; |
| 6192 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6193 | status = -ERESTARTSYS; |
| 6194 | } |
| 6195 | return status; |
| 6196 | } |
| 6197 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6198 | #ifdef CONFIG_NFS_V4_1 |
| 6199 | struct nfs4_lock_waiter { |
| 6200 | struct task_struct *task; |
| 6201 | struct inode *inode; |
| 6202 | struct nfs_lowner *owner; |
| 6203 | bool notified; |
| 6204 | }; |
| 6205 | |
| 6206 | static int |
| 6207 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6208 | { |
| 6209 | int ret; |
| 6210 | struct cb_notify_lock_args *cbnl = key; |
| 6211 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6212 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6213 | *wowner = waiter->owner; |
| 6214 | |
| 6215 | /* Only wake if the callback was for the same owner */ |
| 6216 | if (lowner->clientid != wowner->clientid || |
| 6217 | lowner->id != wowner->id || |
| 6218 | lowner->s_dev != wowner->s_dev) |
| 6219 | return 0; |
| 6220 | |
| 6221 | /* Make sure it's for the right inode */ |
| 6222 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6223 | return 0; |
| 6224 | |
| 6225 | waiter->notified = true; |
| 6226 | |
| 6227 | /* override "private" so we can use default_wake_function */ |
| 6228 | wait->private = waiter->task; |
| 6229 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6230 | wait->private = waiter; |
| 6231 | return ret; |
| 6232 | } |
| 6233 | |
| 6234 | static int |
| 6235 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6236 | { |
| 6237 | int status = -ERESTARTSYS; |
| 6238 | unsigned long flags; |
| 6239 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6240 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6241 | struct nfs_client *clp = server->nfs_client; |
| 6242 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6243 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6244 | .id = lsp->ls_seqid.owner_id, |
| 6245 | .s_dev = server->s_dev }; |
| 6246 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6247 | .inode = state->inode, |
| 6248 | .owner = &owner, |
| 6249 | .notified = false }; |
| 6250 | wait_queue_t wait; |
| 6251 | |
| 6252 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6253 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6254 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6255 | |
| 6256 | init_wait(&wait); |
| 6257 | wait.private = &waiter; |
| 6258 | wait.func = nfs4_wake_lock_waiter; |
| 6259 | add_wait_queue(q, &wait); |
| 6260 | |
| 6261 | while(!signalled()) { |
| 6262 | status = nfs4_proc_setlk(state, cmd, request); |
| 6263 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6264 | break; |
| 6265 | |
| 6266 | status = -ERESTARTSYS; |
| 6267 | spin_lock_irqsave(&q->lock, flags); |
| 6268 | if (waiter.notified) { |
| 6269 | spin_unlock_irqrestore(&q->lock, flags); |
| 6270 | continue; |
| 6271 | } |
| 6272 | set_current_state(TASK_INTERRUPTIBLE); |
| 6273 | spin_unlock_irqrestore(&q->lock, flags); |
| 6274 | |
| 6275 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6276 | } |
| 6277 | |
| 6278 | finish_wait(q, &wait); |
| 6279 | return status; |
| 6280 | } |
| 6281 | #else /* !CONFIG_NFS_V4_1 */ |
| 6282 | static inline int |
| 6283 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6284 | { |
| 6285 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6286 | } |
| 6287 | #endif |
| 6288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | static int |
| 6290 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6291 | { |
| 6292 | struct nfs_open_context *ctx; |
| 6293 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6294 | int status; |
| 6295 | |
| 6296 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6297 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | state = ctx->state; |
| 6299 | |
| 6300 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6301 | return -EINVAL; |
| 6302 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6303 | if (IS_GETLK(cmd)) { |
| 6304 | if (state != NULL) |
| 6305 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6306 | return 0; |
| 6307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | |
| 6309 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6310 | return -EINVAL; |
| 6311 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6312 | if (request->fl_type == F_UNLCK) { |
| 6313 | if (state != NULL) |
| 6314 | return nfs4_proc_unlck(state, cmd, request); |
| 6315 | return 0; |
| 6316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6318 | if (state == NULL) |
| 6319 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6320 | |
| 6321 | if ((request->fl_flags & FL_POSIX) && |
| 6322 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6323 | return -ENOLCK; |
| 6324 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6325 | /* |
| 6326 | * Don't rely on the VFS having checked the file open mode, |
| 6327 | * since it won't do this for flock() locks. |
| 6328 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6329 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6330 | case F_RDLCK: |
| 6331 | if (!(filp->f_mode & FMODE_READ)) |
| 6332 | return -EBADF; |
| 6333 | break; |
| 6334 | case F_WRLCK: |
| 6335 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6336 | return -EBADF; |
| 6337 | } |
| 6338 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6339 | status = nfs4_set_lock_state(state, request); |
| 6340 | if (status != 0) |
| 6341 | return status; |
| 6342 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6343 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | } |
| 6345 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6346 | 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] | 6347 | { |
| 6348 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6349 | int err; |
| 6350 | |
| 6351 | err = nfs4_set_lock_state(state, fl); |
| 6352 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6353 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6354 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6355 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6356 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6357 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6358 | struct nfs_release_lockowner_data { |
| 6359 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6360 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6361 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6362 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6363 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6364 | }; |
| 6365 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6366 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6367 | { |
| 6368 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6369 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6370 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6371 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6372 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6373 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6374 | } |
| 6375 | |
| 6376 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6377 | { |
| 6378 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6379 | struct nfs_server *server = data->server; |
| 6380 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6381 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6382 | |
| 6383 | switch (task->tk_status) { |
| 6384 | case 0: |
| 6385 | renew_lease(server, data->timestamp); |
| 6386 | break; |
| 6387 | case -NFS4ERR_STALE_CLIENTID: |
| 6388 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6389 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6390 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6391 | case -NFS4ERR_LEASE_MOVED: |
| 6392 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6393 | if (nfs4_async_handle_error(task, server, |
| 6394 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6395 | rpc_restart_call_prepare(task); |
| 6396 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6397 | } |
| 6398 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6399 | static void nfs4_release_lockowner_release(void *calldata) |
| 6400 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6401 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6402 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6403 | kfree(calldata); |
| 6404 | } |
| 6405 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6406 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6407 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6408 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6409 | .rpc_release = nfs4_release_lockowner_release, |
| 6410 | }; |
| 6411 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6412 | static void |
| 6413 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6414 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6415 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6416 | struct rpc_message msg = { |
| 6417 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6418 | }; |
| 6419 | |
| 6420 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6421 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6422 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6423 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6424 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6425 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6426 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6427 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6428 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6429 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6430 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6431 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6432 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6433 | msg.rpc_resp = &data->res; |
| 6434 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6435 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6436 | } |
| 6437 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6438 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6439 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6440 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6441 | struct dentry *unused, struct inode *inode, |
| 6442 | const char *key, const void *buf, |
| 6443 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6444 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6445 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6448 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6449 | struct dentry *unused, struct inode *inode, |
| 6450 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6451 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6452 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6453 | } |
| 6454 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6455 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6456 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6457 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6458 | } |
| 6459 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6460 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6461 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6462 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6463 | struct dentry *unused, struct inode *inode, |
| 6464 | const char *key, const void *buf, |
| 6465 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6466 | { |
| 6467 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6468 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6469 | |
| 6470 | return -EOPNOTSUPP; |
| 6471 | } |
| 6472 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6473 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6474 | struct dentry *unused, struct inode *inode, |
| 6475 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6476 | { |
| 6477 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6478 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6479 | return -EOPNOTSUPP; |
| 6480 | } |
| 6481 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6482 | static ssize_t |
| 6483 | 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] | 6484 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6485 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6486 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6487 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6488 | len = security_inode_listsecurity(inode, list, list_len); |
| 6489 | if (list_len && len > list_len) |
| 6490 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6491 | } |
| 6492 | return len; |
| 6493 | } |
| 6494 | |
| 6495 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6496 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6497 | .get = nfs4_xattr_get_nfs4_label, |
| 6498 | .set = nfs4_xattr_set_nfs4_label, |
| 6499 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6500 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6501 | #else |
| 6502 | |
| 6503 | static ssize_t |
| 6504 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6505 | { |
| 6506 | return 0; |
| 6507 | } |
| 6508 | |
| 6509 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6510 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6511 | /* |
| 6512 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6513 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6514 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6515 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6516 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6517 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6518 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6519 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6520 | return; |
| 6521 | |
| 6522 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6523 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6524 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6525 | fattr->nlink = 2; |
| 6526 | } |
| 6527 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6528 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6529 | const struct qstr *name, |
| 6530 | struct nfs4_fs_locations *fs_locations, |
| 6531 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6532 | { |
| 6533 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6534 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6535 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6536 | }; |
| 6537 | struct nfs4_fs_locations_arg args = { |
| 6538 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6539 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6540 | .page = page, |
| 6541 | .bitmask = bitmask, |
| 6542 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6543 | struct nfs4_fs_locations_res res = { |
| 6544 | .fs_locations = fs_locations, |
| 6545 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6546 | struct rpc_message msg = { |
| 6547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6548 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6549 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6550 | }; |
| 6551 | int status; |
| 6552 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6553 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6554 | |
| 6555 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6556 | * is not supported */ |
| 6557 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6558 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6559 | else |
| 6560 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6561 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6562 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6563 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6564 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6565 | 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] | 6566 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6567 | return status; |
| 6568 | } |
| 6569 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6570 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6571 | const struct qstr *name, |
| 6572 | struct nfs4_fs_locations *fs_locations, |
| 6573 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6574 | { |
| 6575 | struct nfs4_exception exception = { }; |
| 6576 | int err; |
| 6577 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6578 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6579 | fs_locations, page); |
| 6580 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6581 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6582 | &exception); |
| 6583 | } while (exception.retry); |
| 6584 | return err; |
| 6585 | } |
| 6586 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6587 | /* |
| 6588 | * This operation also signals the server that this client is |
| 6589 | * performing migration recovery. The server can stop returning |
| 6590 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6591 | * appended to this compound to identify the client ID which is |
| 6592 | * performing recovery. |
| 6593 | */ |
| 6594 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6595 | struct nfs4_fs_locations *locations, |
| 6596 | struct page *page, struct rpc_cred *cred) |
| 6597 | { |
| 6598 | struct nfs_server *server = NFS_SERVER(inode); |
| 6599 | struct rpc_clnt *clnt = server->client; |
| 6600 | u32 bitmask[2] = { |
| 6601 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6602 | }; |
| 6603 | struct nfs4_fs_locations_arg args = { |
| 6604 | .clientid = server->nfs_client->cl_clientid, |
| 6605 | .fh = NFS_FH(inode), |
| 6606 | .page = page, |
| 6607 | .bitmask = bitmask, |
| 6608 | .migration = 1, /* skip LOOKUP */ |
| 6609 | .renew = 1, /* append RENEW */ |
| 6610 | }; |
| 6611 | struct nfs4_fs_locations_res res = { |
| 6612 | .fs_locations = locations, |
| 6613 | .migration = 1, |
| 6614 | .renew = 1, |
| 6615 | }; |
| 6616 | struct rpc_message msg = { |
| 6617 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6618 | .rpc_argp = &args, |
| 6619 | .rpc_resp = &res, |
| 6620 | .rpc_cred = cred, |
| 6621 | }; |
| 6622 | unsigned long now = jiffies; |
| 6623 | int status; |
| 6624 | |
| 6625 | nfs_fattr_init(&locations->fattr); |
| 6626 | locations->server = server; |
| 6627 | locations->nlocations = 0; |
| 6628 | |
| 6629 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6630 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6631 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6632 | &args.seq_args, &res.seq_res); |
| 6633 | if (status) |
| 6634 | return status; |
| 6635 | |
| 6636 | renew_lease(server, now); |
| 6637 | return 0; |
| 6638 | } |
| 6639 | |
| 6640 | #ifdef CONFIG_NFS_V4_1 |
| 6641 | |
| 6642 | /* |
| 6643 | * This operation also signals the server that this client is |
| 6644 | * performing migration recovery. The server can stop asserting |
| 6645 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6646 | * performing this operation is identified in the SEQUENCE |
| 6647 | * operation in this compound. |
| 6648 | * |
| 6649 | * When the client supports GETATTR(fs_locations_info), it can |
| 6650 | * be plumbed in here. |
| 6651 | */ |
| 6652 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6653 | struct nfs4_fs_locations *locations, |
| 6654 | struct page *page, struct rpc_cred *cred) |
| 6655 | { |
| 6656 | struct nfs_server *server = NFS_SERVER(inode); |
| 6657 | struct rpc_clnt *clnt = server->client; |
| 6658 | u32 bitmask[2] = { |
| 6659 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6660 | }; |
| 6661 | struct nfs4_fs_locations_arg args = { |
| 6662 | .fh = NFS_FH(inode), |
| 6663 | .page = page, |
| 6664 | .bitmask = bitmask, |
| 6665 | .migration = 1, /* skip LOOKUP */ |
| 6666 | }; |
| 6667 | struct nfs4_fs_locations_res res = { |
| 6668 | .fs_locations = locations, |
| 6669 | .migration = 1, |
| 6670 | }; |
| 6671 | struct rpc_message msg = { |
| 6672 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6673 | .rpc_argp = &args, |
| 6674 | .rpc_resp = &res, |
| 6675 | .rpc_cred = cred, |
| 6676 | }; |
| 6677 | int status; |
| 6678 | |
| 6679 | nfs_fattr_init(&locations->fattr); |
| 6680 | locations->server = server; |
| 6681 | locations->nlocations = 0; |
| 6682 | |
| 6683 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6684 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6685 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6686 | &args.seq_args, &res.seq_res); |
| 6687 | if (status == NFS4_OK && |
| 6688 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6689 | status = -NFS4ERR_LEASE_MOVED; |
| 6690 | return status; |
| 6691 | } |
| 6692 | |
| 6693 | #endif /* CONFIG_NFS_V4_1 */ |
| 6694 | |
| 6695 | /** |
| 6696 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6697 | * @inode: inode on FSID that is migrating |
| 6698 | * @locations: result of query |
| 6699 | * @page: buffer |
| 6700 | * @cred: credential to use for this operation |
| 6701 | * |
| 6702 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6703 | * operation failed, or a negative errno if a local error occurred. |
| 6704 | * |
| 6705 | * On success, "locations" is filled in, but if the server has |
| 6706 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6707 | * asserted. |
| 6708 | * |
| 6709 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6710 | * from this client that require migration recovery. |
| 6711 | */ |
| 6712 | int nfs4_proc_get_locations(struct inode *inode, |
| 6713 | struct nfs4_fs_locations *locations, |
| 6714 | struct page *page, struct rpc_cred *cred) |
| 6715 | { |
| 6716 | struct nfs_server *server = NFS_SERVER(inode); |
| 6717 | struct nfs_client *clp = server->nfs_client; |
| 6718 | const struct nfs4_mig_recovery_ops *ops = |
| 6719 | clp->cl_mvops->mig_recovery_ops; |
| 6720 | struct nfs4_exception exception = { }; |
| 6721 | int status; |
| 6722 | |
| 6723 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6724 | (unsigned long long)server->fsid.major, |
| 6725 | (unsigned long long)server->fsid.minor, |
| 6726 | clp->cl_hostname); |
| 6727 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6728 | |
| 6729 | do { |
| 6730 | status = ops->get_locations(inode, locations, page, cred); |
| 6731 | if (status != -NFS4ERR_DELAY) |
| 6732 | break; |
| 6733 | nfs4_handle_exception(server, status, &exception); |
| 6734 | } while (exception.retry); |
| 6735 | return status; |
| 6736 | } |
| 6737 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6738 | /* |
| 6739 | * This operation also signals the server that this client is |
| 6740 | * performing "lease moved" recovery. The server can stop |
| 6741 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6742 | * is appended to this compound to identify the client ID which is |
| 6743 | * performing recovery. |
| 6744 | */ |
| 6745 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6746 | { |
| 6747 | struct nfs_server *server = NFS_SERVER(inode); |
| 6748 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6749 | struct rpc_clnt *clnt = server->client; |
| 6750 | struct nfs4_fsid_present_arg args = { |
| 6751 | .fh = NFS_FH(inode), |
| 6752 | .clientid = clp->cl_clientid, |
| 6753 | .renew = 1, /* append RENEW */ |
| 6754 | }; |
| 6755 | struct nfs4_fsid_present_res res = { |
| 6756 | .renew = 1, |
| 6757 | }; |
| 6758 | struct rpc_message msg = { |
| 6759 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6760 | .rpc_argp = &args, |
| 6761 | .rpc_resp = &res, |
| 6762 | .rpc_cred = cred, |
| 6763 | }; |
| 6764 | unsigned long now = jiffies; |
| 6765 | int status; |
| 6766 | |
| 6767 | res.fh = nfs_alloc_fhandle(); |
| 6768 | if (res.fh == NULL) |
| 6769 | return -ENOMEM; |
| 6770 | |
| 6771 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6772 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6773 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6774 | &args.seq_args, &res.seq_res); |
| 6775 | nfs_free_fhandle(res.fh); |
| 6776 | if (status) |
| 6777 | return status; |
| 6778 | |
| 6779 | do_renew_lease(clp, now); |
| 6780 | return 0; |
| 6781 | } |
| 6782 | |
| 6783 | #ifdef CONFIG_NFS_V4_1 |
| 6784 | |
| 6785 | /* |
| 6786 | * This operation also signals the server that this client is |
| 6787 | * performing "lease moved" recovery. The server can stop asserting |
| 6788 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6789 | * this operation is identified in the SEQUENCE operation in this |
| 6790 | * compound. |
| 6791 | */ |
| 6792 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6793 | { |
| 6794 | struct nfs_server *server = NFS_SERVER(inode); |
| 6795 | struct rpc_clnt *clnt = server->client; |
| 6796 | struct nfs4_fsid_present_arg args = { |
| 6797 | .fh = NFS_FH(inode), |
| 6798 | }; |
| 6799 | struct nfs4_fsid_present_res res = { |
| 6800 | }; |
| 6801 | struct rpc_message msg = { |
| 6802 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6803 | .rpc_argp = &args, |
| 6804 | .rpc_resp = &res, |
| 6805 | .rpc_cred = cred, |
| 6806 | }; |
| 6807 | int status; |
| 6808 | |
| 6809 | res.fh = nfs_alloc_fhandle(); |
| 6810 | if (res.fh == NULL) |
| 6811 | return -ENOMEM; |
| 6812 | |
| 6813 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6814 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6815 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6816 | &args.seq_args, &res.seq_res); |
| 6817 | nfs_free_fhandle(res.fh); |
| 6818 | if (status == NFS4_OK && |
| 6819 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6820 | status = -NFS4ERR_LEASE_MOVED; |
| 6821 | return status; |
| 6822 | } |
| 6823 | |
| 6824 | #endif /* CONFIG_NFS_V4_1 */ |
| 6825 | |
| 6826 | /** |
| 6827 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6828 | * @inode: inode on FSID to check |
| 6829 | * @cred: credential to use for this operation |
| 6830 | * |
| 6831 | * Server indicates whether the FSID is present, moved, or not |
| 6832 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6833 | * condition for this client ID. |
| 6834 | * |
| 6835 | * Returns NFS4_OK if the FSID is present on this server, |
| 6836 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6837 | * NFS4ERR code if some error occurred on the server, or a |
| 6838 | * negative errno if a local failure occurred. |
| 6839 | */ |
| 6840 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6841 | { |
| 6842 | struct nfs_server *server = NFS_SERVER(inode); |
| 6843 | struct nfs_client *clp = server->nfs_client; |
| 6844 | const struct nfs4_mig_recovery_ops *ops = |
| 6845 | clp->cl_mvops->mig_recovery_ops; |
| 6846 | struct nfs4_exception exception = { }; |
| 6847 | int status; |
| 6848 | |
| 6849 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6850 | (unsigned long long)server->fsid.major, |
| 6851 | (unsigned long long)server->fsid.minor, |
| 6852 | clp->cl_hostname); |
| 6853 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6854 | |
| 6855 | do { |
| 6856 | status = ops->fsid_present(inode, cred); |
| 6857 | if (status != -NFS4ERR_DELAY) |
| 6858 | break; |
| 6859 | nfs4_handle_exception(server, status, &exception); |
| 6860 | } while (exception.retry); |
| 6861 | return status; |
| 6862 | } |
| 6863 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6864 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6865 | * If 'use_integrity' is true and the state managment nfs_client |
| 6866 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6867 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6868 | * Considerations sections. Otherwise, just use the user cred with the |
| 6869 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6870 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6871 | 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] | 6872 | { |
| 6873 | int status; |
| 6874 | struct nfs4_secinfo_arg args = { |
| 6875 | .dir_fh = NFS_FH(dir), |
| 6876 | .name = name, |
| 6877 | }; |
| 6878 | struct nfs4_secinfo_res res = { |
| 6879 | .flavors = flavors, |
| 6880 | }; |
| 6881 | struct rpc_message msg = { |
| 6882 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6883 | .rpc_argp = &args, |
| 6884 | .rpc_resp = &res, |
| 6885 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6886 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6887 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6888 | |
| 6889 | if (use_integrity) { |
| 6890 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6891 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6892 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6893 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6894 | |
| 6895 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6896 | |
| 6897 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6898 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6899 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6900 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6901 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6902 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6903 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6904 | if (cred) |
| 6905 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6906 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6907 | return status; |
| 6908 | } |
| 6909 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6910 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6911 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6912 | { |
| 6913 | struct nfs4_exception exception = { }; |
| 6914 | int err; |
| 6915 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6916 | err = -NFS4ERR_WRONGSEC; |
| 6917 | |
| 6918 | /* try to use integrity protection with machine cred */ |
| 6919 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6920 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6921 | |
| 6922 | /* |
| 6923 | * if unable to use integrity protection, or SECINFO with |
| 6924 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6925 | * disallowed by spec, but exists in deployed servers) use |
| 6926 | * the current filesystem's rpc_client and the user cred. |
| 6927 | */ |
| 6928 | if (err == -NFS4ERR_WRONGSEC) |
| 6929 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6930 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6931 | trace_nfs4_secinfo(dir, name, err); |
| 6932 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6933 | &exception); |
| 6934 | } while (exception.retry); |
| 6935 | return err; |
| 6936 | } |
| 6937 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6938 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6939 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6940 | * Check the exchange flags returned by the server for invalid flags, having |
| 6941 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6942 | * DS flags set. |
| 6943 | */ |
| 6944 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6945 | { |
| 6946 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6947 | goto out_inval; |
| 6948 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6949 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6950 | goto out_inval; |
| 6951 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6952 | goto out_inval; |
| 6953 | return NFS_OK; |
| 6954 | out_inval: |
| 6955 | return -NFS4ERR_INVAL; |
| 6956 | } |
| 6957 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6958 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6959 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6960 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6961 | { |
| 6962 | if (a->server_scope_sz == b->server_scope_sz && |
| 6963 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6964 | return true; |
| 6965 | |
| 6966 | return false; |
| 6967 | } |
| 6968 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6969 | static void |
| 6970 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6971 | { |
| 6972 | } |
| 6973 | |
| 6974 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6975 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6976 | }; |
| 6977 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6978 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6979 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6980 | * |
| 6981 | * The 4.1 client currently uses the same TCP connection for the |
| 6982 | * fore and backchannel. |
| 6983 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6984 | static |
| 6985 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6986 | struct rpc_xprt *xprt, |
| 6987 | struct nfs_client *clp, |
| 6988 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6989 | { |
| 6990 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6991 | struct nfs41_bind_conn_to_session_args args = { |
| 6992 | .client = clp, |
| 6993 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6994 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6995 | struct nfs41_bind_conn_to_session_res res; |
| 6996 | struct rpc_message msg = { |
| 6997 | .rpc_proc = |
| 6998 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6999 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7000 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7001 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7002 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7003 | struct rpc_task_setup task_setup_data = { |
| 7004 | .rpc_client = clnt, |
| 7005 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7006 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7007 | .rpc_message = &msg, |
| 7008 | .flags = RPC_TASK_TIMEOUT, |
| 7009 | }; |
| 7010 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7011 | |
| 7012 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7013 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7014 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7015 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7016 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7017 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7018 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7019 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7020 | args.dir = NFS4_CDFC4_FORE; |
| 7021 | |
| 7022 | task = rpc_run_task(&task_setup_data); |
| 7023 | if (!IS_ERR(task)) { |
| 7024 | status = task->tk_status; |
| 7025 | rpc_put_task(task); |
| 7026 | } else |
| 7027 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7028 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7029 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7030 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7031 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7032 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7033 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7034 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7035 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7036 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7037 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7038 | __func__); |
| 7039 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7040 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7041 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7042 | 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] | 7043 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7044 | __func__); |
| 7045 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7046 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7047 | } |
| 7048 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7049 | out: |
| 7050 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7051 | return status; |
| 7052 | } |
| 7053 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7054 | struct rpc_bind_conn_calldata { |
| 7055 | struct nfs_client *clp; |
| 7056 | struct rpc_cred *cred; |
| 7057 | }; |
| 7058 | |
| 7059 | static int |
| 7060 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7061 | struct rpc_xprt *xprt, |
| 7062 | void *calldata) |
| 7063 | { |
| 7064 | struct rpc_bind_conn_calldata *p = calldata; |
| 7065 | |
| 7066 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7067 | } |
| 7068 | |
| 7069 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7070 | { |
| 7071 | struct rpc_bind_conn_calldata data = { |
| 7072 | .clp = clp, |
| 7073 | .cred = cred, |
| 7074 | }; |
| 7075 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7076 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7077 | } |
| 7078 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7079 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7080 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7081 | * 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] | 7082 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7083 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7084 | .how = SP4_MACH_CRED, |
| 7085 | .enforce.u.words = { |
| 7086 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7087 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7088 | 1 << (OP_CREATE_SESSION - 32) | |
| 7089 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7090 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7091 | }, |
| 7092 | .allow.u.words = { |
| 7093 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7094 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7095 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7096 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7097 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7098 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7099 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7100 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7101 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7102 | 1 << (OP_FREE_STATEID - 32) | |
| 7103 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7104 | } |
| 7105 | }; |
| 7106 | |
| 7107 | /* |
| 7108 | * Select the state protection mode for client `clp' given the server results |
| 7109 | * from exchange_id in `sp'. |
| 7110 | * |
| 7111 | * Returns 0 on success, negative errno otherwise. |
| 7112 | */ |
| 7113 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7114 | struct nfs41_state_protection *sp) |
| 7115 | { |
| 7116 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7117 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7118 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7119 | 1 << (OP_CREATE_SESSION - 32) | |
| 7120 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7121 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7122 | }; |
| 7123 | unsigned int i; |
| 7124 | |
| 7125 | if (sp->how == SP4_MACH_CRED) { |
| 7126 | /* Print state protect result */ |
| 7127 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7128 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7129 | if (test_bit(i, sp->enforce.u.longs)) |
| 7130 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7131 | if (test_bit(i, sp->allow.u.longs)) |
| 7132 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7133 | } |
| 7134 | |
| 7135 | /* make sure nothing is on enforce list that isn't supported */ |
| 7136 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7137 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7138 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7139 | return -EINVAL; |
| 7140 | } |
| 7141 | } |
| 7142 | |
| 7143 | /* |
| 7144 | * Minimal mode - state operations are allowed to use machine |
| 7145 | * credential. Note this already happens by default, so the |
| 7146 | * client doesn't have to do anything more than the negotiation. |
| 7147 | * |
| 7148 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7149 | * we're already using the machine cred for exchange_id |
| 7150 | * and will never use a different cred. |
| 7151 | */ |
| 7152 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7153 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7154 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7155 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7156 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7157 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7158 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7159 | } else { |
| 7160 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7161 | return -EINVAL; |
| 7162 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7163 | |
| 7164 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7165 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7166 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7167 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7168 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7169 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7170 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7171 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7172 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7173 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7174 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7175 | &clp->cl_sp4_flags); |
| 7176 | } |
| 7177 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7178 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7179 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7180 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7181 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7182 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7183 | |
| 7184 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7185 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7186 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7187 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7188 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7189 | |
| 7190 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7191 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7192 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7193 | } |
| 7194 | |
| 7195 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7196 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7197 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7198 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | return 0; |
| 7202 | } |
| 7203 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7204 | struct nfs41_exchange_id_data { |
| 7205 | struct nfs41_exchange_id_res res; |
| 7206 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7207 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7208 | int rpc_status; |
| 7209 | }; |
| 7210 | |
| 7211 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7212 | { |
| 7213 | struct nfs41_exchange_id_data *cdata = |
| 7214 | (struct nfs41_exchange_id_data *)data; |
| 7215 | struct nfs_client *clp = cdata->args.client; |
| 7216 | int status = task->tk_status; |
| 7217 | |
| 7218 | trace_nfs4_exchange_id(clp, status); |
| 7219 | |
| 7220 | if (status == 0) |
| 7221 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7222 | |
| 7223 | if (cdata->xprt && status == 0) { |
| 7224 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7225 | cdata->xprt); |
| 7226 | goto out; |
| 7227 | } |
| 7228 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7229 | if (status == 0) |
| 7230 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7231 | |
| 7232 | if (status == 0) { |
| 7233 | clp->cl_clientid = cdata->res.clientid; |
| 7234 | clp->cl_exchange_flags = cdata->res.flags; |
| 7235 | /* Client ID is not confirmed */ |
| 7236 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7237 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7238 | &clp->cl_session->session_state); |
| 7239 | clp->cl_seqid = cdata->res.seqid; |
| 7240 | } |
| 7241 | |
| 7242 | kfree(clp->cl_serverowner); |
| 7243 | clp->cl_serverowner = cdata->res.server_owner; |
| 7244 | cdata->res.server_owner = NULL; |
| 7245 | |
| 7246 | /* use the most recent implementation id */ |
| 7247 | kfree(clp->cl_implid); |
| 7248 | clp->cl_implid = cdata->res.impl_id; |
| 7249 | cdata->res.impl_id = NULL; |
| 7250 | |
| 7251 | if (clp->cl_serverscope != NULL && |
| 7252 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7253 | cdata->res.server_scope)) { |
| 7254 | dprintk("%s: server_scope mismatch detected\n", |
| 7255 | __func__); |
| 7256 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7257 | kfree(clp->cl_serverscope); |
| 7258 | clp->cl_serverscope = NULL; |
| 7259 | } |
| 7260 | |
| 7261 | if (clp->cl_serverscope == NULL) { |
| 7262 | clp->cl_serverscope = cdata->res.server_scope; |
| 7263 | cdata->res.server_scope = NULL; |
| 7264 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7265 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7266 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7267 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7268 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7269 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7270 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7271 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | static void nfs4_exchange_id_release(void *data) |
| 7275 | { |
| 7276 | struct nfs41_exchange_id_data *cdata = |
| 7277 | (struct nfs41_exchange_id_data *)data; |
| 7278 | |
| 7279 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7280 | if (cdata->xprt) { |
| 7281 | xprt_put(cdata->xprt); |
| 7282 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7283 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7284 | kfree(cdata->res.impl_id); |
| 7285 | kfree(cdata->res.server_scope); |
| 7286 | kfree(cdata->res.server_owner); |
| 7287 | kfree(cdata); |
| 7288 | } |
| 7289 | |
| 7290 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7291 | .rpc_call_done = nfs4_exchange_id_done, |
| 7292 | .rpc_release = nfs4_exchange_id_release, |
| 7293 | }; |
| 7294 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7295 | /* |
| 7296 | * _nfs4_proc_exchange_id() |
| 7297 | * |
| 7298 | * Wrapper for EXCHANGE_ID operation. |
| 7299 | */ |
| 7300 | 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] | 7301 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7302 | { |
| 7303 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7304 | struct rpc_message msg = { |
| 7305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7306 | .rpc_cred = cred, |
| 7307 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7308 | struct rpc_task_setup task_setup_data = { |
| 7309 | .rpc_client = clp->cl_rpcclient, |
| 7310 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7311 | .rpc_message = &msg, |
| 7312 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7313 | }; |
| 7314 | struct nfs41_exchange_id_data *calldata; |
| 7315 | struct rpc_task *task; |
| 7316 | int status = -EIO; |
| 7317 | |
| 7318 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7319 | goto out; |
| 7320 | |
| 7321 | status = -ENOMEM; |
| 7322 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7323 | if (!calldata) |
| 7324 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7325 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7326 | if (!xprt) |
| 7327 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7328 | |
| 7329 | status = nfs4_init_uniform_client_string(clp); |
| 7330 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7331 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7332 | |
| 7333 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7334 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7335 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7336 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7337 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7338 | GFP_NOFS); |
| 7339 | status = -ENOMEM; |
| 7340 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7341 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7342 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7343 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7344 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7345 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7346 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7347 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7348 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7349 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7350 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7351 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7352 | switch (sp4_how) { |
| 7353 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7354 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7355 | break; |
| 7356 | |
| 7357 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7358 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7359 | break; |
| 7360 | |
| 7361 | default: |
| 7362 | /* unsupported! */ |
| 7363 | WARN_ON_ONCE(1); |
| 7364 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7365 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7366 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7367 | if (xprt) { |
| 7368 | calldata->xprt = xprt; |
| 7369 | task_setup_data.rpc_xprt = xprt; |
| 7370 | task_setup_data.flags = |
| 7371 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7372 | calldata->args.verifier = &clp->cl_confirm; |
| 7373 | } else { |
| 7374 | calldata->args.verifier = &verifier; |
| 7375 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7376 | calldata->args.client = clp; |
| 7377 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7378 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7379 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7380 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7381 | #else |
| 7382 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7383 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7384 | #endif |
| 7385 | msg.rpc_argp = &calldata->args; |
| 7386 | msg.rpc_resp = &calldata->res; |
| 7387 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7388 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7389 | task = rpc_run_task(&task_setup_data); |
| 7390 | if (IS_ERR(task)) { |
| 7391 | status = PTR_ERR(task); |
| 7392 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7393 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7394 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7395 | if (!xprt) { |
| 7396 | status = rpc_wait_for_completion_task(task); |
| 7397 | if (!status) |
| 7398 | status = calldata->rpc_status; |
| 7399 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7400 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7401 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7402 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7403 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7404 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7405 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7406 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7407 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7408 | clp->cl_implid->date.seconds, |
| 7409 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7410 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7411 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7412 | |
| 7413 | out_impl_id: |
| 7414 | kfree(calldata->res.impl_id); |
| 7415 | out_server_scope: |
| 7416 | kfree(calldata->res.server_scope); |
| 7417 | out_server_owner: |
| 7418 | kfree(calldata->res.server_owner); |
| 7419 | out_calldata: |
| 7420 | kfree(calldata); |
| 7421 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7422 | } |
| 7423 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7424 | /* |
| 7425 | * nfs4_proc_exchange_id() |
| 7426 | * |
| 7427 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7428 | * |
| 7429 | * Since the clientid has expired, all compounds using sessions |
| 7430 | * associated with the stale clientid will be returning |
| 7431 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7432 | * be in some phase of session reset. |
| 7433 | * |
| 7434 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7435 | */ |
| 7436 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7437 | { |
| 7438 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7439 | int status; |
| 7440 | |
| 7441 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7442 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7443 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7444 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7445 | if (!status) |
| 7446 | return 0; |
| 7447 | } |
| 7448 | |
| 7449 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7450 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7451 | } |
| 7452 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7453 | /** |
| 7454 | * nfs4_test_session_trunk |
| 7455 | * |
| 7456 | * This is an add_xprt_test() test function called from |
| 7457 | * rpc_clnt_setup_test_and_add_xprt. |
| 7458 | * |
| 7459 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7460 | * and is dereferrenced in nfs4_exchange_id_release |
| 7461 | * |
| 7462 | * Upon success, add the new transport to the rpc_clnt |
| 7463 | * |
| 7464 | * @clnt: struct rpc_clnt to get new transport |
| 7465 | * @xprt: the rpc_xprt to test |
| 7466 | * @data: call data for _nfs4_proc_exchange_id. |
| 7467 | */ |
| 7468 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7469 | void *data) |
| 7470 | { |
| 7471 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7472 | u32 sp4_how; |
| 7473 | |
| 7474 | dprintk("--> %s try %s\n", __func__, |
| 7475 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7476 | |
| 7477 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7478 | |
| 7479 | /* Test connection for session trunking. Async exchange_id call */ |
| 7480 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7481 | } |
| 7482 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7483 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7484 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7485 | struct rpc_cred *cred) |
| 7486 | { |
| 7487 | struct rpc_message msg = { |
| 7488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7489 | .rpc_argp = clp, |
| 7490 | .rpc_cred = cred, |
| 7491 | }; |
| 7492 | int status; |
| 7493 | |
| 7494 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7495 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7496 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7497 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7498 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7499 | return status; |
| 7500 | } |
| 7501 | |
| 7502 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7503 | struct rpc_cred *cred) |
| 7504 | { |
| 7505 | unsigned int loop; |
| 7506 | int ret; |
| 7507 | |
| 7508 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7509 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7510 | switch (ret) { |
| 7511 | case -NFS4ERR_DELAY: |
| 7512 | case -NFS4ERR_CLIENTID_BUSY: |
| 7513 | ssleep(1); |
| 7514 | break; |
| 7515 | default: |
| 7516 | return ret; |
| 7517 | } |
| 7518 | } |
| 7519 | return 0; |
| 7520 | } |
| 7521 | |
| 7522 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7523 | { |
| 7524 | struct rpc_cred *cred; |
| 7525 | int ret = 0; |
| 7526 | |
| 7527 | if (clp->cl_mvops->minor_version < 1) |
| 7528 | goto out; |
| 7529 | if (clp->cl_exchange_flags == 0) |
| 7530 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7531 | if (clp->cl_preserve_clid) |
| 7532 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7533 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7534 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7535 | if (cred) |
| 7536 | put_rpccred(cred); |
| 7537 | switch (ret) { |
| 7538 | case 0: |
| 7539 | case -NFS4ERR_STALE_CLIENTID: |
| 7540 | clp->cl_exchange_flags = 0; |
| 7541 | } |
| 7542 | out: |
| 7543 | return ret; |
| 7544 | } |
| 7545 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7546 | struct nfs4_get_lease_time_data { |
| 7547 | struct nfs4_get_lease_time_args *args; |
| 7548 | struct nfs4_get_lease_time_res *res; |
| 7549 | struct nfs_client *clp; |
| 7550 | }; |
| 7551 | |
| 7552 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7553 | void *calldata) |
| 7554 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7555 | struct nfs4_get_lease_time_data *data = |
| 7556 | (struct nfs4_get_lease_time_data *)calldata; |
| 7557 | |
| 7558 | dprintk("--> %s\n", __func__); |
| 7559 | /* just setup sequence, do not trigger session recovery |
| 7560 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7561 | nfs41_setup_sequence(data->clp->cl_session, |
| 7562 | &data->args->la_seq_args, |
| 7563 | &data->res->lr_seq_res, |
| 7564 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7565 | dprintk("<-- %s\n", __func__); |
| 7566 | } |
| 7567 | |
| 7568 | /* |
| 7569 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7570 | * from sequence operation or clientid errors. |
| 7571 | */ |
| 7572 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7573 | { |
| 7574 | struct nfs4_get_lease_time_data *data = |
| 7575 | (struct nfs4_get_lease_time_data *)calldata; |
| 7576 | |
| 7577 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7578 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7579 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7580 | switch (task->tk_status) { |
| 7581 | case -NFS4ERR_DELAY: |
| 7582 | case -NFS4ERR_GRACE: |
| 7583 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7584 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7585 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7586 | /* fall through */ |
| 7587 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7588 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7589 | return; |
| 7590 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7591 | dprintk("<-- %s\n", __func__); |
| 7592 | } |
| 7593 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7594 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7595 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7596 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7597 | }; |
| 7598 | |
| 7599 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7600 | { |
| 7601 | struct rpc_task *task; |
| 7602 | struct nfs4_get_lease_time_args args; |
| 7603 | struct nfs4_get_lease_time_res res = { |
| 7604 | .lr_fsinfo = fsinfo, |
| 7605 | }; |
| 7606 | struct nfs4_get_lease_time_data data = { |
| 7607 | .args = &args, |
| 7608 | .res = &res, |
| 7609 | .clp = clp, |
| 7610 | }; |
| 7611 | struct rpc_message msg = { |
| 7612 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7613 | .rpc_argp = &args, |
| 7614 | .rpc_resp = &res, |
| 7615 | }; |
| 7616 | struct rpc_task_setup task_setup = { |
| 7617 | .rpc_client = clp->cl_rpcclient, |
| 7618 | .rpc_message = &msg, |
| 7619 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7620 | .callback_data = &data, |
| 7621 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7622 | }; |
| 7623 | int status; |
| 7624 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7625 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7626 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7627 | dprintk("--> %s\n", __func__); |
| 7628 | task = rpc_run_task(&task_setup); |
| 7629 | |
| 7630 | if (IS_ERR(task)) |
| 7631 | status = PTR_ERR(task); |
| 7632 | else { |
| 7633 | status = task->tk_status; |
| 7634 | rpc_put_task(task); |
| 7635 | } |
| 7636 | dprintk("<-- %s return %d\n", __func__, status); |
| 7637 | |
| 7638 | return status; |
| 7639 | } |
| 7640 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7641 | /* |
| 7642 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7643 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7644 | * use them. |
| 7645 | * |
| 7646 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7647 | * always set csa_cachethis to FALSE because the current implementation |
| 7648 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7649 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7650 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7651 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7652 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7653 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7654 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7655 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7656 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7657 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7658 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7659 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7660 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7661 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7662 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7663 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7664 | |
| 7665 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7666 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7667 | __func__, |
| 7668 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7669 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7670 | |
| 7671 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7672 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7673 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7674 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7675 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7676 | 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] | 7677 | |
| 7678 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7679 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7680 | __func__, |
| 7681 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7682 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7683 | args->bc_attrs.max_reqs); |
| 7684 | } |
| 7685 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7686 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7687 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7688 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7689 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7690 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7691 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7692 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7693 | return -EINVAL; |
| 7694 | /* |
| 7695 | * Our requested max_ops is the minimum we need; we're not |
| 7696 | * prepared to break up compounds into smaller pieces than that. |
| 7697 | * So, no point even trying to continue if the server won't |
| 7698 | * cooperate: |
| 7699 | */ |
| 7700 | if (rcvd->max_ops < sent->max_ops) |
| 7701 | return -EINVAL; |
| 7702 | if (rcvd->max_reqs == 0) |
| 7703 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7704 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7705 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7706 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7707 | } |
| 7708 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7709 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7710 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7711 | { |
| 7712 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7713 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7714 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7715 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7716 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7717 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7718 | return -EINVAL; |
| 7719 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7720 | return -EINVAL; |
| 7721 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7722 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7723 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7724 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7725 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7726 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7727 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7728 | return 0; |
| 7729 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7730 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7731 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7732 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7733 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7734 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7735 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7736 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7737 | if (ret) |
| 7738 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7739 | return nfs4_verify_back_channel_attrs(args, res); |
| 7740 | } |
| 7741 | |
| 7742 | static void nfs4_update_session(struct nfs4_session *session, |
| 7743 | struct nfs41_create_session_res *res) |
| 7744 | { |
| 7745 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7746 | /* Mark client id and session as being confirmed */ |
| 7747 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7748 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7749 | session->flags = res->flags; |
| 7750 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7751 | if (res->flags & SESSION4_BACK_CHAN) |
| 7752 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7753 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7754 | } |
| 7755 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7756 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7757 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7758 | { |
| 7759 | struct nfs4_session *session = clp->cl_session; |
| 7760 | struct nfs41_create_session_args args = { |
| 7761 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7762 | .clientid = clp->cl_clientid, |
| 7763 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7764 | .cb_program = NFS4_CALLBACK, |
| 7765 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7766 | struct nfs41_create_session_res res; |
| 7767 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7768 | struct rpc_message msg = { |
| 7769 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7770 | .rpc_argp = &args, |
| 7771 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7772 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7773 | }; |
| 7774 | int status; |
| 7775 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7776 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7777 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7778 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7779 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7780 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7781 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7782 | switch (status) { |
| 7783 | case -NFS4ERR_STALE_CLIENTID: |
| 7784 | case -NFS4ERR_DELAY: |
| 7785 | case -ETIMEDOUT: |
| 7786 | case -EACCES: |
| 7787 | case -EAGAIN: |
| 7788 | goto out; |
| 7789 | }; |
| 7790 | |
| 7791 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7792 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7793 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7794 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7795 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7796 | if (status) |
| 7797 | goto out; |
| 7798 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7799 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7800 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7801 | return status; |
| 7802 | } |
| 7803 | |
| 7804 | /* |
| 7805 | * Issues a CREATE_SESSION operation to the server. |
| 7806 | * It is the responsibility of the caller to verify the session is |
| 7807 | * expired before calling this routine. |
| 7808 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7809 | 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] | 7810 | { |
| 7811 | int status; |
| 7812 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7813 | struct nfs4_session *session = clp->cl_session; |
| 7814 | |
| 7815 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7816 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7817 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7818 | if (status) |
| 7819 | goto out; |
| 7820 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7821 | /* Init or reset the session slot tables */ |
| 7822 | status = nfs4_setup_session_slot_tables(session); |
| 7823 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7824 | if (status) |
| 7825 | goto out; |
| 7826 | |
| 7827 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7828 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7829 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7830 | out: |
| 7831 | dprintk("<-- %s\n", __func__); |
| 7832 | return status; |
| 7833 | } |
| 7834 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7835 | /* |
| 7836 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7837 | * The caller must serialize access to this routine. |
| 7838 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7839 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7840 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7841 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7842 | struct rpc_message msg = { |
| 7843 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7844 | .rpc_argp = session, |
| 7845 | .rpc_cred = cred, |
| 7846 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7847 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7848 | |
| 7849 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7850 | |
| 7851 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7852 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7853 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7854 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7855 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7856 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7857 | |
| 7858 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7859 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7860 | "Session has been destroyed regardless...\n", status); |
| 7861 | |
| 7862 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7863 | return status; |
| 7864 | } |
| 7865 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7866 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7867 | * Renew the cl_session lease. |
| 7868 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7869 | struct nfs4_sequence_data { |
| 7870 | struct nfs_client *clp; |
| 7871 | struct nfs4_sequence_args args; |
| 7872 | struct nfs4_sequence_res res; |
| 7873 | }; |
| 7874 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7875 | static void nfs41_sequence_release(void *data) |
| 7876 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7877 | struct nfs4_sequence_data *calldata = data; |
| 7878 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7879 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7880 | if (atomic_read(&clp->cl_count) > 1) |
| 7881 | nfs4_schedule_state_renewal(clp); |
| 7882 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7883 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7884 | } |
| 7885 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7886 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7887 | { |
| 7888 | switch(task->tk_status) { |
| 7889 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7890 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7891 | return -EAGAIN; |
| 7892 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7893 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7894 | } |
| 7895 | return 0; |
| 7896 | } |
| 7897 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7898 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7899 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7900 | struct nfs4_sequence_data *calldata = data; |
| 7901 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7902 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7903 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7904 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7905 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7906 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7907 | if (task->tk_status < 0) { |
| 7908 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7909 | if (atomic_read(&clp->cl_count) == 1) |
| 7910 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7911 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7912 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7913 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7914 | return; |
| 7915 | } |
| 7916 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7917 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7918 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7919 | dprintk("<-- %s\n", __func__); |
| 7920 | } |
| 7921 | |
| 7922 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7923 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7924 | struct nfs4_sequence_data *calldata = data; |
| 7925 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7926 | struct nfs4_sequence_args *args; |
| 7927 | struct nfs4_sequence_res *res; |
| 7928 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7929 | args = task->tk_msg.rpc_argp; |
| 7930 | res = task->tk_msg.rpc_resp; |
| 7931 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7932 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7936 | .rpc_call_done = nfs41_sequence_call_done, |
| 7937 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7938 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7939 | }; |
| 7940 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7941 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7942 | struct rpc_cred *cred, |
| 7943 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7944 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7945 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7946 | struct rpc_message msg = { |
| 7947 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7948 | .rpc_cred = cred, |
| 7949 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7950 | struct rpc_task_setup task_setup_data = { |
| 7951 | .rpc_client = clp->cl_rpcclient, |
| 7952 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7953 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7954 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7955 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7956 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7957 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7958 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7959 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7960 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7961 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7962 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7963 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7964 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7965 | if (is_privileged) |
| 7966 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7967 | msg.rpc_argp = &calldata->args; |
| 7968 | msg.rpc_resp = &calldata->res; |
| 7969 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7970 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7971 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7972 | return rpc_run_task(&task_setup_data); |
| 7973 | } |
| 7974 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7975 | 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] | 7976 | { |
| 7977 | struct rpc_task *task; |
| 7978 | int ret = 0; |
| 7979 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7980 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7981 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7982 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7983 | if (IS_ERR(task)) |
| 7984 | ret = PTR_ERR(task); |
| 7985 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7986 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7987 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7988 | return ret; |
| 7989 | } |
| 7990 | |
| 7991 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7992 | { |
| 7993 | struct rpc_task *task; |
| 7994 | int ret; |
| 7995 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7996 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7997 | if (IS_ERR(task)) { |
| 7998 | ret = PTR_ERR(task); |
| 7999 | goto out; |
| 8000 | } |
| 8001 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8002 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8003 | ret = task->tk_status; |
| 8004 | rpc_put_task(task); |
| 8005 | out: |
| 8006 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8007 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8008 | } |
| 8009 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8010 | struct nfs4_reclaim_complete_data { |
| 8011 | struct nfs_client *clp; |
| 8012 | struct nfs41_reclaim_complete_args arg; |
| 8013 | struct nfs41_reclaim_complete_res res; |
| 8014 | }; |
| 8015 | |
| 8016 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8017 | { |
| 8018 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8019 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8020 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8021 | &calldata->arg.seq_args, |
| 8022 | &calldata->res.seq_res, |
| 8023 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8024 | } |
| 8025 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8026 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8027 | { |
| 8028 | switch(task->tk_status) { |
| 8029 | case 0: |
| 8030 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8031 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8032 | break; |
| 8033 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8034 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8035 | /* fall through */ |
| 8036 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8037 | return -EAGAIN; |
| 8038 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8039 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8040 | } |
| 8041 | return 0; |
| 8042 | } |
| 8043 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8044 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8045 | { |
| 8046 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8047 | struct nfs_client *clp = calldata->clp; |
| 8048 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8049 | |
| 8050 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8051 | if (!nfs41_sequence_done(task, res)) |
| 8052 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8053 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8054 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8055 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8056 | rpc_restart_call_prepare(task); |
| 8057 | return; |
| 8058 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8059 | dprintk("<-- %s\n", __func__); |
| 8060 | } |
| 8061 | |
| 8062 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8063 | { |
| 8064 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8065 | |
| 8066 | kfree(calldata); |
| 8067 | } |
| 8068 | |
| 8069 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8070 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8071 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8072 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8073 | }; |
| 8074 | |
| 8075 | /* |
| 8076 | * Issue a global reclaim complete. |
| 8077 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8078 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8079 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8080 | { |
| 8081 | struct nfs4_reclaim_complete_data *calldata; |
| 8082 | struct rpc_task *task; |
| 8083 | struct rpc_message msg = { |
| 8084 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8085 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8086 | }; |
| 8087 | struct rpc_task_setup task_setup_data = { |
| 8088 | .rpc_client = clp->cl_rpcclient, |
| 8089 | .rpc_message = &msg, |
| 8090 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8091 | .flags = RPC_TASK_ASYNC, |
| 8092 | }; |
| 8093 | int status = -ENOMEM; |
| 8094 | |
| 8095 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8096 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8097 | if (calldata == NULL) |
| 8098 | goto out; |
| 8099 | calldata->clp = clp; |
| 8100 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8101 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8102 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8103 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8104 | msg.rpc_argp = &calldata->arg; |
| 8105 | msg.rpc_resp = &calldata->res; |
| 8106 | task_setup_data.callback_data = calldata; |
| 8107 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8108 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8109 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8110 | goto out; |
| 8111 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8112 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8113 | if (status == 0) |
| 8114 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8115 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8116 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8117 | out: |
| 8118 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8119 | return status; |
| 8120 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8121 | |
| 8122 | static void |
| 8123 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8124 | { |
| 8125 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8126 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8127 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8128 | |
| 8129 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8130 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8131 | &lgp->res.seq_res, task); |
| 8132 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8133 | } |
| 8134 | |
| 8135 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8136 | { |
| 8137 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8138 | |
| 8139 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8140 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8141 | dprintk("<-- %s\n", __func__); |
| 8142 | } |
| 8143 | |
| 8144 | static int |
| 8145 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8146 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8147 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8148 | struct inode *inode = lgp->args.inode; |
| 8149 | struct nfs_server *server = NFS_SERVER(inode); |
| 8150 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8151 | int nfs4err = task->tk_status; |
| 8152 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8153 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8154 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8155 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8156 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8157 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8158 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8159 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8160 | |
| 8161 | /* |
| 8162 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8163 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8164 | * retry go inband. |
| 8165 | */ |
| 8166 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8167 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8168 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8169 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8170 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8171 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8172 | */ |
| 8173 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8174 | status = -EOVERFLOW; |
| 8175 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8176 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8177 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8178 | * (or clients) writing to the same RAID stripe except when |
| 8179 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8180 | * |
| 8181 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8182 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8183 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8184 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8185 | if (lgp->args.minlength == 0) { |
| 8186 | status = -EOVERFLOW; |
| 8187 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8188 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8189 | status = -EBUSY; |
| 8190 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8191 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8192 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8193 | break; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8194 | case -NFS4ERR_EXPIRED: |
| 8195 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8196 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8197 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8198 | lo = NFS_I(inode)->layout; |
| 8199 | /* If the open stateid was bad, then recover it. */ |
| 8200 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8201 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8202 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8203 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8204 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8205 | break; |
| 8206 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8207 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8208 | /* |
| 8209 | * Mark the bad layout state as invalid, then retry |
| 8210 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8211 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8212 | spin_unlock(&inode->i_lock); |
| 8213 | pnfs_free_lseg_list(&head); |
| 8214 | status = -EAGAIN; |
| 8215 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8216 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8217 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8218 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8219 | if (!status) { |
| 8220 | if (exception->retry) |
| 8221 | status = -EAGAIN; |
| 8222 | else |
| 8223 | status = err; |
| 8224 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8225 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8226 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8227 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8228 | } |
| 8229 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8230 | static size_t max_response_pages(struct nfs_server *server) |
| 8231 | { |
| 8232 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8233 | return nfs_page_array_len(0, max_resp_sz); |
| 8234 | } |
| 8235 | |
| 8236 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8237 | { |
| 8238 | int i; |
| 8239 | |
| 8240 | if (!pages) |
| 8241 | return; |
| 8242 | |
| 8243 | for (i = 0; i < size; i++) { |
| 8244 | if (!pages[i]) |
| 8245 | break; |
| 8246 | __free_page(pages[i]); |
| 8247 | } |
| 8248 | kfree(pages); |
| 8249 | } |
| 8250 | |
| 8251 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8252 | { |
| 8253 | struct page **pages; |
| 8254 | int i; |
| 8255 | |
| 8256 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8257 | if (!pages) { |
| 8258 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8259 | return NULL; |
| 8260 | } |
| 8261 | |
| 8262 | for (i = 0; i < size; i++) { |
| 8263 | pages[i] = alloc_page(gfp_flags); |
| 8264 | if (!pages[i]) { |
| 8265 | dprintk("%s: failed to allocate page\n", __func__); |
| 8266 | nfs4_free_pages(pages, size); |
| 8267 | return NULL; |
| 8268 | } |
| 8269 | } |
| 8270 | |
| 8271 | return pages; |
| 8272 | } |
| 8273 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8274 | static void nfs4_layoutget_release(void *calldata) |
| 8275 | { |
| 8276 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8277 | struct inode *inode = lgp->args.inode; |
| 8278 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8279 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8280 | |
| 8281 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8282 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8283 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8284 | put_nfs_open_context(lgp->args.ctx); |
| 8285 | kfree(calldata); |
| 8286 | dprintk("<-- %s\n", __func__); |
| 8287 | } |
| 8288 | |
| 8289 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8290 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8291 | .rpc_call_done = nfs4_layoutget_done, |
| 8292 | .rpc_release = nfs4_layoutget_release, |
| 8293 | }; |
| 8294 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8295 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8296 | 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] | 8297 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8298 | struct inode *inode = lgp->args.inode; |
| 8299 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8300 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8301 | struct rpc_task *task; |
| 8302 | struct rpc_message msg = { |
| 8303 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8304 | .rpc_argp = &lgp->args, |
| 8305 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8306 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8307 | }; |
| 8308 | struct rpc_task_setup task_setup_data = { |
| 8309 | .rpc_client = server->client, |
| 8310 | .rpc_message = &msg, |
| 8311 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8312 | .callback_data = lgp, |
| 8313 | .flags = RPC_TASK_ASYNC, |
| 8314 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8315 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8316 | struct nfs4_exception exception = { |
| 8317 | .inode = inode, |
| 8318 | .timeout = *timeout, |
| 8319 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8320 | int status = 0; |
| 8321 | |
| 8322 | dprintk("--> %s\n", __func__); |
| 8323 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8324 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8325 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8326 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8327 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8328 | if (!lgp->args.layout.pages) { |
| 8329 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8330 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8331 | } |
| 8332 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8333 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8334 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8335 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8336 | 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] | 8337 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8338 | task = rpc_run_task(&task_setup_data); |
| 8339 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8340 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8341 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8342 | if (status == 0) { |
| 8343 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8344 | *timeout = exception.timeout; |
| 8345 | } |
| 8346 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8347 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8348 | &lgp->args.range, |
| 8349 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8350 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8351 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8352 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8353 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8354 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8355 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8356 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8357 | rpc_put_task(task); |
| 8358 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8359 | if (status) |
| 8360 | return ERR_PTR(status); |
| 8361 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8362 | } |
| 8363 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8364 | static void |
| 8365 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8366 | { |
| 8367 | struct nfs4_layoutreturn *lrp = calldata; |
| 8368 | |
| 8369 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8370 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8371 | &lrp->args.seq_args, |
| 8372 | &lrp->res.seq_res, |
| 8373 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8377 | { |
| 8378 | struct nfs4_layoutreturn *lrp = calldata; |
| 8379 | struct nfs_server *server; |
| 8380 | |
| 8381 | dprintk("--> %s\n", __func__); |
| 8382 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8383 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8384 | return; |
| 8385 | |
| 8386 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8387 | switch (task->tk_status) { |
| 8388 | default: |
| 8389 | task->tk_status = 0; |
| 8390 | case 0: |
| 8391 | break; |
| 8392 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8393 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8394 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8395 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8396 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8397 | return; |
| 8398 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8399 | dprintk("<-- %s\n", __func__); |
| 8400 | } |
| 8401 | |
| 8402 | static void nfs4_layoutreturn_release(void *calldata) |
| 8403 | { |
| 8404 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8405 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8406 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8407 | |
| 8408 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8409 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8410 | if (lrp->res.lrs_present) { |
| 8411 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8412 | &lrp->args.range, |
| 8413 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8414 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8415 | } else |
| 8416 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8417 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8418 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8419 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8420 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8421 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8422 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8423 | kfree(calldata); |
| 8424 | dprintk("<-- %s\n", __func__); |
| 8425 | } |
| 8426 | |
| 8427 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8428 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8429 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8430 | .rpc_release = nfs4_layoutreturn_release, |
| 8431 | }; |
| 8432 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8433 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8434 | { |
| 8435 | struct rpc_task *task; |
| 8436 | struct rpc_message msg = { |
| 8437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8438 | .rpc_argp = &lrp->args, |
| 8439 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8440 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8441 | }; |
| 8442 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8443 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8444 | .rpc_message = &msg, |
| 8445 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8446 | .callback_data = lrp, |
| 8447 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8448 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8449 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8450 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8451 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8452 | &task_setup_data.rpc_client, &msg); |
| 8453 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8454 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8455 | if (!sync) { |
| 8456 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8457 | if (!lrp->inode) { |
| 8458 | nfs4_layoutreturn_release(lrp); |
| 8459 | return -EAGAIN; |
| 8460 | } |
| 8461 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8462 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8463 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8464 | task = rpc_run_task(&task_setup_data); |
| 8465 | if (IS_ERR(task)) |
| 8466 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8467 | if (sync) |
| 8468 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8469 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8470 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8471 | rpc_put_task(task); |
| 8472 | return status; |
| 8473 | } |
| 8474 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8475 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8476 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8477 | struct pnfs_device *pdev, |
| 8478 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8479 | { |
| 8480 | struct nfs4_getdeviceinfo_args args = { |
| 8481 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8482 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8483 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8484 | }; |
| 8485 | struct nfs4_getdeviceinfo_res res = { |
| 8486 | .pdev = pdev, |
| 8487 | }; |
| 8488 | struct rpc_message msg = { |
| 8489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8490 | .rpc_argp = &args, |
| 8491 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8492 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8493 | }; |
| 8494 | int status; |
| 8495 | |
| 8496 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8497 | 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] | 8498 | if (res.notification & ~args.notify_types) |
| 8499 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8500 | if (res.notification != args.notify_types) |
| 8501 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8502 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8503 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8504 | |
| 8505 | return status; |
| 8506 | } |
| 8507 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8508 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8509 | struct pnfs_device *pdev, |
| 8510 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8511 | { |
| 8512 | struct nfs4_exception exception = { }; |
| 8513 | int err; |
| 8514 | |
| 8515 | do { |
| 8516 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8517 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8518 | &exception); |
| 8519 | } while (exception.retry); |
| 8520 | return err; |
| 8521 | } |
| 8522 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8523 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8524 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8525 | { |
| 8526 | struct nfs4_layoutcommit_data *data = calldata; |
| 8527 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8528 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8529 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8530 | nfs41_setup_sequence(session, |
| 8531 | &data->args.seq_args, |
| 8532 | &data->res.seq_res, |
| 8533 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8534 | } |
| 8535 | |
| 8536 | static void |
| 8537 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8538 | { |
| 8539 | struct nfs4_layoutcommit_data *data = calldata; |
| 8540 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8541 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8542 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8543 | return; |
| 8544 | |
| 8545 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8546 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8547 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8548 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8549 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8550 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8551 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8552 | break; |
| 8553 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8554 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8555 | rpc_restart_call_prepare(task); |
| 8556 | return; |
| 8557 | } |
| 8558 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8559 | } |
| 8560 | |
| 8561 | static void nfs4_layoutcommit_release(void *calldata) |
| 8562 | { |
| 8563 | struct nfs4_layoutcommit_data *data = calldata; |
| 8564 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8565 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8566 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8567 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8568 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8569 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8570 | kfree(data); |
| 8571 | } |
| 8572 | |
| 8573 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8574 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8575 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8576 | .rpc_release = nfs4_layoutcommit_release, |
| 8577 | }; |
| 8578 | |
| 8579 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8580 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8581 | { |
| 8582 | struct rpc_message msg = { |
| 8583 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8584 | .rpc_argp = &data->args, |
| 8585 | .rpc_resp = &data->res, |
| 8586 | .rpc_cred = data->cred, |
| 8587 | }; |
| 8588 | struct rpc_task_setup task_setup_data = { |
| 8589 | .task = &data->task, |
| 8590 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8591 | .rpc_message = &msg, |
| 8592 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8593 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8594 | }; |
| 8595 | struct rpc_task *task; |
| 8596 | int status = 0; |
| 8597 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8598 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8599 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8600 | data->args.lastbytewritten, |
| 8601 | data->args.inode->i_ino); |
| 8602 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8603 | if (!sync) { |
| 8604 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8605 | if (data->inode == NULL) { |
| 8606 | nfs4_layoutcommit_release(data); |
| 8607 | return -EAGAIN; |
| 8608 | } |
| 8609 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8610 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8611 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8612 | task = rpc_run_task(&task_setup_data); |
| 8613 | if (IS_ERR(task)) |
| 8614 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8615 | if (sync) |
| 8616 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8617 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8618 | dprintk("%s: status %d\n", __func__, status); |
| 8619 | rpc_put_task(task); |
| 8620 | return status; |
| 8621 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8622 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8623 | /** |
| 8624 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8625 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8626 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8627 | static int |
| 8628 | _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] | 8629 | struct nfs_fsinfo *info, |
| 8630 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8631 | { |
| 8632 | struct nfs41_secinfo_no_name_args args = { |
| 8633 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8634 | }; |
| 8635 | struct nfs4_secinfo_res res = { |
| 8636 | .flavors = flavors, |
| 8637 | }; |
| 8638 | struct rpc_message msg = { |
| 8639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8640 | .rpc_argp = &args, |
| 8641 | .rpc_resp = &res, |
| 8642 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8643 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8644 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8645 | int status; |
| 8646 | |
| 8647 | if (use_integrity) { |
| 8648 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8649 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8650 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8651 | } |
| 8652 | |
| 8653 | dprintk("--> %s\n", __func__); |
| 8654 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8655 | &res.seq_res, 0); |
| 8656 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8657 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8658 | if (cred) |
| 8659 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8660 | |
| 8661 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8662 | } |
| 8663 | |
| 8664 | static int |
| 8665 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8666 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8667 | { |
| 8668 | struct nfs4_exception exception = { }; |
| 8669 | int err; |
| 8670 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8671 | /* first try using integrity protection */ |
| 8672 | err = -NFS4ERR_WRONGSEC; |
| 8673 | |
| 8674 | /* try to use integrity protection with machine cred */ |
| 8675 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8676 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8677 | flavors, true); |
| 8678 | |
| 8679 | /* |
| 8680 | * if unable to use integrity protection, or SECINFO with |
| 8681 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8682 | * disallowed by spec, but exists in deployed servers) use |
| 8683 | * the current filesystem's rpc_client and the user cred. |
| 8684 | */ |
| 8685 | if (err == -NFS4ERR_WRONGSEC) |
| 8686 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8687 | flavors, false); |
| 8688 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8689 | switch (err) { |
| 8690 | case 0: |
| 8691 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8692 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8693 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8694 | default: |
| 8695 | err = nfs4_handle_exception(server, err, &exception); |
| 8696 | } |
| 8697 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8698 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8699 | return err; |
| 8700 | } |
| 8701 | |
| 8702 | static int |
| 8703 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8704 | struct nfs_fsinfo *info) |
| 8705 | { |
| 8706 | int err; |
| 8707 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8708 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8709 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8710 | struct nfs4_secinfo4 *secinfo; |
| 8711 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8712 | |
| 8713 | page = alloc_page(GFP_KERNEL); |
| 8714 | if (!page) { |
| 8715 | err = -ENOMEM; |
| 8716 | goto out; |
| 8717 | } |
| 8718 | |
| 8719 | flavors = page_address(page); |
| 8720 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8721 | |
| 8722 | /* |
| 8723 | * Fall back on "guess and check" method if |
| 8724 | * the server doesn't support SECINFO_NO_NAME |
| 8725 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8726 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8727 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8728 | goto out_freepage; |
| 8729 | } |
| 8730 | if (err) |
| 8731 | goto out_freepage; |
| 8732 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8733 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8734 | secinfo = &flavors->flavors[i]; |
| 8735 | |
| 8736 | switch (secinfo->flavor) { |
| 8737 | case RPC_AUTH_NULL: |
| 8738 | case RPC_AUTH_UNIX: |
| 8739 | case RPC_AUTH_GSS: |
| 8740 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8741 | &secinfo->flavor_info); |
| 8742 | break; |
| 8743 | default: |
| 8744 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8745 | break; |
| 8746 | } |
| 8747 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8748 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8749 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8750 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8751 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8752 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8753 | info, flavor); |
| 8754 | if (!err) |
| 8755 | break; |
| 8756 | } |
| 8757 | } |
| 8758 | |
| 8759 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8760 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8761 | |
| 8762 | out_freepage: |
| 8763 | put_page(page); |
| 8764 | if (err == -EACCES) |
| 8765 | return -EPERM; |
| 8766 | out: |
| 8767 | return err; |
| 8768 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8769 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8770 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8771 | nfs4_stateid *stateid, |
| 8772 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8773 | { |
| 8774 | int status; |
| 8775 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8776 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8777 | }; |
| 8778 | struct nfs41_test_stateid_res res; |
| 8779 | struct rpc_message msg = { |
| 8780 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8781 | .rpc_argp = &args, |
| 8782 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8783 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8784 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8785 | struct rpc_clnt *rpc_client = server->client; |
| 8786 | |
| 8787 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8788 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8789 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8790 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8791 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8792 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8793 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8794 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8795 | if (status != NFS_OK) { |
| 8796 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8797 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8798 | } |
| 8799 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8800 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8801 | } |
| 8802 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8803 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8804 | int err, struct nfs4_exception *exception) |
| 8805 | { |
| 8806 | exception->retry = 0; |
| 8807 | switch(err) { |
| 8808 | case -NFS4ERR_DELAY: |
| 8809 | nfs4_handle_exception(server, err, exception); |
| 8810 | break; |
| 8811 | case -NFS4ERR_BADSESSION: |
| 8812 | case -NFS4ERR_BADSLOT: |
| 8813 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8814 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8815 | case -NFS4ERR_DEADSESSION: |
| 8816 | nfs4_do_handle_exception(server, err, exception); |
| 8817 | } |
| 8818 | } |
| 8819 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8820 | /** |
| 8821 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8822 | * |
| 8823 | * @server: server / transport on which to perform the operation |
| 8824 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8825 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8826 | * |
| 8827 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8828 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8829 | * failed or the state ID is not currently valid. |
| 8830 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8831 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8832 | nfs4_stateid *stateid, |
| 8833 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8834 | { |
| 8835 | struct nfs4_exception exception = { }; |
| 8836 | int err; |
| 8837 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8838 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8839 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8840 | } while (exception.retry); |
| 8841 | return err; |
| 8842 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8843 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8844 | struct nfs_free_stateid_data { |
| 8845 | struct nfs_server *server; |
| 8846 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8847 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8848 | }; |
| 8849 | |
| 8850 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8851 | { |
| 8852 | struct nfs_free_stateid_data *data = calldata; |
| 8853 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8854 | &data->args.seq_args, |
| 8855 | &data->res.seq_res, |
| 8856 | task); |
| 8857 | } |
| 8858 | |
| 8859 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8860 | { |
| 8861 | struct nfs_free_stateid_data *data = calldata; |
| 8862 | |
| 8863 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8864 | |
| 8865 | switch (task->tk_status) { |
| 8866 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8867 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8868 | rpc_restart_call_prepare(task); |
| 8869 | } |
| 8870 | } |
| 8871 | |
| 8872 | static void nfs41_free_stateid_release(void *calldata) |
| 8873 | { |
| 8874 | kfree(calldata); |
| 8875 | } |
| 8876 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8877 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8878 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8879 | .rpc_call_done = nfs41_free_stateid_done, |
| 8880 | .rpc_release = nfs41_free_stateid_release, |
| 8881 | }; |
| 8882 | |
| 8883 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8884 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8885 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8886 | bool privileged) |
| 8887 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8888 | struct rpc_message msg = { |
| 8889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8890 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8891 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8892 | struct rpc_task_setup task_setup = { |
| 8893 | .rpc_client = server->client, |
| 8894 | .rpc_message = &msg, |
| 8895 | .callback_ops = &nfs41_free_stateid_ops, |
| 8896 | .flags = RPC_TASK_ASYNC, |
| 8897 | }; |
| 8898 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8899 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8900 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8901 | &task_setup.rpc_client, &msg); |
| 8902 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8903 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8904 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8905 | if (!data) |
| 8906 | return ERR_PTR(-ENOMEM); |
| 8907 | data->server = server; |
| 8908 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8909 | |
| 8910 | task_setup.callback_data = data; |
| 8911 | |
| 8912 | msg.rpc_argp = &data->args; |
| 8913 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8914 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8915 | if (privileged) |
| 8916 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8917 | |
| 8918 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8919 | } |
| 8920 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8921 | /** |
| 8922 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8923 | * |
| 8924 | * @server: server / transport on which to perform the operation |
| 8925 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8926 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8927 | * |
| 8928 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8929 | * negative NFS4ERR value is returned. |
| 8930 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8931 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8932 | nfs4_stateid *stateid, |
| 8933 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8934 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8935 | struct rpc_task *task; |
| 8936 | int ret; |
| 8937 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8938 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8939 | if (IS_ERR(task)) |
| 8940 | return PTR_ERR(task); |
| 8941 | ret = rpc_wait_for_completion_task(task); |
| 8942 | if (!ret) |
| 8943 | ret = task->tk_status; |
| 8944 | rpc_put_task(task); |
| 8945 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8946 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8947 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8948 | static void |
| 8949 | 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] | 8950 | { |
| 8951 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8952 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8953 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8954 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8955 | nfs4_free_lock_state(server, lsp); |
| 8956 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8957 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8958 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8959 | } |
| 8960 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8961 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8962 | const nfs4_stateid *s2) |
| 8963 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8964 | if (s1->type != s2->type) |
| 8965 | return false; |
| 8966 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8967 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8968 | return false; |
| 8969 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8970 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8971 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8972 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8973 | return true; |
| 8974 | |
| 8975 | return false; |
| 8976 | } |
| 8977 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8978 | #endif /* CONFIG_NFS_V4_1 */ |
| 8979 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8980 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8981 | const nfs4_stateid *s2) |
| 8982 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8983 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8984 | } |
| 8985 | |
| 8986 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8987 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8988 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8989 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8990 | .recover_open = nfs4_open_reclaim, |
| 8991 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8992 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8993 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8994 | }; |
| 8995 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8996 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8997 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8998 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8999 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9000 | .recover_open = nfs4_open_reclaim, |
| 9001 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9002 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9003 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9004 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9005 | }; |
| 9006 | #endif /* CONFIG_NFS_V4_1 */ |
| 9007 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9008 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9009 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9010 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9011 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9012 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9013 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9014 | }; |
| 9015 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9016 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9017 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9018 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9019 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9020 | .recover_open = nfs41_open_expired, |
| 9021 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9022 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9023 | }; |
| 9024 | #endif /* CONFIG_NFS_V4_1 */ |
| 9025 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9026 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9027 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9028 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9029 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9030 | }; |
| 9031 | |
| 9032 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9033 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9034 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9035 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9036 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9037 | }; |
| 9038 | #endif |
| 9039 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9040 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9041 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9042 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9043 | }; |
| 9044 | |
| 9045 | #if defined(CONFIG_NFS_V4_1) |
| 9046 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9047 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9048 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9049 | }; |
| 9050 | #endif /* CONFIG_NFS_V4_1 */ |
| 9051 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9052 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9053 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9054 | .init_caps = NFS_CAP_READDIRPLUS |
| 9055 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9056 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9057 | .init_client = nfs40_init_client, |
| 9058 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9059 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9060 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9061 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9062 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9063 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9064 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9065 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9066 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9067 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9068 | }; |
| 9069 | |
| 9070 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9071 | static struct nfs_seqid * |
| 9072 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9073 | { |
| 9074 | return NULL; |
| 9075 | } |
| 9076 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9077 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9078 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9079 | .init_caps = NFS_CAP_READDIRPLUS |
| 9080 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9081 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9082 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9083 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9084 | .init_client = nfs41_init_client, |
| 9085 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9086 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9087 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9088 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9089 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9090 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9091 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9092 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9093 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9094 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9095 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9096 | }; |
| 9097 | #endif |
| 9098 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9099 | #if defined(CONFIG_NFS_V4_2) |
| 9100 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9101 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9102 | .init_caps = NFS_CAP_READDIRPLUS |
| 9103 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9104 | | NFS_CAP_POSIX_LOCK |
| 9105 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9106 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9107 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9108 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9109 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9110 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9111 | | NFS_CAP_LAYOUTSTATS |
| 9112 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9113 | .init_client = nfs41_init_client, |
| 9114 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9115 | .match_stateid = nfs41_match_stateid, |
| 9116 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9117 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9118 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9119 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9120 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9121 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9122 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9123 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9124 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9125 | }; |
| 9126 | #endif |
| 9127 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9128 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9129 | [0] = &nfs_v4_0_minor_ops, |
| 9130 | #if defined(CONFIG_NFS_V4_1) |
| 9131 | [1] = &nfs_v4_1_minor_ops, |
| 9132 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9133 | #if defined(CONFIG_NFS_V4_2) |
| 9134 | [2] = &nfs_v4_2_minor_ops, |
| 9135 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9136 | }; |
| 9137 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9138 | 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] | 9139 | { |
| 9140 | ssize_t error, error2; |
| 9141 | |
| 9142 | error = generic_listxattr(dentry, list, size); |
| 9143 | if (error < 0) |
| 9144 | return error; |
| 9145 | if (list) { |
| 9146 | list += error; |
| 9147 | size -= error; |
| 9148 | } |
| 9149 | |
| 9150 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9151 | if (error2 < 0) |
| 9152 | return error2; |
| 9153 | return error + error2; |
| 9154 | } |
| 9155 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9156 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9157 | .create = nfs_create, |
| 9158 | .lookup = nfs_lookup, |
| 9159 | .atomic_open = nfs_atomic_open, |
| 9160 | .link = nfs_link, |
| 9161 | .unlink = nfs_unlink, |
| 9162 | .symlink = nfs_symlink, |
| 9163 | .mkdir = nfs_mkdir, |
| 9164 | .rmdir = nfs_rmdir, |
| 9165 | .mknod = nfs_mknod, |
| 9166 | .rename = nfs_rename, |
| 9167 | .permission = nfs_permission, |
| 9168 | .getattr = nfs_getattr, |
| 9169 | .setattr = nfs_setattr, |
| 9170 | .getxattr = generic_getxattr, |
| 9171 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9172 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9173 | .removexattr = generic_removexattr, |
| 9174 | }; |
| 9175 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9176 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9177 | .permission = nfs_permission, |
| 9178 | .getattr = nfs_getattr, |
| 9179 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9180 | .getxattr = generic_getxattr, |
| 9181 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9182 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9183 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9184 | }; |
| 9185 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9186 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9187 | .version = 4, /* protocol version */ |
| 9188 | .dentry_ops = &nfs4_dentry_operations, |
| 9189 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9190 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9191 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9192 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9193 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9194 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9195 | .getattr = nfs4_proc_getattr, |
| 9196 | .setattr = nfs4_proc_setattr, |
| 9197 | .lookup = nfs4_proc_lookup, |
| 9198 | .access = nfs4_proc_access, |
| 9199 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9200 | .create = nfs4_proc_create, |
| 9201 | .remove = nfs4_proc_remove, |
| 9202 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9203 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9204 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9205 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9206 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9207 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9208 | .link = nfs4_proc_link, |
| 9209 | .symlink = nfs4_proc_symlink, |
| 9210 | .mkdir = nfs4_proc_mkdir, |
| 9211 | .rmdir = nfs4_proc_remove, |
| 9212 | .readdir = nfs4_proc_readdir, |
| 9213 | .mknod = nfs4_proc_mknod, |
| 9214 | .statfs = nfs4_proc_statfs, |
| 9215 | .fsinfo = nfs4_proc_fsinfo, |
| 9216 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9217 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9218 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9219 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9220 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9221 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9222 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9223 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9224 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9225 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9226 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9227 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9228 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9229 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9230 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9231 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9232 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9233 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9234 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9235 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9236 | .create_server = nfs4_create_server, |
| 9237 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9238 | }; |
| 9239 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9240 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9241 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9242 | .list = nfs4_xattr_list_nfs4_acl, |
| 9243 | .get = nfs4_xattr_get_nfs4_acl, |
| 9244 | .set = nfs4_xattr_set_nfs4_acl, |
| 9245 | }; |
| 9246 | |
| 9247 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9248 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9249 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9250 | &nfs4_xattr_nfs4_label_handler, |
| 9251 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9252 | NULL |
| 9253 | }; |
| 9254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9255 | /* |
| 9256 | * Local variables: |
| 9257 | * c-basic-offset: 8 |
| 9258 | * End: |
| 9259 | */ |