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 | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2388 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2389 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2390 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2391 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2392 | write_seqlock(&state->seqlock); |
| 2393 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2394 | write_sequnlock(&state->seqlock); |
| 2395 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2396 | } |
| 2397 | |
| 2398 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2399 | { |
| 2400 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2401 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2405 | { |
| 2406 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2407 | nfs40_clear_delegation_stateid(state); |
| 2408 | return nfs4_open_expired(sp, state); |
| 2409 | } |
| 2410 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2411 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2412 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2413 | nfs4_stateid *stateid, |
| 2414 | struct rpc_cred *cred) |
| 2415 | { |
| 2416 | int status; |
| 2417 | |
| 2418 | status = nfs41_test_stateid(server, stateid, cred); |
| 2419 | |
| 2420 | switch (status) { |
| 2421 | case -NFS4ERR_EXPIRED: |
| 2422 | case -NFS4ERR_ADMIN_REVOKED: |
| 2423 | case -NFS4ERR_DELEG_REVOKED: |
| 2424 | /* Ack the revoked state to the server */ |
| 2425 | nfs41_free_stateid(server, stateid, cred); |
| 2426 | case -NFS4ERR_BAD_STATEID: |
| 2427 | return status; |
| 2428 | } |
| 2429 | return NFS_OK; |
| 2430 | } |
| 2431 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2432 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2433 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2434 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2435 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2436 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2437 | struct rpc_cred *cred; |
| 2438 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2439 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2440 | /* Get the delegation credential for use by test/free_stateid */ |
| 2441 | rcu_read_lock(); |
| 2442 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2443 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2444 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2445 | return; |
| 2446 | } |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2447 | |
| 2448 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2449 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2450 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2451 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2452 | return; |
| 2453 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2454 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2455 | cred = get_rpccred(delegation->cred); |
| 2456 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2457 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2458 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2459 | if (status != NFS_OK) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame^] | 2460 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2461 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2462 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | /** |
| 2466 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2467 | * |
| 2468 | * @state: NFSv4 state for an inode |
| 2469 | * |
| 2470 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2471 | * Otherwise a negative NFS4ERR value is returned. |
| 2472 | */ |
| 2473 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2474 | { |
| 2475 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2476 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2477 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2478 | int status; |
| 2479 | |
| 2480 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2481 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2482 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2483 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2484 | return -NFS4ERR_BAD_STATEID; |
| 2485 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2486 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2487 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2488 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2489 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2490 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2491 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2492 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2493 | } |
| 2494 | return status; |
| 2495 | } |
| 2496 | |
| 2497 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2498 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2499 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2500 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2501 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2502 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2503 | if (status != NFS_OK) |
| 2504 | status = nfs4_open_expired(sp, state); |
| 2505 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2506 | } |
| 2507 | #endif |
| 2508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2510 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2511 | * fields corresponding to attributes that were used to store the verifier. |
| 2512 | * Make sure we clobber those fields in the later setattr call |
| 2513 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2514 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2515 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2516 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2517 | const u32 *attrset = opendata->o_res.attrset; |
| 2518 | |
| 2519 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2520 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2521 | sattr->ia_valid |= ATTR_ATIME; |
| 2522 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2523 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2524 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2525 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2526 | |
| 2527 | /* Except MODE, it seems harmless of setting twice. */ |
| 2528 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2529 | sattr->ia_valid &= ~ATTR_MODE; |
| 2530 | |
| 2531 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2532 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2533 | } |
| 2534 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2535 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2536 | fmode_t fmode, |
| 2537 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2538 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2539 | { |
| 2540 | struct nfs4_state_owner *sp = opendata->owner; |
| 2541 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2542 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2543 | struct nfs4_state *state; |
| 2544 | unsigned int seq; |
| 2545 | int ret; |
| 2546 | |
| 2547 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2548 | |
| 2549 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2550 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2551 | goto out; |
| 2552 | |
| 2553 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2554 | ret = PTR_ERR(state); |
| 2555 | if (IS_ERR(state)) |
| 2556 | goto out; |
| 2557 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2558 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2559 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2560 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2561 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2562 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2563 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2564 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2565 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2566 | alias = d_exact_alias(dentry, state->inode); |
| 2567 | if (!alias) |
| 2568 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2569 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2570 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2571 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2572 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2573 | } |
| 2574 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2575 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2576 | } |
| 2577 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2578 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2579 | if (ret != 0) |
| 2580 | goto out; |
| 2581 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2582 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2583 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2584 | nfs_inode_attach_open_context(ctx); |
| 2585 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2586 | nfs4_schedule_stateid_recovery(server, state); |
| 2587 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2588 | out: |
| 2589 | return ret; |
| 2590 | } |
| 2591 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2592 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2593 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2595 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2596 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2597 | int flags, |
| 2598 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2599 | struct nfs4_label *label, |
| 2600 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | { |
| 2602 | struct nfs4_state_owner *sp; |
| 2603 | struct nfs4_state *state = NULL; |
| 2604 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2605 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2606 | struct dentry *dentry = ctx->dentry; |
| 2607 | struct rpc_cred *cred = ctx->cred; |
| 2608 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2609 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2610 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2611 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2612 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
| 2614 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2616 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2617 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2619 | goto out_err; |
| 2620 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2621 | status = nfs4_recover_expired_lease(server); |
| 2622 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2623 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2624 | if (d_really_is_positive(dentry)) |
| 2625 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2626 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2627 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2628 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2629 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2630 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2631 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2632 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2634 | if (label) { |
| 2635 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2636 | if (IS_ERR(olabel)) { |
| 2637 | status = PTR_ERR(olabel); |
| 2638 | goto err_opendata_put; |
| 2639 | } |
| 2640 | } |
| 2641 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2642 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2643 | if (!opendata->f_attr.mdsthreshold) { |
| 2644 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2645 | if (!opendata->f_attr.mdsthreshold) |
| 2646 | goto err_free_label; |
| 2647 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2648 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2649 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2650 | if (d_really_is_positive(dentry)) |
| 2651 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2652 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2653 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2654 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2655 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2656 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2657 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2658 | 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] | 2659 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2660 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2661 | /* |
| 2662 | * send create attributes which was not set by open |
| 2663 | * with an extra setattr. |
| 2664 | */ |
| 2665 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2666 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2667 | status = nfs4_do_setattr(state->inode, cred, |
| 2668 | opendata->o_res.f_attr, sattr, |
| 2669 | state, label, olabel); |
| 2670 | if (status == 0) { |
| 2671 | nfs_setattr_update_inode(state->inode, sattr, |
| 2672 | opendata->o_res.f_attr); |
| 2673 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2674 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2675 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2676 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2677 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2678 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2679 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2680 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2681 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2682 | opendata->f_attr.mdsthreshold = NULL; |
| 2683 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2684 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2685 | nfs4_label_free(olabel); |
| 2686 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2687 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2690 | err_free_label: |
| 2691 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2692 | err_opendata_put: |
| 2693 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2694 | err_put_state_owner: |
| 2695 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | return status; |
| 2698 | } |
| 2699 | |
| 2700 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2701 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2702 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2703 | int flags, |
| 2704 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2705 | struct nfs4_label *label, |
| 2706 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2708 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | struct nfs4_exception exception = { }; |
| 2710 | struct nfs4_state *res; |
| 2711 | int status; |
| 2712 | |
| 2713 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2714 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2715 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2716 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | if (status == 0) |
| 2718 | break; |
| 2719 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2720 | * book-keeping w.r.t. state-changing operations |
| 2721 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2722 | * It is actually a sign of a bug on the client or on the server. |
| 2723 | * |
| 2724 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2725 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | * have unhashed the old state_owner for us, and that we can |
| 2727 | * therefore safely retry using a new one. We should still warn |
| 2728 | * the user though... |
| 2729 | */ |
| 2730 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2731 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2732 | " returned a bad sequence-id error!\n", |
| 2733 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | exception.retry = 1; |
| 2735 | continue; |
| 2736 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2737 | /* |
| 2738 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2739 | * state before it received the OPEN_CONFIRM. |
| 2740 | * Recover by retrying the request as per the discussion |
| 2741 | * on Page 181 of RFC3530. |
| 2742 | */ |
| 2743 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2744 | exception.retry = 1; |
| 2745 | continue; |
| 2746 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2747 | if (status == -EAGAIN) { |
| 2748 | /* We must have found a delegation */ |
| 2749 | exception.retry = 1; |
| 2750 | continue; |
| 2751 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2752 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2753 | continue; |
| 2754 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | status, &exception)); |
| 2756 | } while (exception.retry); |
| 2757 | return res; |
| 2758 | } |
| 2759 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2760 | static int _nfs4_do_setattr(struct inode *inode, |
| 2761 | struct nfs_setattrargs *arg, |
| 2762 | struct nfs_setattrres *res, |
| 2763 | struct rpc_cred *cred, |
| 2764 | struct nfs4_state *state) |
| 2765 | { |
| 2766 | struct nfs_server *server = NFS_SERVER(inode); |
| 2767 | struct rpc_message msg = { |
| 2768 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2769 | .rpc_argp = arg, |
| 2770 | .rpc_resp = res, |
| 2771 | .rpc_cred = cred, |
| 2772 | }; |
| 2773 | struct rpc_cred *delegation_cred = NULL; |
| 2774 | unsigned long timestamp = jiffies; |
| 2775 | fmode_t fmode; |
| 2776 | bool truncate; |
| 2777 | int status; |
| 2778 | |
| 2779 | nfs_fattr_init(res->fattr); |
| 2780 | |
| 2781 | /* Servers should only apply open mode checks for file size changes */ |
| 2782 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2783 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2784 | |
| 2785 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2786 | /* Use that stateid */ |
| 2787 | } else if (truncate && state != NULL) { |
| 2788 | struct nfs_lockowner lockowner = { |
| 2789 | .l_owner = current->files, |
| 2790 | .l_pid = current->tgid, |
| 2791 | }; |
| 2792 | if (!nfs4_valid_open_stateid(state)) |
| 2793 | return -EBADF; |
| 2794 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2795 | &arg->stateid, &delegation_cred) == -EIO) |
| 2796 | return -EBADF; |
| 2797 | } else |
| 2798 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2799 | if (delegation_cred) |
| 2800 | msg.rpc_cred = delegation_cred; |
| 2801 | |
| 2802 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2803 | |
| 2804 | put_rpccred(delegation_cred); |
| 2805 | if (status == 0 && state != NULL) |
| 2806 | renew_lease(server, timestamp); |
| 2807 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2808 | return status; |
| 2809 | } |
| 2810 | |
| 2811 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2812 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2813 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2814 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2816 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2818 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | .iap = sattr, |
| 2820 | .server = server, |
| 2821 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2822 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | }; |
| 2824 | struct nfs_setattrres res = { |
| 2825 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2826 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | .server = server, |
| 2828 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2829 | struct nfs4_exception exception = { |
| 2830 | .state = state, |
| 2831 | .inode = inode, |
| 2832 | .stateid = &arg.stateid, |
| 2833 | }; |
| 2834 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2836 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2837 | if (ilabel) |
| 2838 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2841 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2842 | switch (err) { |
| 2843 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2844 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2845 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2846 | "applying open mode checks to " |
| 2847 | "a SETATTR that is not " |
| 2848 | "changing file size.\n", |
| 2849 | server->nfs_client->cl_hostname); |
| 2850 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2851 | if (state && !(state->state & FMODE_WRITE)) { |
| 2852 | err = -EBADF; |
| 2853 | if (sattr->ia_valid & ATTR_OPEN) |
| 2854 | err = -EACCES; |
| 2855 | goto out; |
| 2856 | } |
| 2857 | } |
| 2858 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2860 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | return err; |
| 2862 | } |
| 2863 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2864 | static bool |
| 2865 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2866 | { |
| 2867 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2868 | return false; |
| 2869 | |
| 2870 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2871 | } |
| 2872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | struct nfs4_closedata { |
| 2874 | struct inode *inode; |
| 2875 | struct nfs4_state *state; |
| 2876 | struct nfs_closeargs arg; |
| 2877 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2878 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2879 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2880 | bool roc; |
| 2881 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | }; |
| 2883 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2884 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2885 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2886 | struct nfs4_closedata *calldata = data; |
| 2887 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2888 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2889 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2890 | if (calldata->roc) |
| 2891 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2892 | nfs4_put_open_state(calldata->state); |
| 2893 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2894 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2895 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2896 | kfree(calldata); |
| 2897 | } |
| 2898 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2899 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2901 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2904 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2906 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2907 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2908 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2909 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | /* hmm. we are done with the inode, and in the process of freeing |
| 2911 | * the state_owner. we keep this around to process errors |
| 2912 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | switch (task->tk_status) { |
| 2914 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2915 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2916 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2917 | pnfs_roc_set_barrier(state->inode, |
| 2918 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2919 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2920 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2921 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2923 | case -NFS4ERR_OLD_STATEID: |
| 2924 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2926 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2927 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2928 | rpc_restart_call_prepare(task); |
| 2929 | goto out_release; |
| 2930 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2931 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2932 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2934 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2935 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2936 | goto out_release; |
| 2937 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2939 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2940 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2941 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2942 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2943 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2944 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2947 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2949 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2950 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2951 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2952 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2953 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2954 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2955 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2956 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2957 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2958 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2959 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2960 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2961 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2962 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2963 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2964 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2965 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2966 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2967 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2968 | if (state->n_rdonly == 0) |
| 2969 | call_close |= is_rdonly; |
| 2970 | else if (is_rdonly) |
| 2971 | calldata->arg.fmode |= FMODE_READ; |
| 2972 | if (state->n_wronly == 0) |
| 2973 | call_close |= is_wronly; |
| 2974 | else if (is_wronly) |
| 2975 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2976 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2977 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2978 | } else if (is_rdwr) |
| 2979 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2980 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2981 | if (!nfs4_valid_open_stateid(state)) |
| 2982 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2983 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2984 | |
| 2985 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2986 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2987 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2988 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2989 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2990 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2991 | nfs_release_seqid(calldata->arg.seqid); |
| 2992 | goto out_wait; |
| 2993 | } |
| 2994 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2995 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2996 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2997 | if (calldata->roc) |
| 2998 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2999 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3000 | calldata->arg.share_access = |
| 3001 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3002 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3003 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3004 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3005 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3006 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3007 | &calldata->arg.seq_args, |
| 3008 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3009 | task) != 0) |
| 3010 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3011 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3012 | return; |
| 3013 | out_no_action: |
| 3014 | task->tk_action = NULL; |
| 3015 | out_wait: |
| 3016 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3019 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3020 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3021 | .rpc_call_done = nfs4_close_done, |
| 3022 | .rpc_release = nfs4_free_closedata, |
| 3023 | }; |
| 3024 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3025 | static bool nfs4_roc(struct inode *inode) |
| 3026 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3027 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3028 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3029 | return pnfs_roc(inode); |
| 3030 | } |
| 3031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | /* |
| 3033 | * It is possible for data to be read/written from a mem-mapped file |
| 3034 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3035 | * This means that we can't safely call nfsv4 close on a file until |
| 3036 | * the inode is cleared. This in turn means that we are not good |
| 3037 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3038 | * share state even when we are done with one of the three share |
| 3039 | * stateid's in the inode. |
| 3040 | * |
| 3041 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3042 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3043 | 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] | 3044 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3045 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3046 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3048 | struct nfs4_state_owner *sp = state->owner; |
| 3049 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3050 | struct rpc_message msg = { |
| 3051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3052 | .rpc_cred = state->owner->so_cred, |
| 3053 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3054 | struct rpc_task_setup task_setup_data = { |
| 3055 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3056 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3057 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3058 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3059 | .flags = RPC_TASK_ASYNC, |
| 3060 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3061 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3063 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3064 | &task_setup_data.rpc_client, &msg); |
| 3065 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3066 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3068 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3069 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3070 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3072 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3074 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3075 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3076 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3077 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3078 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3079 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3080 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3081 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3082 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3083 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3084 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3085 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3086 | msg.rpc_argp = &calldata->arg; |
| 3087 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3088 | task_setup_data.callback_data = calldata; |
| 3089 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3090 | if (IS_ERR(task)) |
| 3091 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3092 | status = 0; |
| 3093 | if (wait) |
| 3094 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3095 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3096 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3097 | out_free_calldata: |
| 3098 | kfree(calldata); |
| 3099 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3100 | nfs4_put_open_state(state); |
| 3101 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3102 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3105 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3106 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3107 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3110 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3111 | |
| 3112 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3114 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3115 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3116 | |
| 3117 | nfs4_label_release_security(label); |
| 3118 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3119 | if (IS_ERR(state)) |
| 3120 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3121 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3124 | 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] | 3125 | { |
| 3126 | if (ctx->state == NULL) |
| 3127 | return; |
| 3128 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3129 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3130 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3131 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3134 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3135 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3136 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3139 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3140 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3141 | struct nfs4_server_caps_arg args = { |
| 3142 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3143 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | struct nfs4_server_caps_res res = {}; |
| 3146 | struct rpc_message msg = { |
| 3147 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3148 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | .rpc_resp = &res, |
| 3150 | }; |
| 3151 | int status; |
| 3152 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3153 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3154 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3155 | FATTR4_WORD0_LINK_SUPPORT | |
| 3156 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3157 | FATTR4_WORD0_ACLSUPPORT; |
| 3158 | if (minorversion) |
| 3159 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3160 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3161 | 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] | 3162 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3163 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3164 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3165 | case 0: |
| 3166 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3167 | res.attr_bitmask[2] = 0; |
| 3168 | break; |
| 3169 | case 1: |
| 3170 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3171 | break; |
| 3172 | case 2: |
| 3173 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3176 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3177 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3178 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3179 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3180 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3181 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3182 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3183 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | server->caps |= NFS_CAP_ACLS; |
| 3185 | if (res.has_links != 0) |
| 3186 | server->caps |= NFS_CAP_HARDLINKS; |
| 3187 | if (res.has_symlinks != 0) |
| 3188 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3189 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3190 | server->caps |= NFS_CAP_FILEID; |
| 3191 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3192 | server->caps |= NFS_CAP_MODE; |
| 3193 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3194 | server->caps |= NFS_CAP_NLINK; |
| 3195 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3196 | server->caps |= NFS_CAP_OWNER; |
| 3197 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3198 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3199 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3200 | server->caps |= NFS_CAP_ATIME; |
| 3201 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3202 | server->caps |= NFS_CAP_CTIME; |
| 3203 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3204 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3205 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3206 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3207 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3208 | #endif |
| 3209 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3210 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3211 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3212 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3213 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3214 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3215 | 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] | 3216 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3217 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3218 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3220 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | return status; |
| 3224 | } |
| 3225 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3226 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { |
| 3228 | struct nfs4_exception exception = { }; |
| 3229 | int err; |
| 3230 | do { |
| 3231 | err = nfs4_handle_exception(server, |
| 3232 | _nfs4_server_capabilities(server, fhandle), |
| 3233 | &exception); |
| 3234 | } while (exception.retry); |
| 3235 | return err; |
| 3236 | } |
| 3237 | |
| 3238 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3239 | struct nfs_fsinfo *info) |
| 3240 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3241 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3243 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | }; |
| 3245 | struct nfs4_lookup_res res = { |
| 3246 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3247 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | .fh = fhandle, |
| 3249 | }; |
| 3250 | struct rpc_message msg = { |
| 3251 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3252 | .rpc_argp = &args, |
| 3253 | .rpc_resp = &res, |
| 3254 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3255 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3256 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3257 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3258 | /* |
| 3259 | * Process the label in the upcoming getfattr |
| 3260 | */ |
| 3261 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3262 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3263 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3264 | 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] | 3265 | } |
| 3266 | |
| 3267 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3268 | struct nfs_fsinfo *info) |
| 3269 | { |
| 3270 | struct nfs4_exception exception = { }; |
| 3271 | int err; |
| 3272 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3273 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3274 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3275 | switch (err) { |
| 3276 | case 0: |
| 3277 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3278 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3279 | default: |
| 3280 | err = nfs4_handle_exception(server, err, &exception); |
| 3281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3283 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | return err; |
| 3285 | } |
| 3286 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3287 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3288 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3289 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3290 | struct rpc_auth_create_args auth_args = { |
| 3291 | .pseudoflavor = flavor, |
| 3292 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3293 | struct rpc_auth *auth; |
| 3294 | int ret; |
| 3295 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3296 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3297 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3298 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3299 | goto out; |
| 3300 | } |
| 3301 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3302 | out: |
| 3303 | return ret; |
| 3304 | } |
| 3305 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3306 | /* |
| 3307 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3308 | * |
| 3309 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3310 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3311 | * |
| 3312 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3313 | * negative errno value. |
| 3314 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3315 | 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] | 3316 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3318 | /* Per 3530bis 15.33.5 */ |
| 3319 | static const rpc_authflavor_t flav_array[] = { |
| 3320 | RPC_AUTH_GSS_KRB5P, |
| 3321 | RPC_AUTH_GSS_KRB5I, |
| 3322 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3323 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3324 | RPC_AUTH_NULL, |
| 3325 | }; |
| 3326 | int status = -EPERM; |
| 3327 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3329 | if (server->auth_info.flavor_len > 0) { |
| 3330 | /* try each flavor specified by user */ |
| 3331 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3332 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3333 | server->auth_info.flavors[i]); |
| 3334 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3335 | continue; |
| 3336 | break; |
| 3337 | } |
| 3338 | } else { |
| 3339 | /* no flavors specified by user, try default list */ |
| 3340 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3341 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3342 | flav_array[i]); |
| 3343 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3344 | continue; |
| 3345 | break; |
| 3346 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3347 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3348 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3349 | /* |
| 3350 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3351 | * to access the mount. It could also mean that we tried to mount |
| 3352 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3353 | * existing mount programs don't handle -EACCES very well so it should |
| 3354 | * be mapped to -EPERM instead. |
| 3355 | */ |
| 3356 | if (status == -EACCES) |
| 3357 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3358 | return status; |
| 3359 | } |
| 3360 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3361 | /** |
| 3362 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3363 | * @server: initialized nfs_server handle |
| 3364 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3365 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3366 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3367 | * |
| 3368 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3369 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3370 | 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] | 3371 | struct nfs_fsinfo *info, |
| 3372 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3373 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3374 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3375 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3376 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3377 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3378 | |
| 3379 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3380 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3381 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | if (status == 0) |
| 3384 | status = nfs4_server_capabilities(server, fhandle); |
| 3385 | if (status == 0) |
| 3386 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3387 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3388 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3391 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3392 | struct nfs_fsinfo *info) |
| 3393 | { |
| 3394 | int error; |
| 3395 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3396 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3397 | |
| 3398 | error = nfs4_server_capabilities(server, mntfh); |
| 3399 | if (error < 0) { |
| 3400 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3401 | return error; |
| 3402 | } |
| 3403 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3404 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3405 | if (IS_ERR(label)) |
| 3406 | return PTR_ERR(label); |
| 3407 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3408 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3409 | if (error < 0) { |
| 3410 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3411 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3415 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3416 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3417 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3418 | err_free_label: |
| 3419 | nfs4_label_free(label); |
| 3420 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3421 | return error; |
| 3422 | } |
| 3423 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3424 | /* |
| 3425 | * Get locations and (maybe) other attributes of a referral. |
| 3426 | * Note that we'll actually follow the referral later when |
| 3427 | * we detect fsid mismatch in inode revalidation |
| 3428 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3429 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3430 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3431 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3432 | { |
| 3433 | int status = -ENOMEM; |
| 3434 | struct page *page = NULL; |
| 3435 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3436 | |
| 3437 | page = alloc_page(GFP_KERNEL); |
| 3438 | if (page == NULL) |
| 3439 | goto out; |
| 3440 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3441 | if (locations == NULL) |
| 3442 | goto out; |
| 3443 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3444 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3445 | if (status != 0) |
| 3446 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3447 | |
| 3448 | /* |
| 3449 | * If the fsid didn't change, this is a migration event, not a |
| 3450 | * referral. Cause us to drop into the exception handler, which |
| 3451 | * will kick off migration recovery. |
| 3452 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3453 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3454 | dprintk("%s: server did not return a different fsid for" |
| 3455 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3456 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3457 | goto out; |
| 3458 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3459 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3460 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3461 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3462 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3463 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3464 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3465 | out: |
| 3466 | if (page) |
| 3467 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3468 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3469 | return status; |
| 3470 | } |
| 3471 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3472 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3473 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | { |
| 3475 | struct nfs4_getattr_arg args = { |
| 3476 | .fh = fhandle, |
| 3477 | .bitmask = server->attr_bitmask, |
| 3478 | }; |
| 3479 | struct nfs4_getattr_res res = { |
| 3480 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3481 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | .server = server, |
| 3483 | }; |
| 3484 | struct rpc_message msg = { |
| 3485 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3486 | .rpc_argp = &args, |
| 3487 | .rpc_resp = &res, |
| 3488 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3489 | |
| 3490 | args.bitmask = nfs4_bitmask(server, label); |
| 3491 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3492 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3493 | 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] | 3494 | } |
| 3495 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3496 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3497 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | { |
| 3499 | struct nfs4_exception exception = { }; |
| 3500 | int err; |
| 3501 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3502 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3503 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3504 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | &exception); |
| 3506 | } while (exception.retry); |
| 3507 | return err; |
| 3508 | } |
| 3509 | |
| 3510 | /* |
| 3511 | * The file is not closed if it is opened due to the a request to change |
| 3512 | * the size of the file. The open call will not be needed once the |
| 3513 | * VFS layer lookup-intents are implemented. |
| 3514 | * |
| 3515 | * Close is called when the inode is destroyed. |
| 3516 | * If we haven't opened the file for O_WRONLY, we |
| 3517 | * need to in the size_change case to obtain a stateid. |
| 3518 | * |
| 3519 | * Got race? |
| 3520 | * Because OPEN is always done by name in nfsv4, it is |
| 3521 | * possible that we opened a different file by the same |
| 3522 | * name. We can recognize this race condition, but we |
| 3523 | * can't do anything about it besides returning an error. |
| 3524 | * |
| 3525 | * This will be fixed with VFS changes (lookup-intent). |
| 3526 | */ |
| 3527 | static int |
| 3528 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3529 | struct iattr *sattr) |
| 3530 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3531 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3532 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3533 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3534 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | int status; |
| 3536 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3537 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3538 | sattr->ia_valid & ATTR_SIZE && |
| 3539 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3540 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3541 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3542 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3544 | /* Deal with open(O_TRUNC) */ |
| 3545 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3546 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3547 | |
| 3548 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3549 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3550 | return 0; |
| 3551 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3552 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3553 | if (sattr->ia_valid & ATTR_FILE) { |
| 3554 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3555 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3556 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3557 | if (ctx) { |
| 3558 | cred = ctx->cred; |
| 3559 | state = ctx->state; |
| 3560 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3561 | } |
| 3562 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3563 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3564 | if (IS_ERR(label)) |
| 3565 | return PTR_ERR(label); |
| 3566 | |
| 3567 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3568 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3569 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3570 | nfs_setsecurity(inode, fattr, label); |
| 3571 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3572 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | return status; |
| 3574 | } |
| 3575 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3576 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3577 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3578 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3579 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3580 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3581 | int status; |
| 3582 | struct nfs4_lookup_arg args = { |
| 3583 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3584 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3585 | .name = name, |
| 3586 | }; |
| 3587 | struct nfs4_lookup_res res = { |
| 3588 | .server = server, |
| 3589 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3590 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3591 | .fh = fhandle, |
| 3592 | }; |
| 3593 | struct rpc_message msg = { |
| 3594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3595 | .rpc_argp = &args, |
| 3596 | .rpc_resp = &res, |
| 3597 | }; |
| 3598 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3599 | args.bitmask = nfs4_bitmask(server, label); |
| 3600 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3601 | nfs_fattr_init(fattr); |
| 3602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3604 | 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] | 3605 | dprintk("NFS reply lookup: %d\n", status); |
| 3606 | return status; |
| 3607 | } |
| 3608 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3609 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3610 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3611 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3612 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3613 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3614 | fattr->nlink = 2; |
| 3615 | } |
| 3616 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3617 | 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] | 3618 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3619 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3620 | { |
| 3621 | struct nfs4_exception exception = { }; |
| 3622 | struct rpc_clnt *client = *clnt; |
| 3623 | int err; |
| 3624 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3625 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3626 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3627 | switch (err) { |
| 3628 | case -NFS4ERR_BADNAME: |
| 3629 | err = -ENOENT; |
| 3630 | goto out; |
| 3631 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3632 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3633 | if (err == -NFS4ERR_MOVED) |
| 3634 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3635 | goto out; |
| 3636 | case -NFS4ERR_WRONGSEC: |
| 3637 | err = -EPERM; |
| 3638 | if (client != *clnt) |
| 3639 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3640 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3641 | if (IS_ERR(client)) |
| 3642 | return PTR_ERR(client); |
| 3643 | |
| 3644 | exception.retry = 1; |
| 3645 | break; |
| 3646 | default: |
| 3647 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3648 | } |
| 3649 | } while (exception.retry); |
| 3650 | |
| 3651 | out: |
| 3652 | if (err == 0) |
| 3653 | *clnt = client; |
| 3654 | else if (client != *clnt) |
| 3655 | rpc_shutdown_client(client); |
| 3656 | |
| 3657 | return err; |
| 3658 | } |
| 3659 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3660 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3661 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3662 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3664 | int status; |
| 3665 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3666 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3667 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3668 | if (client != NFS_CLIENT(dir)) { |
| 3669 | rpc_shutdown_client(client); |
| 3670 | nfs_fixup_secinfo_attributes(fattr); |
| 3671 | } |
| 3672 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | } |
| 3674 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3675 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3676 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3677 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3678 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3679 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3680 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3681 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3682 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3683 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3684 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3685 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3686 | } |
| 3687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3689 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3690 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | struct nfs4_accessargs args = { |
| 3692 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3693 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3695 | struct nfs4_accessres res = { |
| 3696 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3697 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | struct rpc_message msg = { |
| 3699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3700 | .rpc_argp = &args, |
| 3701 | .rpc_resp = &res, |
| 3702 | .rpc_cred = entry->cred, |
| 3703 | }; |
| 3704 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3705 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | |
| 3707 | /* |
| 3708 | * Determine which access bits we want to ask for... |
| 3709 | */ |
| 3710 | if (mode & MAY_READ) |
| 3711 | args.access |= NFS4_ACCESS_READ; |
| 3712 | if (S_ISDIR(inode->i_mode)) { |
| 3713 | if (mode & MAY_WRITE) |
| 3714 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3715 | if (mode & MAY_EXEC) |
| 3716 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3717 | } else { |
| 3718 | if (mode & MAY_WRITE) |
| 3719 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3720 | if (mode & MAY_EXEC) |
| 3721 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3722 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3723 | |
| 3724 | res.fattr = nfs_alloc_fattr(); |
| 3725 | if (res.fattr == NULL) |
| 3726 | return -ENOMEM; |
| 3727 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3728 | 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] | 3729 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3730 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3731 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3733 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | return status; |
| 3735 | } |
| 3736 | |
| 3737 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3738 | { |
| 3739 | struct nfs4_exception exception = { }; |
| 3740 | int err; |
| 3741 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3742 | err = _nfs4_proc_access(inode, entry); |
| 3743 | trace_nfs4_access(inode, err); |
| 3744 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | &exception); |
| 3746 | } while (exception.retry); |
| 3747 | return err; |
| 3748 | } |
| 3749 | |
| 3750 | /* |
| 3751 | * TODO: For the time being, we don't try to get any attributes |
| 3752 | * along with any of the zero-copy operations READ, READDIR, |
| 3753 | * READLINK, WRITE. |
| 3754 | * |
| 3755 | * In the case of the first three, we want to put the GETATTR |
| 3756 | * after the read-type operation -- this is because it is hard |
| 3757 | * to predict the length of a GETATTR response in v4, and thus |
| 3758 | * align the READ data correctly. This means that the GETATTR |
| 3759 | * may end up partially falling into the page cache, and we should |
| 3760 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3761 | * To do this efficiently, we need to know the total length |
| 3762 | * of data received, which doesn't seem to be available outside |
| 3763 | * of the RPC layer. |
| 3764 | * |
| 3765 | * In the case of WRITE, we also want to put the GETATTR after |
| 3766 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3767 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | * |
| 3769 | * Both of these changes to the XDR layer would in fact be quite |
| 3770 | * minor, but I decided to leave them for a subsequent patch. |
| 3771 | */ |
| 3772 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3773 | unsigned int pgbase, unsigned int pglen) |
| 3774 | { |
| 3775 | struct nfs4_readlink args = { |
| 3776 | .fh = NFS_FH(inode), |
| 3777 | .pgbase = pgbase, |
| 3778 | .pglen = pglen, |
| 3779 | .pages = &page, |
| 3780 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3781 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | struct rpc_message msg = { |
| 3783 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3784 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3785 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | }; |
| 3787 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3788 | 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] | 3789 | } |
| 3790 | |
| 3791 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3792 | unsigned int pgbase, unsigned int pglen) |
| 3793 | { |
| 3794 | struct nfs4_exception exception = { }; |
| 3795 | int err; |
| 3796 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3797 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3798 | trace_nfs4_readlink(inode, err); |
| 3799 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | &exception); |
| 3801 | } while (exception.retry); |
| 3802 | return err; |
| 3803 | } |
| 3804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3806 | * 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] | 3807 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | static int |
| 3809 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3810 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3812 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3813 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | int status = 0; |
| 3816 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3817 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3818 | if (IS_ERR(ctx)) |
| 3819 | return PTR_ERR(ctx); |
| 3820 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3821 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3822 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3823 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3824 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | if (IS_ERR(state)) { |
| 3826 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3827 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3830 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3831 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | return status; |
| 3833 | } |
| 3834 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3835 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3837 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3838 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3840 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3842 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3843 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3844 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3846 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3847 | .rpc_argp = &args, |
| 3848 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3850 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3851 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3852 | 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] | 3853 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3854 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | return status; |
| 3856 | } |
| 3857 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3858 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | { |
| 3860 | struct nfs4_exception exception = { }; |
| 3861 | int err; |
| 3862 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3863 | err = _nfs4_proc_remove(dir, name); |
| 3864 | trace_nfs4_remove(dir, name, err); |
| 3865 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | &exception); |
| 3867 | } while (exception.retry); |
| 3868 | return err; |
| 3869 | } |
| 3870 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3871 | 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] | 3872 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3873 | struct nfs_server *server = NFS_SERVER(dir); |
| 3874 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3875 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3877 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3879 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3880 | |
| 3881 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3884 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3885 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3886 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3887 | &data->args.seq_args, |
| 3888 | &data->res.seq_res, |
| 3889 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3892 | 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] | 3893 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3894 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3895 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3896 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3897 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3898 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3899 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3900 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3901 | return 0; |
| 3902 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3903 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3906 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3907 | { |
| 3908 | struct nfs_server *server = NFS_SERVER(dir); |
| 3909 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3910 | struct nfs_renameres *res = msg->rpc_resp; |
| 3911 | |
| 3912 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3913 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3914 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3915 | } |
| 3916 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3917 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3918 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3919 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3920 | &data->args.seq_args, |
| 3921 | &data->res.seq_res, |
| 3922 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3926 | struct inode *new_dir) |
| 3927 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3928 | struct nfs_renamedata *data = task->tk_calldata; |
| 3929 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3930 | |
| 3931 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3932 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3933 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3934 | return 0; |
| 3935 | |
| 3936 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3937 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3938 | return 1; |
| 3939 | } |
| 3940 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3941 | 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] | 3942 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3943 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | struct nfs4_link_arg arg = { |
| 3945 | .fh = NFS_FH(inode), |
| 3946 | .dir_fh = NFS_FH(dir), |
| 3947 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3948 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3950 | struct nfs4_link_res res = { |
| 3951 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3952 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3953 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | struct rpc_message msg = { |
| 3955 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3956 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3957 | .rpc_resp = &res, |
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 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3961 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3962 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3963 | goto out; |
| 3964 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3965 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3966 | if (IS_ERR(res.label)) { |
| 3967 | status = PTR_ERR(res.label); |
| 3968 | goto out; |
| 3969 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3970 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3971 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3972 | 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] | 3973 | if (!status) { |
| 3974 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3975 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3976 | if (!status) |
| 3977 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3978 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3979 | |
| 3980 | |
| 3981 | nfs4_label_free(res.label); |
| 3982 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3983 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3984 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | return status; |
| 3986 | } |
| 3987 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3988 | 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] | 3989 | { |
| 3990 | struct nfs4_exception exception = { }; |
| 3991 | int err; |
| 3992 | do { |
| 3993 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3994 | _nfs4_proc_link(inode, dir, name), |
| 3995 | &exception); |
| 3996 | } while (exception.retry); |
| 3997 | return err; |
| 3998 | } |
| 3999 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4000 | struct nfs4_createdata { |
| 4001 | struct rpc_message msg; |
| 4002 | struct nfs4_create_arg arg; |
| 4003 | struct nfs4_create_res res; |
| 4004 | struct nfs_fh fh; |
| 4005 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4006 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4007 | }; |
| 4008 | |
| 4009 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4010 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4011 | { |
| 4012 | struct nfs4_createdata *data; |
| 4013 | |
| 4014 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4015 | if (data != NULL) { |
| 4016 | struct nfs_server *server = NFS_SERVER(dir); |
| 4017 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4018 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4019 | if (IS_ERR(data->label)) |
| 4020 | goto out_free; |
| 4021 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4022 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4023 | data->msg.rpc_argp = &data->arg; |
| 4024 | data->msg.rpc_resp = &data->res; |
| 4025 | data->arg.dir_fh = NFS_FH(dir); |
| 4026 | data->arg.server = server; |
| 4027 | data->arg.name = name; |
| 4028 | data->arg.attrs = sattr; |
| 4029 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4030 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4031 | data->res.server = server; |
| 4032 | data->res.fh = &data->fh; |
| 4033 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4034 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4035 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4036 | } |
| 4037 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4038 | out_free: |
| 4039 | kfree(data); |
| 4040 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4044 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4045 | 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] | 4046 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4047 | if (status == 0) { |
| 4048 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4049 | 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] | 4050 | } |
| 4051 | return status; |
| 4052 | } |
| 4053 | |
| 4054 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4055 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4056 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4057 | kfree(data); |
| 4058 | } |
| 4059 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4060 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4061 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4062 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4064 | struct nfs4_createdata *data; |
| 4065 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4067 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4068 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4069 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4070 | status = -ENOMEM; |
| 4071 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4072 | if (data == NULL) |
| 4073 | goto out; |
| 4074 | |
| 4075 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4076 | data->arg.u.symlink.pages = &page; |
| 4077 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4078 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4080 | status = nfs4_do_create(dir, dentry, data); |
| 4081 | |
| 4082 | nfs4_free_createdata(data); |
| 4083 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | return status; |
| 4085 | } |
| 4086 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4087 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4088 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | { |
| 4090 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4091 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4093 | |
| 4094 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4097 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4098 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4099 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | &exception); |
| 4101 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4102 | |
| 4103 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | return err; |
| 4105 | } |
| 4106 | |
| 4107 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4108 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4110 | struct nfs4_createdata *data; |
| 4111 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4113 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4114 | if (data == NULL) |
| 4115 | goto out; |
| 4116 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4117 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4118 | status = nfs4_do_create(dir, dentry, data); |
| 4119 | |
| 4120 | nfs4_free_createdata(data); |
| 4121 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | return status; |
| 4123 | } |
| 4124 | |
| 4125 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4126 | struct iattr *sattr) |
| 4127 | { |
| 4128 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4129 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4131 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4132 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4133 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4134 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4136 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4137 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4138 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | &exception); |
| 4140 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4141 | nfs4_label_release_security(label); |
| 4142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | return err; |
| 4144 | } |
| 4145 | |
| 4146 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4147 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4149 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | struct nfs4_readdir_arg args = { |
| 4151 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4152 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | .pgbase = 0, |
| 4154 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4155 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4156 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | }; |
| 4158 | struct nfs4_readdir_res res; |
| 4159 | struct rpc_message msg = { |
| 4160 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4161 | .rpc_argp = &args, |
| 4162 | .rpc_resp = &res, |
| 4163 | .rpc_cred = cred, |
| 4164 | }; |
| 4165 | int status; |
| 4166 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4167 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4168 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4169 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4170 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4172 | 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] | 4173 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4174 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4175 | status += args.pgbase; |
| 4176 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4177 | |
| 4178 | nfs_invalidate_atime(dir); |
| 4179 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4180 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | return status; |
| 4182 | } |
| 4183 | |
| 4184 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4185 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | { |
| 4187 | struct nfs4_exception exception = { }; |
| 4188 | int err; |
| 4189 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4190 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4191 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4192 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4193 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | &exception); |
| 4195 | } while (exception.retry); |
| 4196 | return err; |
| 4197 | } |
| 4198 | |
| 4199 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4200 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4202 | struct nfs4_createdata *data; |
| 4203 | int mode = sattr->ia_mode; |
| 4204 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4206 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4207 | if (data == NULL) |
| 4208 | goto out; |
| 4209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4213 | data->arg.ftype = NF4BLK; |
| 4214 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4215 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | } |
| 4217 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4218 | data->arg.ftype = NF4CHR; |
| 4219 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4220 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4221 | } else if (!S_ISSOCK(mode)) { |
| 4222 | status = -EINVAL; |
| 4223 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4225 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4226 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4227 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4228 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4229 | nfs4_free_createdata(data); |
| 4230 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | return status; |
| 4232 | } |
| 4233 | |
| 4234 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4235 | struct iattr *sattr, dev_t rdev) |
| 4236 | { |
| 4237 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4238 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4240 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4241 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4242 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4243 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4245 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4246 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4247 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | &exception); |
| 4249 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4250 | |
| 4251 | nfs4_label_release_security(label); |
| 4252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | return err; |
| 4254 | } |
| 4255 | |
| 4256 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4257 | struct nfs_fsstat *fsstat) |
| 4258 | { |
| 4259 | struct nfs4_statfs_arg args = { |
| 4260 | .fh = fhandle, |
| 4261 | .bitmask = server->attr_bitmask, |
| 4262 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4263 | struct nfs4_statfs_res res = { |
| 4264 | .fsstat = fsstat, |
| 4265 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | struct rpc_message msg = { |
| 4267 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4268 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4269 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | }; |
| 4271 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4272 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4273 | 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] | 4274 | } |
| 4275 | |
| 4276 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4277 | { |
| 4278 | struct nfs4_exception exception = { }; |
| 4279 | int err; |
| 4280 | do { |
| 4281 | err = nfs4_handle_exception(server, |
| 4282 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4283 | &exception); |
| 4284 | } while (exception.retry); |
| 4285 | return err; |
| 4286 | } |
| 4287 | |
| 4288 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4289 | struct nfs_fsinfo *fsinfo) |
| 4290 | { |
| 4291 | struct nfs4_fsinfo_arg args = { |
| 4292 | .fh = fhandle, |
| 4293 | .bitmask = server->attr_bitmask, |
| 4294 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4295 | struct nfs4_fsinfo_res res = { |
| 4296 | .fsinfo = fsinfo, |
| 4297 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | struct rpc_message msg = { |
| 4299 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4300 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4301 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | }; |
| 4303 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4304 | 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] | 4305 | } |
| 4306 | |
| 4307 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4308 | { |
| 4309 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4310 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | int err; |
| 4312 | |
| 4313 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4314 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4315 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4316 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4317 | nfs4_set_lease_period(server->nfs_client, |
| 4318 | fsinfo->lease_time * HZ, |
| 4319 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4320 | break; |
| 4321 | } |
| 4322 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | } while (exception.retry); |
| 4324 | return err; |
| 4325 | } |
| 4326 | |
| 4327 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4328 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4329 | int error; |
| 4330 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4331 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4332 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4333 | if (error == 0) { |
| 4334 | /* block layout checks this! */ |
| 4335 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4336 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4337 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4338 | |
| 4339 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4343 | struct nfs_pathconf *pathconf) |
| 4344 | { |
| 4345 | struct nfs4_pathconf_arg args = { |
| 4346 | .fh = fhandle, |
| 4347 | .bitmask = server->attr_bitmask, |
| 4348 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4349 | struct nfs4_pathconf_res res = { |
| 4350 | .pathconf = pathconf, |
| 4351 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | struct rpc_message msg = { |
| 4353 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4354 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4355 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | }; |
| 4357 | |
| 4358 | /* None of the pathconf attributes are mandatory to implement */ |
| 4359 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4360 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4361 | return 0; |
| 4362 | } |
| 4363 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4364 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4365 | 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] | 4366 | } |
| 4367 | |
| 4368 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4369 | struct nfs_pathconf *pathconf) |
| 4370 | { |
| 4371 | struct nfs4_exception exception = { }; |
| 4372 | int err; |
| 4373 | |
| 4374 | do { |
| 4375 | err = nfs4_handle_exception(server, |
| 4376 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4377 | &exception); |
| 4378 | } while (exception.retry); |
| 4379 | return err; |
| 4380 | } |
| 4381 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4382 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4383 | const struct nfs_open_context *ctx, |
| 4384 | const struct nfs_lock_context *l_ctx, |
| 4385 | fmode_t fmode) |
| 4386 | { |
| 4387 | const struct nfs_lockowner *lockowner = NULL; |
| 4388 | |
| 4389 | if (l_ctx != NULL) |
| 4390 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4391 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4392 | } |
| 4393 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4394 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4395 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4396 | const struct nfs_open_context *ctx, |
| 4397 | const struct nfs_lock_context *l_ctx, |
| 4398 | fmode_t fmode) |
| 4399 | { |
| 4400 | nfs4_stateid current_stateid; |
| 4401 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4402 | /* If the current stateid represents a lost lock, then exit */ |
| 4403 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4404 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4405 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4406 | } |
| 4407 | |
| 4408 | static bool nfs4_error_stateid_expired(int err) |
| 4409 | { |
| 4410 | switch (err) { |
| 4411 | case -NFS4ERR_DELEG_REVOKED: |
| 4412 | case -NFS4ERR_ADMIN_REVOKED: |
| 4413 | case -NFS4ERR_BAD_STATEID: |
| 4414 | case -NFS4ERR_STALE_STATEID: |
| 4415 | case -NFS4ERR_OLD_STATEID: |
| 4416 | case -NFS4ERR_OPENMODE: |
| 4417 | case -NFS4ERR_EXPIRED: |
| 4418 | return true; |
| 4419 | } |
| 4420 | return false; |
| 4421 | } |
| 4422 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4423 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4424 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4425 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4426 | } |
| 4427 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4428 | 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] | 4429 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4430 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4432 | trace_nfs4_read(hdr, task->tk_status); |
| 4433 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4434 | hdr->args.context->state, |
| 4435 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4436 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4437 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4439 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4440 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4442 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4443 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4446 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4447 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4448 | { |
| 4449 | |
| 4450 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4451 | nfs4_stateid_is_current(&args->stateid, |
| 4452 | args->context, |
| 4453 | args->lock_context, |
| 4454 | FMODE_READ)) |
| 4455 | return false; |
| 4456 | rpc_restart_call_prepare(task); |
| 4457 | return true; |
| 4458 | } |
| 4459 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4460 | 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] | 4461 | { |
| 4462 | |
| 4463 | dprintk("--> %s\n", __func__); |
| 4464 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4465 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4466 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4467 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4468 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4469 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4470 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4473 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4474 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4476 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4477 | if (!hdr->pgio_done_cb) |
| 4478 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4479 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4480 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4483 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4484 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4485 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4486 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4487 | &hdr->args.seq_args, |
| 4488 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4489 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4490 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4491 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4492 | hdr->args.lock_context, |
| 4493 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4494 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4495 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4496 | return -EIO; |
| 4497 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4500 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4501 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4503 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4504 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4505 | trace_nfs4_write(hdr, task->tk_status); |
| 4506 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4507 | hdr->args.context->state, |
| 4508 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4509 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4510 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4512 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4513 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4514 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4515 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4516 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4519 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4520 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4521 | { |
| 4522 | |
| 4523 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4524 | nfs4_stateid_is_current(&args->stateid, |
| 4525 | args->context, |
| 4526 | args->lock_context, |
| 4527 | FMODE_WRITE)) |
| 4528 | return false; |
| 4529 | rpc_restart_call_prepare(task); |
| 4530 | return true; |
| 4531 | } |
| 4532 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4533 | 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] | 4534 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4535 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4536 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4537 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4538 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4539 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4540 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4543 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4544 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4545 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4546 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4547 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4548 | return false; |
| 4549 | /* Otherwise, request attributes if and only if we don't hold |
| 4550 | * a delegation |
| 4551 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4552 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4553 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4554 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4555 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4556 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4558 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4559 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4560 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4561 | hdr->args.bitmask = NULL; |
| 4562 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4563 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4564 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4565 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4566 | if (!hdr->pgio_done_cb) |
| 4567 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4568 | hdr->res.server = server; |
| 4569 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4571 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4572 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | } |
| 4574 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4575 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4576 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4577 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4578 | &data->args.seq_args, |
| 4579 | &data->res.seq_res, |
| 4580 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | } |
| 4582 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4583 | 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] | 4584 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4586 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4587 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4588 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4589 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4590 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4591 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4593 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | } |
| 4595 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4596 | 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] | 4597 | { |
| 4598 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4599 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4600 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4603 | 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] | 4604 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4605 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4606 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4607 | if (data->commit_done_cb == NULL) |
| 4608 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4609 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4610 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4611 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4614 | struct nfs4_renewdata { |
| 4615 | struct nfs_client *client; |
| 4616 | unsigned long timestamp; |
| 4617 | }; |
| 4618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | /* |
| 4620 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4621 | * standalone procedure for queueing an asynchronous RENEW. |
| 4622 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4623 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4624 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4625 | struct nfs4_renewdata *data = calldata; |
| 4626 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4627 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4628 | if (atomic_read(&clp->cl_count) > 1) |
| 4629 | nfs4_schedule_state_renewal(clp); |
| 4630 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4631 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4632 | } |
| 4633 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4634 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4636 | struct nfs4_renewdata *data = calldata; |
| 4637 | struct nfs_client *clp = data->client; |
| 4638 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4640 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4641 | switch (task->tk_status) { |
| 4642 | case 0: |
| 4643 | break; |
| 4644 | case -NFS4ERR_LEASE_MOVED: |
| 4645 | nfs4_schedule_lease_moved_recovery(clp); |
| 4646 | break; |
| 4647 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4648 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4649 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4650 | return; |
| 4651 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4652 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4653 | return; |
| 4654 | } |
| 4655 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4657 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4660 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4661 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4662 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4663 | }; |
| 4664 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4665 | 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] | 4666 | { |
| 4667 | struct rpc_message msg = { |
| 4668 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4669 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4670 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4672 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4674 | if (renew_flags == 0) |
| 4675 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4676 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4677 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4678 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4679 | if (data == NULL) |
| 4680 | return -ENOMEM; |
| 4681 | data->client = clp; |
| 4682 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4683 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4684 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4687 | 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] | 4688 | { |
| 4689 | struct rpc_message msg = { |
| 4690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4691 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4692 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | }; |
| 4694 | unsigned long now = jiffies; |
| 4695 | int status; |
| 4696 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4697 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | if (status < 0) |
| 4699 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4700 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | return 0; |
| 4702 | } |
| 4703 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4704 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4705 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4706 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4709 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4710 | * 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] | 4711 | * the stack. |
| 4712 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4713 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4714 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4715 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4716 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4717 | { |
| 4718 | struct page *newpage, **spages; |
| 4719 | int rc = 0; |
| 4720 | size_t len; |
| 4721 | spages = pages; |
| 4722 | |
| 4723 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4724 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4725 | newpage = alloc_page(GFP_KERNEL); |
| 4726 | |
| 4727 | if (newpage == NULL) |
| 4728 | goto unwind; |
| 4729 | memcpy(page_address(newpage), buf, len); |
| 4730 | buf += len; |
| 4731 | buflen -= len; |
| 4732 | *pages++ = newpage; |
| 4733 | rc++; |
| 4734 | } while (buflen != 0); |
| 4735 | |
| 4736 | return rc; |
| 4737 | |
| 4738 | unwind: |
| 4739 | for(; rc > 0; rc--) |
| 4740 | __free_page(spages[rc-1]); |
| 4741 | return -ENOMEM; |
| 4742 | } |
| 4743 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4744 | struct nfs4_cached_acl { |
| 4745 | int cached; |
| 4746 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4747 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4748 | }; |
| 4749 | |
| 4750 | 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] | 4751 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4752 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4753 | |
| 4754 | spin_lock(&inode->i_lock); |
| 4755 | kfree(nfsi->nfs4_acl); |
| 4756 | nfsi->nfs4_acl = acl; |
| 4757 | spin_unlock(&inode->i_lock); |
| 4758 | } |
| 4759 | |
| 4760 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4761 | { |
| 4762 | nfs4_set_cached_acl(inode, NULL); |
| 4763 | } |
| 4764 | |
| 4765 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4766 | { |
| 4767 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4768 | struct nfs4_cached_acl *acl; |
| 4769 | int ret = -ENOENT; |
| 4770 | |
| 4771 | spin_lock(&inode->i_lock); |
| 4772 | acl = nfsi->nfs4_acl; |
| 4773 | if (acl == NULL) |
| 4774 | goto out; |
| 4775 | if (buf == NULL) /* user is just asking for length */ |
| 4776 | goto out_len; |
| 4777 | if (acl->cached == 0) |
| 4778 | goto out; |
| 4779 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4780 | if (acl->len > buflen) |
| 4781 | goto out; |
| 4782 | memcpy(buf, acl->data, acl->len); |
| 4783 | out_len: |
| 4784 | ret = acl->len; |
| 4785 | out: |
| 4786 | spin_unlock(&inode->i_lock); |
| 4787 | return ret; |
| 4788 | } |
| 4789 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4790 | 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] | 4791 | { |
| 4792 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4793 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4794 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4795 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4796 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4797 | if (acl == NULL) |
| 4798 | goto out; |
| 4799 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4800 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4801 | } else { |
| 4802 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4803 | if (acl == NULL) |
| 4804 | goto out; |
| 4805 | acl->cached = 0; |
| 4806 | } |
| 4807 | acl->len = acl_len; |
| 4808 | out: |
| 4809 | nfs4_set_cached_acl(inode, acl); |
| 4810 | } |
| 4811 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4812 | /* |
| 4813 | * The getxattr API returns the required buffer length when called with a |
| 4814 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4815 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4816 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4817 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4818 | * the cache. If not so, we throw away the page, and cache the required |
| 4819 | * length. The next getxattr call will then produce another round trip to |
| 4820 | * the server, this time with the input buf of the required size. |
| 4821 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4822 | 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] | 4823 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4824 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4825 | struct nfs_getaclargs args = { |
| 4826 | .fh = NFS_FH(inode), |
| 4827 | .acl_pages = pages, |
| 4828 | .acl_len = buflen, |
| 4829 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4830 | struct nfs_getaclres res = { |
| 4831 | .acl_len = buflen, |
| 4832 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4833 | struct rpc_message msg = { |
| 4834 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4835 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4836 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4837 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4838 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4839 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4840 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4841 | /* As long as we're doing a round trip to the server anyway, |
| 4842 | * let's be prepared for a page of acl data. */ |
| 4843 | if (npages == 0) |
| 4844 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4845 | if (npages > ARRAY_SIZE(pages)) |
| 4846 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4847 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4848 | for (i = 0; i < npages; i++) { |
| 4849 | pages[i] = alloc_page(GFP_KERNEL); |
| 4850 | if (!pages[i]) |
| 4851 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4852 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4853 | |
| 4854 | /* for decoding across pages */ |
| 4855 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4856 | if (!res.acl_scratch) |
| 4857 | goto out_free; |
| 4858 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4859 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4860 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4861 | 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] | 4862 | __func__, buf, buflen, npages, args.acl_len); |
| 4863 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4864 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4865 | if (ret) |
| 4866 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4867 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4868 | /* Handle the case where the passed-in buffer is too short */ |
| 4869 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4870 | /* Did the user only issue a request for the acl length? */ |
| 4871 | if (buf == NULL) |
| 4872 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4873 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4874 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4875 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4876 | 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] | 4877 | if (buf) { |
| 4878 | if (res.acl_len > buflen) { |
| 4879 | ret = -ERANGE; |
| 4880 | goto out_free; |
| 4881 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4882 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4883 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4884 | out_ok: |
| 4885 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4886 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4887 | for (i = 0; i < npages; i++) |
| 4888 | if (pages[i]) |
| 4889 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4890 | if (res.acl_scratch) |
| 4891 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4892 | return ret; |
| 4893 | } |
| 4894 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4895 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4896 | { |
| 4897 | struct nfs4_exception exception = { }; |
| 4898 | ssize_t ret; |
| 4899 | do { |
| 4900 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4901 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4902 | if (ret >= 0) |
| 4903 | break; |
| 4904 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4905 | } while (exception.retry); |
| 4906 | return ret; |
| 4907 | } |
| 4908 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4909 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4910 | { |
| 4911 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4912 | int ret; |
| 4913 | |
| 4914 | if (!nfs4_server_supports_acls(server)) |
| 4915 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4916 | ret = nfs_revalidate_inode(server, inode); |
| 4917 | if (ret < 0) |
| 4918 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4919 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4920 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4921 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4922 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4923 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4924 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4925 | return ret; |
| 4926 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4929 | 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] | 4930 | { |
| 4931 | struct nfs_server *server = NFS_SERVER(inode); |
| 4932 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4933 | struct nfs_setaclargs arg = { |
| 4934 | .fh = NFS_FH(inode), |
| 4935 | .acl_pages = pages, |
| 4936 | .acl_len = buflen, |
| 4937 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4938 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4939 | struct rpc_message msg = { |
| 4940 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4941 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4942 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4943 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4944 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4945 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4946 | |
| 4947 | if (!nfs4_server_supports_acls(server)) |
| 4948 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4949 | if (npages > ARRAY_SIZE(pages)) |
| 4950 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4951 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4952 | if (i < 0) |
| 4953 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4954 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4955 | 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] | 4956 | |
| 4957 | /* |
| 4958 | * Free each page after tx, so the only ref left is |
| 4959 | * held by the network stack |
| 4960 | */ |
| 4961 | for (; i > 0; i--) |
| 4962 | put_page(pages[i-1]); |
| 4963 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4964 | /* |
| 4965 | * Acl update can result in inode attribute update. |
| 4966 | * so mark the attribute cache invalid. |
| 4967 | */ |
| 4968 | spin_lock(&inode->i_lock); |
| 4969 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4970 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4971 | nfs_access_zap_cache(inode); |
| 4972 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4973 | return ret; |
| 4974 | } |
| 4975 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4976 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4977 | { |
| 4978 | struct nfs4_exception exception = { }; |
| 4979 | int err; |
| 4980 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4981 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4982 | trace_nfs4_set_acl(inode, err); |
| 4983 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4984 | &exception); |
| 4985 | } while (exception.retry); |
| 4986 | return err; |
| 4987 | } |
| 4988 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4989 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4990 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4991 | size_t buflen) |
| 4992 | { |
| 4993 | struct nfs_server *server = NFS_SERVER(inode); |
| 4994 | struct nfs_fattr fattr; |
| 4995 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4996 | |
| 4997 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4998 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4999 | .fh = NFS_FH(inode), |
| 5000 | .bitmask = bitmask, |
| 5001 | }; |
| 5002 | struct nfs4_getattr_res res = { |
| 5003 | .fattr = &fattr, |
| 5004 | .label = &label, |
| 5005 | .server = server, |
| 5006 | }; |
| 5007 | struct rpc_message msg = { |
| 5008 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5009 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5010 | .rpc_resp = &res, |
| 5011 | }; |
| 5012 | int ret; |
| 5013 | |
| 5014 | nfs_fattr_init(&fattr); |
| 5015 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5016 | 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] | 5017 | if (ret) |
| 5018 | return ret; |
| 5019 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5020 | return -ENOENT; |
| 5021 | if (buflen < label.len) |
| 5022 | return -ERANGE; |
| 5023 | return 0; |
| 5024 | } |
| 5025 | |
| 5026 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5027 | size_t buflen) |
| 5028 | { |
| 5029 | struct nfs4_exception exception = { }; |
| 5030 | int err; |
| 5031 | |
| 5032 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5033 | return -EOPNOTSUPP; |
| 5034 | |
| 5035 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5036 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5037 | trace_nfs4_get_security_label(inode, err); |
| 5038 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5039 | &exception); |
| 5040 | } while (exception.retry); |
| 5041 | return err; |
| 5042 | } |
| 5043 | |
| 5044 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5045 | struct nfs4_label *ilabel, |
| 5046 | struct nfs_fattr *fattr, |
| 5047 | struct nfs4_label *olabel) |
| 5048 | { |
| 5049 | |
| 5050 | struct iattr sattr = {0}; |
| 5051 | struct nfs_server *server = NFS_SERVER(inode); |
| 5052 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5053 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5054 | .fh = NFS_FH(inode), |
| 5055 | .iap = &sattr, |
| 5056 | .server = server, |
| 5057 | .bitmask = bitmask, |
| 5058 | .label = ilabel, |
| 5059 | }; |
| 5060 | struct nfs_setattrres res = { |
| 5061 | .fattr = fattr, |
| 5062 | .label = olabel, |
| 5063 | .server = server, |
| 5064 | }; |
| 5065 | struct rpc_message msg = { |
| 5066 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5067 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5068 | .rpc_resp = &res, |
| 5069 | }; |
| 5070 | int status; |
| 5071 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5072 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5073 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5074 | 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] | 5075 | if (status) |
| 5076 | dprintk("%s failed: %d\n", __func__, status); |
| 5077 | |
| 5078 | return status; |
| 5079 | } |
| 5080 | |
| 5081 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5082 | struct nfs4_label *ilabel, |
| 5083 | struct nfs_fattr *fattr, |
| 5084 | struct nfs4_label *olabel) |
| 5085 | { |
| 5086 | struct nfs4_exception exception = { }; |
| 5087 | int err; |
| 5088 | |
| 5089 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5090 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5091 | fattr, olabel); |
| 5092 | trace_nfs4_set_security_label(inode, err); |
| 5093 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5094 | &exception); |
| 5095 | } while (exception.retry); |
| 5096 | return err; |
| 5097 | } |
| 5098 | |
| 5099 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5100 | 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] | 5101 | { |
| 5102 | struct nfs4_label ilabel, *olabel = NULL; |
| 5103 | struct nfs_fattr fattr; |
| 5104 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5105 | int status; |
| 5106 | |
| 5107 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5108 | return -EOPNOTSUPP; |
| 5109 | |
| 5110 | nfs_fattr_init(&fattr); |
| 5111 | |
| 5112 | ilabel.pi = 0; |
| 5113 | ilabel.lfs = 0; |
| 5114 | ilabel.label = (char *)buf; |
| 5115 | ilabel.len = buflen; |
| 5116 | |
| 5117 | cred = rpc_lookup_cred(); |
| 5118 | if (IS_ERR(cred)) |
| 5119 | return PTR_ERR(cred); |
| 5120 | |
| 5121 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5122 | if (IS_ERR(olabel)) { |
| 5123 | status = -PTR_ERR(olabel); |
| 5124 | goto out; |
| 5125 | } |
| 5126 | |
| 5127 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5128 | if (status == 0) |
| 5129 | nfs_setsecurity(inode, &fattr, olabel); |
| 5130 | |
| 5131 | nfs4_label_free(olabel); |
| 5132 | out: |
| 5133 | put_rpccred(cred); |
| 5134 | return status; |
| 5135 | } |
| 5136 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5137 | |
| 5138 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5139 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5140 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5141 | { |
| 5142 | __be32 verf[2]; |
| 5143 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5144 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5145 | /* An impossible timestamp guarantees this value |
| 5146 | * will never match a generated boot time. */ |
| 5147 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5148 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5149 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5150 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5151 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5152 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5153 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5154 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5155 | } |
| 5156 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5157 | static int |
| 5158 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5159 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5160 | size_t len; |
| 5161 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5162 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5163 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5164 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5165 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5166 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5167 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5168 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5169 | 1 + |
| 5170 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5171 | 1; |
| 5172 | rcu_read_unlock(); |
| 5173 | |
| 5174 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5175 | return -EINVAL; |
| 5176 | |
| 5177 | /* |
| 5178 | * Since this string is allocated at mount time, and held until the |
| 5179 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5180 | * about a memory-reclaim deadlock. |
| 5181 | */ |
| 5182 | str = kmalloc(len, GFP_KERNEL); |
| 5183 | if (!str) |
| 5184 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5185 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5186 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5187 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5188 | clp->cl_ipaddr, |
| 5189 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5190 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5191 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5192 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5193 | clp->cl_owner_id = str; |
| 5194 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5195 | } |
| 5196 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5197 | static int |
| 5198 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5199 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5200 | size_t len; |
| 5201 | char *str; |
| 5202 | |
| 5203 | len = 10 + 10 + 1 + 10 + 1 + |
| 5204 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5205 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5206 | |
| 5207 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5208 | return -EINVAL; |
| 5209 | |
| 5210 | /* |
| 5211 | * Since this string is allocated at mount time, and held until the |
| 5212 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5213 | * about a memory-reclaim deadlock. |
| 5214 | */ |
| 5215 | str = kmalloc(len, GFP_KERNEL); |
| 5216 | if (!str) |
| 5217 | return -ENOMEM; |
| 5218 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5219 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5220 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5221 | nfs4_client_id_uniquifier, |
| 5222 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5223 | clp->cl_owner_id = str; |
| 5224 | return 0; |
| 5225 | } |
| 5226 | |
| 5227 | static int |
| 5228 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5229 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5230 | size_t len; |
| 5231 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5232 | |
| 5233 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5234 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5235 | |
| 5236 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5237 | return nfs4_init_uniquifier_client_string(clp); |
| 5238 | |
| 5239 | len = 10 + 10 + 1 + 10 + 1 + |
| 5240 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5241 | |
| 5242 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5243 | return -EINVAL; |
| 5244 | |
| 5245 | /* |
| 5246 | * Since this string is allocated at mount time, and held until the |
| 5247 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5248 | * about a memory-reclaim deadlock. |
| 5249 | */ |
| 5250 | str = kmalloc(len, GFP_KERNEL); |
| 5251 | if (!str) |
| 5252 | return -ENOMEM; |
| 5253 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5254 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5255 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5256 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5257 | clp->cl_owner_id = str; |
| 5258 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5259 | } |
| 5260 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5261 | /* |
| 5262 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5263 | * services. Advertise one based on the address family of the |
| 5264 | * clientaddr. |
| 5265 | */ |
| 5266 | static unsigned int |
| 5267 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5268 | { |
| 5269 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5270 | return scnprintf(buf, len, "tcp6"); |
| 5271 | else |
| 5272 | return scnprintf(buf, len, "tcp"); |
| 5273 | } |
| 5274 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5275 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5276 | { |
| 5277 | struct nfs4_setclientid *sc = calldata; |
| 5278 | |
| 5279 | if (task->tk_status == 0) |
| 5280 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5281 | } |
| 5282 | |
| 5283 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5284 | .rpc_call_done = nfs4_setclientid_done, |
| 5285 | }; |
| 5286 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5287 | /** |
| 5288 | * nfs4_proc_setclientid - Negotiate client ID |
| 5289 | * @clp: state data structure |
| 5290 | * @program: RPC program for NFSv4 callback service |
| 5291 | * @port: IP port number for NFS4 callback service |
| 5292 | * @cred: RPC credential to use for this call |
| 5293 | * @res: where to place the result |
| 5294 | * |
| 5295 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5296 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5297 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5298 | unsigned short port, struct rpc_cred *cred, |
| 5299 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | { |
| 5301 | nfs4_verifier sc_verifier; |
| 5302 | struct nfs4_setclientid setclientid = { |
| 5303 | .sc_verifier = &sc_verifier, |
| 5304 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5305 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | }; |
| 5307 | struct rpc_message msg = { |
| 5308 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5309 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5310 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5311 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5313 | struct rpc_task *task; |
| 5314 | struct rpc_task_setup task_setup_data = { |
| 5315 | .rpc_client = clp->cl_rpcclient, |
| 5316 | .rpc_message = &msg, |
| 5317 | .callback_ops = &nfs4_setclientid_ops, |
| 5318 | .callback_data = &setclientid, |
| 5319 | .flags = RPC_TASK_TIMEOUT, |
| 5320 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5321 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5323 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5324 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5325 | |
| 5326 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5327 | status = nfs4_init_uniform_client_string(clp); |
| 5328 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5329 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5330 | |
| 5331 | if (status) |
| 5332 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5333 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5334 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5335 | setclientid.sc_netid_len = |
| 5336 | nfs4_init_callback_netid(clp, |
| 5337 | setclientid.sc_netid, |
| 5338 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5339 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5340 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5342 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5343 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5344 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5345 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5346 | task = rpc_run_task(&task_setup_data); |
| 5347 | if (IS_ERR(task)) { |
| 5348 | status = PTR_ERR(task); |
| 5349 | goto out; |
| 5350 | } |
| 5351 | status = task->tk_status; |
| 5352 | if (setclientid.sc_cred) { |
| 5353 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5354 | put_rpccred(setclientid.sc_cred); |
| 5355 | } |
| 5356 | rpc_put_task(task); |
| 5357 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5358 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5359 | dprintk("NFS reply setclientid: %d\n", status); |
| 5360 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5363 | /** |
| 5364 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5365 | * @clp: state data structure |
| 5366 | * @res: result of a previous SETCLIENTID |
| 5367 | * @cred: RPC credential to use for this call |
| 5368 | * |
| 5369 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5370 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5371 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5372 | struct nfs4_setclientid_res *arg, |
| 5373 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | struct rpc_message msg = { |
| 5376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5377 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5378 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | int status; |
| 5381 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5382 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5383 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5384 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5385 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5386 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5387 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | return status; |
| 5389 | } |
| 5390 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5391 | struct nfs4_delegreturndata { |
| 5392 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5393 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5394 | struct nfs_fh fh; |
| 5395 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5396 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5397 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5398 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5399 | struct inode *inode; |
| 5400 | bool roc; |
| 5401 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5402 | }; |
| 5403 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5404 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5405 | { |
| 5406 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5407 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5408 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5409 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5410 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5411 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5412 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5413 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5414 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5415 | case -NFS4ERR_ADMIN_REVOKED: |
| 5416 | case -NFS4ERR_DELEG_REVOKED: |
| 5417 | case -NFS4ERR_BAD_STATEID: |
| 5418 | case -NFS4ERR_OLD_STATEID: |
| 5419 | case -NFS4ERR_STALE_STATEID: |
| 5420 | case -NFS4ERR_EXPIRED: |
| 5421 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5422 | if (data->roc) |
| 5423 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5424 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5425 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5426 | if (nfs4_async_handle_error(task, data->res.server, |
| 5427 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5428 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5429 | return; |
| 5430 | } |
| 5431 | } |
| 5432 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | static void nfs4_delegreturn_release(void *calldata) |
| 5436 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5437 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5438 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5439 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5440 | if (inode) { |
| 5441 | if (data->roc) |
| 5442 | pnfs_roc_release(inode); |
| 5443 | nfs_iput_and_deactive(inode); |
| 5444 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5445 | kfree(calldata); |
| 5446 | } |
| 5447 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5448 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5449 | { |
| 5450 | struct nfs4_delegreturndata *d_data; |
| 5451 | |
| 5452 | d_data = (struct nfs4_delegreturndata *)data; |
| 5453 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5454 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5455 | return; |
| 5456 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5457 | if (d_data->roc) |
| 5458 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5459 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5460 | nfs4_setup_sequence(d_data->res.server, |
| 5461 | &d_data->args.seq_args, |
| 5462 | &d_data->res.seq_res, |
| 5463 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5464 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5465 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5466 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5467 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5468 | .rpc_call_done = nfs4_delegreturn_done, |
| 5469 | .rpc_release = nfs4_delegreturn_release, |
| 5470 | }; |
| 5471 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5472 | 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] | 5473 | { |
| 5474 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5475 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5476 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5477 | struct rpc_message msg = { |
| 5478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5479 | .rpc_cred = cred, |
| 5480 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5481 | struct rpc_task_setup task_setup_data = { |
| 5482 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5483 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5484 | .callback_ops = &nfs4_delegreturn_ops, |
| 5485 | .flags = RPC_TASK_ASYNC, |
| 5486 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5487 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5488 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5489 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5490 | if (data == NULL) |
| 5491 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5492 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5493 | |
| 5494 | nfs4_state_protect(server->nfs_client, |
| 5495 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5496 | &task_setup_data.rpc_client, &msg); |
| 5497 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5498 | data->args.fhandle = &data->fh; |
| 5499 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5500 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5501 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5502 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5503 | data->res.fattr = &data->fattr; |
| 5504 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5505 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5506 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5507 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5508 | data->inode = nfs_igrab_and_active(inode); |
| 5509 | if (data->inode) |
| 5510 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5511 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5512 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5513 | msg.rpc_argp = &data->args; |
| 5514 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5515 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5516 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5517 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5518 | if (!issync) |
| 5519 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5520 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5521 | if (status != 0) |
| 5522 | goto out; |
| 5523 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5524 | if (status == 0) |
| 5525 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5526 | else |
| 5527 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5528 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5529 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5530 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5533 | 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] | 5534 | { |
| 5535 | struct nfs_server *server = NFS_SERVER(inode); |
| 5536 | struct nfs4_exception exception = { }; |
| 5537 | int err; |
| 5538 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5539 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5540 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | switch (err) { |
| 5542 | case -NFS4ERR_STALE_STATEID: |
| 5543 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | case 0: |
| 5545 | return 0; |
| 5546 | } |
| 5547 | err = nfs4_handle_exception(server, err, &exception); |
| 5548 | } while (exception.retry); |
| 5549 | return err; |
| 5550 | } |
| 5551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5553 | { |
| 5554 | struct inode *inode = state->inode; |
| 5555 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5556 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5557 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5559 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5560 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5561 | struct nfs_lockt_res res = { |
| 5562 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | }; |
| 5564 | struct rpc_message msg = { |
| 5565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5566 | .rpc_argp = &arg, |
| 5567 | .rpc_resp = &res, |
| 5568 | .rpc_cred = state->owner->so_cred, |
| 5569 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | struct nfs4_lock_state *lsp; |
| 5571 | int status; |
| 5572 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5573 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5574 | status = nfs4_set_lock_state(state, request); |
| 5575 | if (status != 0) |
| 5576 | goto out; |
| 5577 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5578 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5579 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5580 | 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] | 5581 | switch (status) { |
| 5582 | case 0: |
| 5583 | request->fl_type = F_UNLCK; |
| 5584 | break; |
| 5585 | case -NFS4ERR_DENIED: |
| 5586 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5588 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5589 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5590 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | return status; |
| 5592 | } |
| 5593 | |
| 5594 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5595 | { |
| 5596 | struct nfs4_exception exception = { }; |
| 5597 | int err; |
| 5598 | |
| 5599 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5600 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5601 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5602 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | &exception); |
| 5604 | } while (exception.retry); |
| 5605 | return err; |
| 5606 | } |
| 5607 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5608 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5609 | struct nfs_locku_args arg; |
| 5610 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5611 | struct nfs4_lock_state *lsp; |
| 5612 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5613 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5614 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5615 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5616 | }; |
| 5617 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5618 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5619 | struct nfs_open_context *ctx, |
| 5620 | struct nfs4_lock_state *lsp, |
| 5621 | struct nfs_seqid *seqid) |
| 5622 | { |
| 5623 | struct nfs4_unlockdata *p; |
| 5624 | struct inode *inode = lsp->ls_state->inode; |
| 5625 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5626 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5627 | if (p == NULL) |
| 5628 | return NULL; |
| 5629 | p->arg.fh = NFS_FH(inode); |
| 5630 | p->arg.fl = &p->fl; |
| 5631 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5632 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5633 | p->lsp = lsp; |
| 5634 | atomic_inc(&lsp->ls_count); |
| 5635 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5636 | p->ctx = get_nfs_open_context(ctx); |
| 5637 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5638 | p->server = NFS_SERVER(inode); |
| 5639 | return p; |
| 5640 | } |
| 5641 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5642 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5643 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5644 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5645 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5646 | nfs4_put_lock_state(calldata->lsp); |
| 5647 | put_nfs_open_context(calldata->ctx); |
| 5648 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5649 | } |
| 5650 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5651 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5652 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5653 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5654 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5655 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5656 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5657 | switch (task->tk_status) { |
| 5658 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5659 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5660 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5661 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5662 | &calldata->res.stateid)) |
| 5663 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5664 | case -NFS4ERR_BAD_STATEID: |
| 5665 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5666 | case -NFS4ERR_STALE_STATEID: |
| 5667 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5668 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5669 | &calldata->lsp->ls_stateid)) |
| 5670 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5671 | break; |
| 5672 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5673 | if (nfs4_async_handle_error(task, calldata->server, |
| 5674 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5675 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5676 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5677 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5678 | } |
| 5679 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5680 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5681 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5682 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5684 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5685 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5686 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5687 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5688 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5689 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5690 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5691 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5692 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5693 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5694 | &calldata->res.seq_res, |
| 5695 | task) != 0) |
| 5696 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5697 | return; |
| 5698 | out_no_action: |
| 5699 | task->tk_action = NULL; |
| 5700 | out_wait: |
| 5701 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5704 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5705 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5706 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5707 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5708 | }; |
| 5709 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5710 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5711 | struct nfs_open_context *ctx, |
| 5712 | struct nfs4_lock_state *lsp, |
| 5713 | struct nfs_seqid *seqid) |
| 5714 | { |
| 5715 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5716 | struct rpc_message msg = { |
| 5717 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5718 | .rpc_cred = ctx->cred, |
| 5719 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5720 | struct rpc_task_setup task_setup_data = { |
| 5721 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5722 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5723 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5724 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5725 | .flags = RPC_TASK_ASYNC, |
| 5726 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5727 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5728 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5729 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5730 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5731 | /* Ensure this is an unlock - when canceling a lock, the |
| 5732 | * canceled lock is passed in, and it won't be an unlock. |
| 5733 | */ |
| 5734 | fl->fl_type = F_UNLCK; |
| 5735 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5736 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5737 | if (data == NULL) { |
| 5738 | nfs_free_seqid(seqid); |
| 5739 | return ERR_PTR(-ENOMEM); |
| 5740 | } |
| 5741 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5742 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5743 | msg.rpc_argp = &data->arg; |
| 5744 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5745 | task_setup_data.callback_data = data; |
| 5746 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5747 | } |
| 5748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5750 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5751 | struct inode *inode = state->inode; |
| 5752 | struct nfs4_state_owner *sp = state->owner; |
| 5753 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5754 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5755 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5756 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5757 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5758 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5759 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5760 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5761 | status = nfs4_set_lock_state(state, request); |
| 5762 | /* Unlock _before_ we do the RPC call */ |
| 5763 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5764 | /* Exclude nfs_delegation_claim_locks() */ |
| 5765 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5766 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5767 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5768 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5769 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5770 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5771 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5772 | } |
| 5773 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5774 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5775 | if (status != 0) |
| 5776 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5777 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5778 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5779 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5780 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5781 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5782 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5783 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5784 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5785 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5786 | 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] | 5787 | status = PTR_ERR(task); |
| 5788 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5789 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5790 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5791 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5792 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5793 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5794 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5795 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | } |
| 5797 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5798 | struct nfs4_lockdata { |
| 5799 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5800 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5801 | struct nfs4_lock_state *lsp; |
| 5802 | struct nfs_open_context *ctx; |
| 5803 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5804 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5805 | int rpc_status; |
| 5806 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5807 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5808 | }; |
| 5809 | |
| 5810 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5811 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5812 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5813 | { |
| 5814 | struct nfs4_lockdata *p; |
| 5815 | struct inode *inode = lsp->ls_state->inode; |
| 5816 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5817 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5818 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5819 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5820 | if (p == NULL) |
| 5821 | return NULL; |
| 5822 | |
| 5823 | p->arg.fh = NFS_FH(inode); |
| 5824 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5825 | 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] | 5826 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5827 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5828 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5829 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5830 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5831 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5832 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5833 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5834 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5835 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5836 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5837 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5838 | atomic_inc(&lsp->ls_count); |
| 5839 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5840 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5841 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5842 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5843 | out_free_seqid: |
| 5844 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5845 | out_free: |
| 5846 | kfree(p); |
| 5847 | return NULL; |
| 5848 | } |
| 5849 | |
| 5850 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5851 | { |
| 5852 | struct nfs4_lockdata *data = calldata; |
| 5853 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5855 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5856 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5857 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5858 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5859 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5860 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5861 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5862 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5863 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5864 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5865 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5866 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5867 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5868 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5869 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5870 | &data->lsp->ls_stateid); |
| 5871 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5872 | if (!nfs4_valid_open_stateid(state)) { |
| 5873 | data->rpc_status = -EBADF; |
| 5874 | task->tk_action = NULL; |
| 5875 | goto out_release_open_seqid; |
| 5876 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5877 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5878 | if (nfs4_setup_sequence(data->server, |
| 5879 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5880 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5881 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5882 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5883 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5884 | nfs_release_seqid(data->arg.open_seqid); |
| 5885 | out_release_lock_seqid: |
| 5886 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5887 | out_wait: |
| 5888 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5889 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5890 | } |
| 5891 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5892 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5893 | { |
| 5894 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5895 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5896 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5897 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5898 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5899 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5900 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5901 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5902 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5903 | switch (task->tk_status) { |
| 5904 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5905 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5906 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5907 | if (data->arg.new_lock) { |
| 5908 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5909 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5910 | rpc_restart_call_prepare(task); |
| 5911 | break; |
| 5912 | } |
| 5913 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5914 | if (data->arg.new_lock_owner != 0) { |
| 5915 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5916 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5917 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5918 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5919 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5920 | break; |
| 5921 | case -NFS4ERR_BAD_STATEID: |
| 5922 | case -NFS4ERR_OLD_STATEID: |
| 5923 | case -NFS4ERR_STALE_STATEID: |
| 5924 | case -NFS4ERR_EXPIRED: |
| 5925 | if (data->arg.new_lock_owner != 0) { |
| 5926 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5927 | &lsp->ls_state->open_stateid)) |
| 5928 | rpc_restart_call_prepare(task); |
| 5929 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5930 | &lsp->ls_stateid)) |
| 5931 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5932 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5933 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | static void nfs4_lock_release(void *calldata) |
| 5937 | { |
| 5938 | struct nfs4_lockdata *data = calldata; |
| 5939 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5940 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5941 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5942 | if (data->cancelled != 0) { |
| 5943 | struct rpc_task *task; |
| 5944 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5945 | data->arg.lock_seqid); |
| 5946 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5947 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5948 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5949 | } else |
| 5950 | nfs_free_seqid(data->arg.lock_seqid); |
| 5951 | nfs4_put_lock_state(data->lsp); |
| 5952 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5953 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5954 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5955 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5959 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5960 | .rpc_call_done = nfs4_lock_done, |
| 5961 | .rpc_release = nfs4_lock_release, |
| 5962 | }; |
| 5963 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5964 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5965 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5966 | switch (error) { |
| 5967 | case -NFS4ERR_ADMIN_REVOKED: |
| 5968 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5969 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5970 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5971 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5972 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5973 | break; |
| 5974 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5975 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5976 | case -NFS4ERR_EXPIRED: |
| 5977 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5978 | }; |
| 5979 | } |
| 5980 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5981 | 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] | 5982 | { |
| 5983 | struct nfs4_lockdata *data; |
| 5984 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5985 | struct rpc_message msg = { |
| 5986 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5987 | .rpc_cred = state->owner->so_cred, |
| 5988 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5989 | struct rpc_task_setup task_setup_data = { |
| 5990 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5991 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5992 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5993 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5994 | .flags = RPC_TASK_ASYNC, |
| 5995 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5996 | int ret; |
| 5997 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5998 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5999 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6000 | fl->fl_u.nfs4_fl.owner, |
| 6001 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6002 | if (data == NULL) |
| 6003 | return -ENOMEM; |
| 6004 | if (IS_SETLKW(cmd)) |
| 6005 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6006 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6007 | msg.rpc_argp = &data->arg; |
| 6008 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6009 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6010 | if (recovery_type > NFS_LOCK_NEW) { |
| 6011 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6012 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6013 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6014 | } else |
| 6015 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6016 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6017 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6018 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6019 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6020 | if (ret == 0) { |
| 6021 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6022 | if (ret) |
| 6023 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6024 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6025 | } else |
| 6026 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6027 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6028 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6029 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6030 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6034 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6035 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6036 | struct nfs4_exception exception = { |
| 6037 | .inode = state->inode, |
| 6038 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6039 | int err; |
| 6040 | |
| 6041 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6042 | /* Cache the lock if possible... */ |
| 6043 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6044 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6045 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6046 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6047 | break; |
| 6048 | nfs4_handle_exception(server, err, &exception); |
| 6049 | } while (exception.retry); |
| 6050 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6054 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6055 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6056 | struct nfs4_exception exception = { |
| 6057 | .inode = state->inode, |
| 6058 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6059 | int err; |
| 6060 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6061 | err = nfs4_set_lock_state(state, request); |
| 6062 | if (err != 0) |
| 6063 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6064 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6065 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6066 | return 0; |
| 6067 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6068 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6069 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6070 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6071 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6072 | switch (err) { |
| 6073 | default: |
| 6074 | goto out; |
| 6075 | case -NFS4ERR_GRACE: |
| 6076 | case -NFS4ERR_DELAY: |
| 6077 | nfs4_handle_exception(server, err, &exception); |
| 6078 | err = 0; |
| 6079 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6080 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6081 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6082 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6085 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6086 | /** |
| 6087 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6088 | * |
| 6089 | * @state: NFSv4 state for an inode |
| 6090 | * |
| 6091 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6092 | * Otherwise a negative NFS4ERR value is returned. |
| 6093 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6094 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6095 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6096 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6097 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6098 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6099 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6100 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6101 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6102 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6103 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 6104 | status = nfs41_test_and_free_expired_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6105 | &lsp->ls_stateid, |
| 6106 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6107 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6108 | if (status != NFS_OK) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6109 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6110 | ret = status; |
| 6111 | } |
| 6112 | } |
| 6113 | }; |
| 6114 | |
| 6115 | return ret; |
| 6116 | } |
| 6117 | |
| 6118 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6119 | { |
| 6120 | int status = NFS_OK; |
| 6121 | |
| 6122 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6123 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6124 | if (status != NFS_OK) |
| 6125 | status = nfs4_lock_expired(state, request); |
| 6126 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6127 | } |
| 6128 | #endif |
| 6129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6131 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6132 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6133 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6134 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6135 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6136 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6137 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6138 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6139 | if (status < 0) |
| 6140 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6141 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6142 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6143 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6144 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6145 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6146 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6147 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6148 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6149 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6150 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6151 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6152 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6153 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6154 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6155 | out: |
| 6156 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6157 | return status; |
| 6158 | } |
| 6159 | |
| 6160 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6161 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6162 | struct nfs4_exception exception = { |
| 6163 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6164 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | int err; |
| 6167 | |
| 6168 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6169 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6170 | if (err == -NFS4ERR_DENIED) |
| 6171 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6173 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | } while (exception.retry); |
| 6175 | return err; |
| 6176 | } |
| 6177 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6178 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6179 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6180 | |
| 6181 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6182 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6183 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6184 | { |
| 6185 | int status = -ERESTARTSYS; |
| 6186 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6187 | |
| 6188 | while(!signalled()) { |
| 6189 | status = nfs4_proc_setlk(state, cmd, request); |
| 6190 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6191 | break; |
| 6192 | freezable_schedule_timeout_interruptible(timeout); |
| 6193 | timeout *= 2; |
| 6194 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6195 | status = -ERESTARTSYS; |
| 6196 | } |
| 6197 | return status; |
| 6198 | } |
| 6199 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6200 | #ifdef CONFIG_NFS_V4_1 |
| 6201 | struct nfs4_lock_waiter { |
| 6202 | struct task_struct *task; |
| 6203 | struct inode *inode; |
| 6204 | struct nfs_lowner *owner; |
| 6205 | bool notified; |
| 6206 | }; |
| 6207 | |
| 6208 | static int |
| 6209 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6210 | { |
| 6211 | int ret; |
| 6212 | struct cb_notify_lock_args *cbnl = key; |
| 6213 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6214 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6215 | *wowner = waiter->owner; |
| 6216 | |
| 6217 | /* Only wake if the callback was for the same owner */ |
| 6218 | if (lowner->clientid != wowner->clientid || |
| 6219 | lowner->id != wowner->id || |
| 6220 | lowner->s_dev != wowner->s_dev) |
| 6221 | return 0; |
| 6222 | |
| 6223 | /* Make sure it's for the right inode */ |
| 6224 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6225 | return 0; |
| 6226 | |
| 6227 | waiter->notified = true; |
| 6228 | |
| 6229 | /* override "private" so we can use default_wake_function */ |
| 6230 | wait->private = waiter->task; |
| 6231 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6232 | wait->private = waiter; |
| 6233 | return ret; |
| 6234 | } |
| 6235 | |
| 6236 | static int |
| 6237 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6238 | { |
| 6239 | int status = -ERESTARTSYS; |
| 6240 | unsigned long flags; |
| 6241 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6242 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6243 | struct nfs_client *clp = server->nfs_client; |
| 6244 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6245 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6246 | .id = lsp->ls_seqid.owner_id, |
| 6247 | .s_dev = server->s_dev }; |
| 6248 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6249 | .inode = state->inode, |
| 6250 | .owner = &owner, |
| 6251 | .notified = false }; |
| 6252 | wait_queue_t wait; |
| 6253 | |
| 6254 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6255 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6256 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6257 | |
| 6258 | init_wait(&wait); |
| 6259 | wait.private = &waiter; |
| 6260 | wait.func = nfs4_wake_lock_waiter; |
| 6261 | add_wait_queue(q, &wait); |
| 6262 | |
| 6263 | while(!signalled()) { |
| 6264 | status = nfs4_proc_setlk(state, cmd, request); |
| 6265 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6266 | break; |
| 6267 | |
| 6268 | status = -ERESTARTSYS; |
| 6269 | spin_lock_irqsave(&q->lock, flags); |
| 6270 | if (waiter.notified) { |
| 6271 | spin_unlock_irqrestore(&q->lock, flags); |
| 6272 | continue; |
| 6273 | } |
| 6274 | set_current_state(TASK_INTERRUPTIBLE); |
| 6275 | spin_unlock_irqrestore(&q->lock, flags); |
| 6276 | |
| 6277 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6278 | } |
| 6279 | |
| 6280 | finish_wait(q, &wait); |
| 6281 | return status; |
| 6282 | } |
| 6283 | #else /* !CONFIG_NFS_V4_1 */ |
| 6284 | static inline int |
| 6285 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6286 | { |
| 6287 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6288 | } |
| 6289 | #endif |
| 6290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | static int |
| 6292 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6293 | { |
| 6294 | struct nfs_open_context *ctx; |
| 6295 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | int status; |
| 6297 | |
| 6298 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6299 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | state = ctx->state; |
| 6301 | |
| 6302 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6303 | return -EINVAL; |
| 6304 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6305 | if (IS_GETLK(cmd)) { |
| 6306 | if (state != NULL) |
| 6307 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6308 | return 0; |
| 6309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6310 | |
| 6311 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6312 | return -EINVAL; |
| 6313 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6314 | if (request->fl_type == F_UNLCK) { |
| 6315 | if (state != NULL) |
| 6316 | return nfs4_proc_unlck(state, cmd, request); |
| 6317 | return 0; |
| 6318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6319 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6320 | if (state == NULL) |
| 6321 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6322 | |
| 6323 | if ((request->fl_flags & FL_POSIX) && |
| 6324 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6325 | return -ENOLCK; |
| 6326 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6327 | /* |
| 6328 | * Don't rely on the VFS having checked the file open mode, |
| 6329 | * since it won't do this for flock() locks. |
| 6330 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6331 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6332 | case F_RDLCK: |
| 6333 | if (!(filp->f_mode & FMODE_READ)) |
| 6334 | return -EBADF; |
| 6335 | break; |
| 6336 | case F_WRLCK: |
| 6337 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6338 | return -EBADF; |
| 6339 | } |
| 6340 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6341 | status = nfs4_set_lock_state(state, request); |
| 6342 | if (status != 0) |
| 6343 | return status; |
| 6344 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6345 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | } |
| 6347 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6348 | 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] | 6349 | { |
| 6350 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6351 | int err; |
| 6352 | |
| 6353 | err = nfs4_set_lock_state(state, fl); |
| 6354 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6355 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6356 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6357 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6358 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6359 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6360 | struct nfs_release_lockowner_data { |
| 6361 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6362 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6363 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6364 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6365 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6366 | }; |
| 6367 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6368 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6369 | { |
| 6370 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6371 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6372 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6373 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6374 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6375 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6379 | { |
| 6380 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6381 | struct nfs_server *server = data->server; |
| 6382 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6383 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6384 | |
| 6385 | switch (task->tk_status) { |
| 6386 | case 0: |
| 6387 | renew_lease(server, data->timestamp); |
| 6388 | break; |
| 6389 | case -NFS4ERR_STALE_CLIENTID: |
| 6390 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6391 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6392 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6393 | case -NFS4ERR_LEASE_MOVED: |
| 6394 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6395 | if (nfs4_async_handle_error(task, server, |
| 6396 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6397 | rpc_restart_call_prepare(task); |
| 6398 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6399 | } |
| 6400 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6401 | static void nfs4_release_lockowner_release(void *calldata) |
| 6402 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6403 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6404 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6405 | kfree(calldata); |
| 6406 | } |
| 6407 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6408 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6409 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6410 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6411 | .rpc_release = nfs4_release_lockowner_release, |
| 6412 | }; |
| 6413 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6414 | static void |
| 6415 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6416 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6417 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6418 | struct rpc_message msg = { |
| 6419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6420 | }; |
| 6421 | |
| 6422 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6423 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6424 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6425 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6426 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6427 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6428 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6429 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6430 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6431 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6432 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6433 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6434 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6435 | msg.rpc_resp = &data->res; |
| 6436 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6437 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6438 | } |
| 6439 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6440 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6441 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6442 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6443 | struct dentry *unused, struct inode *inode, |
| 6444 | const char *key, const void *buf, |
| 6445 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6446 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6447 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6448 | } |
| 6449 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6450 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6451 | struct dentry *unused, struct inode *inode, |
| 6452 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6453 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6454 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6455 | } |
| 6456 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6457 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6458 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6459 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6460 | } |
| 6461 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6462 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6463 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6464 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6465 | struct dentry *unused, struct inode *inode, |
| 6466 | const char *key, const void *buf, |
| 6467 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6468 | { |
| 6469 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6470 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6471 | |
| 6472 | return -EOPNOTSUPP; |
| 6473 | } |
| 6474 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6475 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6476 | struct dentry *unused, struct inode *inode, |
| 6477 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6478 | { |
| 6479 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6480 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6481 | return -EOPNOTSUPP; |
| 6482 | } |
| 6483 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6484 | static ssize_t |
| 6485 | 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] | 6486 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6487 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6488 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6489 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6490 | len = security_inode_listsecurity(inode, list, list_len); |
| 6491 | if (list_len && len > list_len) |
| 6492 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6493 | } |
| 6494 | return len; |
| 6495 | } |
| 6496 | |
| 6497 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6498 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6499 | .get = nfs4_xattr_get_nfs4_label, |
| 6500 | .set = nfs4_xattr_set_nfs4_label, |
| 6501 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6502 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6503 | #else |
| 6504 | |
| 6505 | static ssize_t |
| 6506 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6507 | { |
| 6508 | return 0; |
| 6509 | } |
| 6510 | |
| 6511 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6512 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6513 | /* |
| 6514 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6515 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6516 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6517 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6518 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6519 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6520 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6521 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6522 | return; |
| 6523 | |
| 6524 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6525 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6526 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6527 | fattr->nlink = 2; |
| 6528 | } |
| 6529 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6530 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6531 | const struct qstr *name, |
| 6532 | struct nfs4_fs_locations *fs_locations, |
| 6533 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6534 | { |
| 6535 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6536 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6537 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6538 | }; |
| 6539 | struct nfs4_fs_locations_arg args = { |
| 6540 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6541 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6542 | .page = page, |
| 6543 | .bitmask = bitmask, |
| 6544 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6545 | struct nfs4_fs_locations_res res = { |
| 6546 | .fs_locations = fs_locations, |
| 6547 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6548 | struct rpc_message msg = { |
| 6549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6550 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6551 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6552 | }; |
| 6553 | int status; |
| 6554 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6555 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6556 | |
| 6557 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6558 | * is not supported */ |
| 6559 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6560 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6561 | else |
| 6562 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6563 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6564 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6565 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6566 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6567 | 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] | 6568 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6569 | return status; |
| 6570 | } |
| 6571 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6572 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6573 | const struct qstr *name, |
| 6574 | struct nfs4_fs_locations *fs_locations, |
| 6575 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6576 | { |
| 6577 | struct nfs4_exception exception = { }; |
| 6578 | int err; |
| 6579 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6580 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6581 | fs_locations, page); |
| 6582 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6583 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6584 | &exception); |
| 6585 | } while (exception.retry); |
| 6586 | return err; |
| 6587 | } |
| 6588 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6589 | /* |
| 6590 | * This operation also signals the server that this client is |
| 6591 | * performing migration recovery. The server can stop returning |
| 6592 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6593 | * appended to this compound to identify the client ID which is |
| 6594 | * performing recovery. |
| 6595 | */ |
| 6596 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6597 | struct nfs4_fs_locations *locations, |
| 6598 | struct page *page, struct rpc_cred *cred) |
| 6599 | { |
| 6600 | struct nfs_server *server = NFS_SERVER(inode); |
| 6601 | struct rpc_clnt *clnt = server->client; |
| 6602 | u32 bitmask[2] = { |
| 6603 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6604 | }; |
| 6605 | struct nfs4_fs_locations_arg args = { |
| 6606 | .clientid = server->nfs_client->cl_clientid, |
| 6607 | .fh = NFS_FH(inode), |
| 6608 | .page = page, |
| 6609 | .bitmask = bitmask, |
| 6610 | .migration = 1, /* skip LOOKUP */ |
| 6611 | .renew = 1, /* append RENEW */ |
| 6612 | }; |
| 6613 | struct nfs4_fs_locations_res res = { |
| 6614 | .fs_locations = locations, |
| 6615 | .migration = 1, |
| 6616 | .renew = 1, |
| 6617 | }; |
| 6618 | struct rpc_message msg = { |
| 6619 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6620 | .rpc_argp = &args, |
| 6621 | .rpc_resp = &res, |
| 6622 | .rpc_cred = cred, |
| 6623 | }; |
| 6624 | unsigned long now = jiffies; |
| 6625 | int status; |
| 6626 | |
| 6627 | nfs_fattr_init(&locations->fattr); |
| 6628 | locations->server = server; |
| 6629 | locations->nlocations = 0; |
| 6630 | |
| 6631 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6632 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6633 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6634 | &args.seq_args, &res.seq_res); |
| 6635 | if (status) |
| 6636 | return status; |
| 6637 | |
| 6638 | renew_lease(server, now); |
| 6639 | return 0; |
| 6640 | } |
| 6641 | |
| 6642 | #ifdef CONFIG_NFS_V4_1 |
| 6643 | |
| 6644 | /* |
| 6645 | * This operation also signals the server that this client is |
| 6646 | * performing migration recovery. The server can stop asserting |
| 6647 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6648 | * performing this operation is identified in the SEQUENCE |
| 6649 | * operation in this compound. |
| 6650 | * |
| 6651 | * When the client supports GETATTR(fs_locations_info), it can |
| 6652 | * be plumbed in here. |
| 6653 | */ |
| 6654 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6655 | struct nfs4_fs_locations *locations, |
| 6656 | struct page *page, struct rpc_cred *cred) |
| 6657 | { |
| 6658 | struct nfs_server *server = NFS_SERVER(inode); |
| 6659 | struct rpc_clnt *clnt = server->client; |
| 6660 | u32 bitmask[2] = { |
| 6661 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6662 | }; |
| 6663 | struct nfs4_fs_locations_arg args = { |
| 6664 | .fh = NFS_FH(inode), |
| 6665 | .page = page, |
| 6666 | .bitmask = bitmask, |
| 6667 | .migration = 1, /* skip LOOKUP */ |
| 6668 | }; |
| 6669 | struct nfs4_fs_locations_res res = { |
| 6670 | .fs_locations = locations, |
| 6671 | .migration = 1, |
| 6672 | }; |
| 6673 | struct rpc_message msg = { |
| 6674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6675 | .rpc_argp = &args, |
| 6676 | .rpc_resp = &res, |
| 6677 | .rpc_cred = cred, |
| 6678 | }; |
| 6679 | int status; |
| 6680 | |
| 6681 | nfs_fattr_init(&locations->fattr); |
| 6682 | locations->server = server; |
| 6683 | locations->nlocations = 0; |
| 6684 | |
| 6685 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6686 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6687 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6688 | &args.seq_args, &res.seq_res); |
| 6689 | if (status == NFS4_OK && |
| 6690 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6691 | status = -NFS4ERR_LEASE_MOVED; |
| 6692 | return status; |
| 6693 | } |
| 6694 | |
| 6695 | #endif /* CONFIG_NFS_V4_1 */ |
| 6696 | |
| 6697 | /** |
| 6698 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6699 | * @inode: inode on FSID that is migrating |
| 6700 | * @locations: result of query |
| 6701 | * @page: buffer |
| 6702 | * @cred: credential to use for this operation |
| 6703 | * |
| 6704 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6705 | * operation failed, or a negative errno if a local error occurred. |
| 6706 | * |
| 6707 | * On success, "locations" is filled in, but if the server has |
| 6708 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6709 | * asserted. |
| 6710 | * |
| 6711 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6712 | * from this client that require migration recovery. |
| 6713 | */ |
| 6714 | int nfs4_proc_get_locations(struct inode *inode, |
| 6715 | struct nfs4_fs_locations *locations, |
| 6716 | struct page *page, struct rpc_cred *cred) |
| 6717 | { |
| 6718 | struct nfs_server *server = NFS_SERVER(inode); |
| 6719 | struct nfs_client *clp = server->nfs_client; |
| 6720 | const struct nfs4_mig_recovery_ops *ops = |
| 6721 | clp->cl_mvops->mig_recovery_ops; |
| 6722 | struct nfs4_exception exception = { }; |
| 6723 | int status; |
| 6724 | |
| 6725 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6726 | (unsigned long long)server->fsid.major, |
| 6727 | (unsigned long long)server->fsid.minor, |
| 6728 | clp->cl_hostname); |
| 6729 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6730 | |
| 6731 | do { |
| 6732 | status = ops->get_locations(inode, locations, page, cred); |
| 6733 | if (status != -NFS4ERR_DELAY) |
| 6734 | break; |
| 6735 | nfs4_handle_exception(server, status, &exception); |
| 6736 | } while (exception.retry); |
| 6737 | return status; |
| 6738 | } |
| 6739 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6740 | /* |
| 6741 | * This operation also signals the server that this client is |
| 6742 | * performing "lease moved" recovery. The server can stop |
| 6743 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6744 | * is appended to this compound to identify the client ID which is |
| 6745 | * performing recovery. |
| 6746 | */ |
| 6747 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6748 | { |
| 6749 | struct nfs_server *server = NFS_SERVER(inode); |
| 6750 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6751 | struct rpc_clnt *clnt = server->client; |
| 6752 | struct nfs4_fsid_present_arg args = { |
| 6753 | .fh = NFS_FH(inode), |
| 6754 | .clientid = clp->cl_clientid, |
| 6755 | .renew = 1, /* append RENEW */ |
| 6756 | }; |
| 6757 | struct nfs4_fsid_present_res res = { |
| 6758 | .renew = 1, |
| 6759 | }; |
| 6760 | struct rpc_message msg = { |
| 6761 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6762 | .rpc_argp = &args, |
| 6763 | .rpc_resp = &res, |
| 6764 | .rpc_cred = cred, |
| 6765 | }; |
| 6766 | unsigned long now = jiffies; |
| 6767 | int status; |
| 6768 | |
| 6769 | res.fh = nfs_alloc_fhandle(); |
| 6770 | if (res.fh == NULL) |
| 6771 | return -ENOMEM; |
| 6772 | |
| 6773 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6774 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6775 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6776 | &args.seq_args, &res.seq_res); |
| 6777 | nfs_free_fhandle(res.fh); |
| 6778 | if (status) |
| 6779 | return status; |
| 6780 | |
| 6781 | do_renew_lease(clp, now); |
| 6782 | return 0; |
| 6783 | } |
| 6784 | |
| 6785 | #ifdef CONFIG_NFS_V4_1 |
| 6786 | |
| 6787 | /* |
| 6788 | * This operation also signals the server that this client is |
| 6789 | * performing "lease moved" recovery. The server can stop asserting |
| 6790 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6791 | * this operation is identified in the SEQUENCE operation in this |
| 6792 | * compound. |
| 6793 | */ |
| 6794 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6795 | { |
| 6796 | struct nfs_server *server = NFS_SERVER(inode); |
| 6797 | struct rpc_clnt *clnt = server->client; |
| 6798 | struct nfs4_fsid_present_arg args = { |
| 6799 | .fh = NFS_FH(inode), |
| 6800 | }; |
| 6801 | struct nfs4_fsid_present_res res = { |
| 6802 | }; |
| 6803 | struct rpc_message msg = { |
| 6804 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6805 | .rpc_argp = &args, |
| 6806 | .rpc_resp = &res, |
| 6807 | .rpc_cred = cred, |
| 6808 | }; |
| 6809 | int status; |
| 6810 | |
| 6811 | res.fh = nfs_alloc_fhandle(); |
| 6812 | if (res.fh == NULL) |
| 6813 | return -ENOMEM; |
| 6814 | |
| 6815 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6816 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6817 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6818 | &args.seq_args, &res.seq_res); |
| 6819 | nfs_free_fhandle(res.fh); |
| 6820 | if (status == NFS4_OK && |
| 6821 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6822 | status = -NFS4ERR_LEASE_MOVED; |
| 6823 | return status; |
| 6824 | } |
| 6825 | |
| 6826 | #endif /* CONFIG_NFS_V4_1 */ |
| 6827 | |
| 6828 | /** |
| 6829 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6830 | * @inode: inode on FSID to check |
| 6831 | * @cred: credential to use for this operation |
| 6832 | * |
| 6833 | * Server indicates whether the FSID is present, moved, or not |
| 6834 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6835 | * condition for this client ID. |
| 6836 | * |
| 6837 | * Returns NFS4_OK if the FSID is present on this server, |
| 6838 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6839 | * NFS4ERR code if some error occurred on the server, or a |
| 6840 | * negative errno if a local failure occurred. |
| 6841 | */ |
| 6842 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6843 | { |
| 6844 | struct nfs_server *server = NFS_SERVER(inode); |
| 6845 | struct nfs_client *clp = server->nfs_client; |
| 6846 | const struct nfs4_mig_recovery_ops *ops = |
| 6847 | clp->cl_mvops->mig_recovery_ops; |
| 6848 | struct nfs4_exception exception = { }; |
| 6849 | int status; |
| 6850 | |
| 6851 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6852 | (unsigned long long)server->fsid.major, |
| 6853 | (unsigned long long)server->fsid.minor, |
| 6854 | clp->cl_hostname); |
| 6855 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6856 | |
| 6857 | do { |
| 6858 | status = ops->fsid_present(inode, cred); |
| 6859 | if (status != -NFS4ERR_DELAY) |
| 6860 | break; |
| 6861 | nfs4_handle_exception(server, status, &exception); |
| 6862 | } while (exception.retry); |
| 6863 | return status; |
| 6864 | } |
| 6865 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6866 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6867 | * If 'use_integrity' is true and the state managment nfs_client |
| 6868 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6869 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6870 | * Considerations sections. Otherwise, just use the user cred with the |
| 6871 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6872 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6873 | 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] | 6874 | { |
| 6875 | int status; |
| 6876 | struct nfs4_secinfo_arg args = { |
| 6877 | .dir_fh = NFS_FH(dir), |
| 6878 | .name = name, |
| 6879 | }; |
| 6880 | struct nfs4_secinfo_res res = { |
| 6881 | .flavors = flavors, |
| 6882 | }; |
| 6883 | struct rpc_message msg = { |
| 6884 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6885 | .rpc_argp = &args, |
| 6886 | .rpc_resp = &res, |
| 6887 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6888 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6889 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6890 | |
| 6891 | if (use_integrity) { |
| 6892 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6893 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6894 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6895 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6896 | |
| 6897 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6898 | |
| 6899 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6900 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6901 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6902 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6903 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6904 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6905 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6906 | if (cred) |
| 6907 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6908 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6909 | return status; |
| 6910 | } |
| 6911 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6912 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6913 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6914 | { |
| 6915 | struct nfs4_exception exception = { }; |
| 6916 | int err; |
| 6917 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6918 | err = -NFS4ERR_WRONGSEC; |
| 6919 | |
| 6920 | /* try to use integrity protection with machine cred */ |
| 6921 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6922 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6923 | |
| 6924 | /* |
| 6925 | * if unable to use integrity protection, or SECINFO with |
| 6926 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6927 | * disallowed by spec, but exists in deployed servers) use |
| 6928 | * the current filesystem's rpc_client and the user cred. |
| 6929 | */ |
| 6930 | if (err == -NFS4ERR_WRONGSEC) |
| 6931 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6932 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6933 | trace_nfs4_secinfo(dir, name, err); |
| 6934 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6935 | &exception); |
| 6936 | } while (exception.retry); |
| 6937 | return err; |
| 6938 | } |
| 6939 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6940 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6941 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6942 | * Check the exchange flags returned by the server for invalid flags, having |
| 6943 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6944 | * DS flags set. |
| 6945 | */ |
| 6946 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6947 | { |
| 6948 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6949 | goto out_inval; |
| 6950 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6951 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6952 | goto out_inval; |
| 6953 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6954 | goto out_inval; |
| 6955 | return NFS_OK; |
| 6956 | out_inval: |
| 6957 | return -NFS4ERR_INVAL; |
| 6958 | } |
| 6959 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6960 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6961 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6962 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6963 | { |
| 6964 | if (a->server_scope_sz == b->server_scope_sz && |
| 6965 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6966 | return true; |
| 6967 | |
| 6968 | return false; |
| 6969 | } |
| 6970 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6971 | static void |
| 6972 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6973 | { |
| 6974 | } |
| 6975 | |
| 6976 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6977 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6978 | }; |
| 6979 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6980 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6981 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6982 | * |
| 6983 | * The 4.1 client currently uses the same TCP connection for the |
| 6984 | * fore and backchannel. |
| 6985 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6986 | static |
| 6987 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6988 | struct rpc_xprt *xprt, |
| 6989 | struct nfs_client *clp, |
| 6990 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6991 | { |
| 6992 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6993 | struct nfs41_bind_conn_to_session_args args = { |
| 6994 | .client = clp, |
| 6995 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6996 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6997 | struct nfs41_bind_conn_to_session_res res; |
| 6998 | struct rpc_message msg = { |
| 6999 | .rpc_proc = |
| 7000 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7001 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7002 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7003 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7004 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7005 | struct rpc_task_setup task_setup_data = { |
| 7006 | .rpc_client = clnt, |
| 7007 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7008 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7009 | .rpc_message = &msg, |
| 7010 | .flags = RPC_TASK_TIMEOUT, |
| 7011 | }; |
| 7012 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7013 | |
| 7014 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7015 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7016 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7017 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7018 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7019 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7020 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7021 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7022 | args.dir = NFS4_CDFC4_FORE; |
| 7023 | |
| 7024 | task = rpc_run_task(&task_setup_data); |
| 7025 | if (!IS_ERR(task)) { |
| 7026 | status = task->tk_status; |
| 7027 | rpc_put_task(task); |
| 7028 | } else |
| 7029 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7030 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7031 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7032 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7033 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7034 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7035 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7036 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7037 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7038 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7039 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7040 | __func__); |
| 7041 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7042 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7043 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7044 | 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] | 7045 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7046 | __func__); |
| 7047 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7048 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7049 | } |
| 7050 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7051 | out: |
| 7052 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7053 | return status; |
| 7054 | } |
| 7055 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7056 | struct rpc_bind_conn_calldata { |
| 7057 | struct nfs_client *clp; |
| 7058 | struct rpc_cred *cred; |
| 7059 | }; |
| 7060 | |
| 7061 | static int |
| 7062 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7063 | struct rpc_xprt *xprt, |
| 7064 | void *calldata) |
| 7065 | { |
| 7066 | struct rpc_bind_conn_calldata *p = calldata; |
| 7067 | |
| 7068 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7069 | } |
| 7070 | |
| 7071 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7072 | { |
| 7073 | struct rpc_bind_conn_calldata data = { |
| 7074 | .clp = clp, |
| 7075 | .cred = cred, |
| 7076 | }; |
| 7077 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7078 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7079 | } |
| 7080 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7081 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7082 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7083 | * 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] | 7084 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7085 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7086 | .how = SP4_MACH_CRED, |
| 7087 | .enforce.u.words = { |
| 7088 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7089 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7090 | 1 << (OP_CREATE_SESSION - 32) | |
| 7091 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7092 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7093 | }, |
| 7094 | .allow.u.words = { |
| 7095 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7096 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7097 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7098 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7099 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7100 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7101 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7102 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7103 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7104 | 1 << (OP_FREE_STATEID - 32) | |
| 7105 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7106 | } |
| 7107 | }; |
| 7108 | |
| 7109 | /* |
| 7110 | * Select the state protection mode for client `clp' given the server results |
| 7111 | * from exchange_id in `sp'. |
| 7112 | * |
| 7113 | * Returns 0 on success, negative errno otherwise. |
| 7114 | */ |
| 7115 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7116 | struct nfs41_state_protection *sp) |
| 7117 | { |
| 7118 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7119 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7120 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7121 | 1 << (OP_CREATE_SESSION - 32) | |
| 7122 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7123 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7124 | }; |
| 7125 | unsigned int i; |
| 7126 | |
| 7127 | if (sp->how == SP4_MACH_CRED) { |
| 7128 | /* Print state protect result */ |
| 7129 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7130 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7131 | if (test_bit(i, sp->enforce.u.longs)) |
| 7132 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7133 | if (test_bit(i, sp->allow.u.longs)) |
| 7134 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7135 | } |
| 7136 | |
| 7137 | /* make sure nothing is on enforce list that isn't supported */ |
| 7138 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7139 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7140 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7141 | return -EINVAL; |
| 7142 | } |
| 7143 | } |
| 7144 | |
| 7145 | /* |
| 7146 | * Minimal mode - state operations are allowed to use machine |
| 7147 | * credential. Note this already happens by default, so the |
| 7148 | * client doesn't have to do anything more than the negotiation. |
| 7149 | * |
| 7150 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7151 | * we're already using the machine cred for exchange_id |
| 7152 | * and will never use a different cred. |
| 7153 | */ |
| 7154 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7155 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7156 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7157 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7158 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7159 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7160 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7161 | } else { |
| 7162 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7163 | return -EINVAL; |
| 7164 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7165 | |
| 7166 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7167 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7168 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7169 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7170 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7171 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7172 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7173 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7174 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7175 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7176 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7177 | &clp->cl_sp4_flags); |
| 7178 | } |
| 7179 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7180 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7181 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7182 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7183 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7184 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7185 | |
| 7186 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7187 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7188 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7189 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7190 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7191 | |
| 7192 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7193 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7194 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7195 | } |
| 7196 | |
| 7197 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7198 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7199 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7200 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7201 | } |
| 7202 | |
| 7203 | return 0; |
| 7204 | } |
| 7205 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7206 | struct nfs41_exchange_id_data { |
| 7207 | struct nfs41_exchange_id_res res; |
| 7208 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7209 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7210 | int rpc_status; |
| 7211 | }; |
| 7212 | |
| 7213 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7214 | { |
| 7215 | struct nfs41_exchange_id_data *cdata = |
| 7216 | (struct nfs41_exchange_id_data *)data; |
| 7217 | struct nfs_client *clp = cdata->args.client; |
| 7218 | int status = task->tk_status; |
| 7219 | |
| 7220 | trace_nfs4_exchange_id(clp, status); |
| 7221 | |
| 7222 | if (status == 0) |
| 7223 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7224 | |
| 7225 | if (cdata->xprt && status == 0) { |
| 7226 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7227 | cdata->xprt); |
| 7228 | goto out; |
| 7229 | } |
| 7230 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7231 | if (status == 0) |
| 7232 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7233 | |
| 7234 | if (status == 0) { |
| 7235 | clp->cl_clientid = cdata->res.clientid; |
| 7236 | clp->cl_exchange_flags = cdata->res.flags; |
| 7237 | /* Client ID is not confirmed */ |
| 7238 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7239 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7240 | &clp->cl_session->session_state); |
| 7241 | clp->cl_seqid = cdata->res.seqid; |
| 7242 | } |
| 7243 | |
| 7244 | kfree(clp->cl_serverowner); |
| 7245 | clp->cl_serverowner = cdata->res.server_owner; |
| 7246 | cdata->res.server_owner = NULL; |
| 7247 | |
| 7248 | /* use the most recent implementation id */ |
| 7249 | kfree(clp->cl_implid); |
| 7250 | clp->cl_implid = cdata->res.impl_id; |
| 7251 | cdata->res.impl_id = NULL; |
| 7252 | |
| 7253 | if (clp->cl_serverscope != NULL && |
| 7254 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7255 | cdata->res.server_scope)) { |
| 7256 | dprintk("%s: server_scope mismatch detected\n", |
| 7257 | __func__); |
| 7258 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7259 | kfree(clp->cl_serverscope); |
| 7260 | clp->cl_serverscope = NULL; |
| 7261 | } |
| 7262 | |
| 7263 | if (clp->cl_serverscope == NULL) { |
| 7264 | clp->cl_serverscope = cdata->res.server_scope; |
| 7265 | cdata->res.server_scope = NULL; |
| 7266 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7267 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7268 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7269 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7270 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7271 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7272 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7273 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | static void nfs4_exchange_id_release(void *data) |
| 7277 | { |
| 7278 | struct nfs41_exchange_id_data *cdata = |
| 7279 | (struct nfs41_exchange_id_data *)data; |
| 7280 | |
| 7281 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7282 | if (cdata->xprt) { |
| 7283 | xprt_put(cdata->xprt); |
| 7284 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7285 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7286 | kfree(cdata->res.impl_id); |
| 7287 | kfree(cdata->res.server_scope); |
| 7288 | kfree(cdata->res.server_owner); |
| 7289 | kfree(cdata); |
| 7290 | } |
| 7291 | |
| 7292 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7293 | .rpc_call_done = nfs4_exchange_id_done, |
| 7294 | .rpc_release = nfs4_exchange_id_release, |
| 7295 | }; |
| 7296 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7297 | /* |
| 7298 | * _nfs4_proc_exchange_id() |
| 7299 | * |
| 7300 | * Wrapper for EXCHANGE_ID operation. |
| 7301 | */ |
| 7302 | 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] | 7303 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7304 | { |
| 7305 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7306 | struct rpc_message msg = { |
| 7307 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7308 | .rpc_cred = cred, |
| 7309 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7310 | struct rpc_task_setup task_setup_data = { |
| 7311 | .rpc_client = clp->cl_rpcclient, |
| 7312 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7313 | .rpc_message = &msg, |
| 7314 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7315 | }; |
| 7316 | struct nfs41_exchange_id_data *calldata; |
| 7317 | struct rpc_task *task; |
| 7318 | int status = -EIO; |
| 7319 | |
| 7320 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7321 | goto out; |
| 7322 | |
| 7323 | status = -ENOMEM; |
| 7324 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7325 | if (!calldata) |
| 7326 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7327 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7328 | if (!xprt) |
| 7329 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7330 | |
| 7331 | status = nfs4_init_uniform_client_string(clp); |
| 7332 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7333 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7334 | |
| 7335 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7336 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7337 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7338 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7339 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7340 | GFP_NOFS); |
| 7341 | status = -ENOMEM; |
| 7342 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7343 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7344 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7345 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7346 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7347 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7348 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7349 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7350 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7351 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7352 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7353 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7354 | switch (sp4_how) { |
| 7355 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7356 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7357 | break; |
| 7358 | |
| 7359 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7360 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7361 | break; |
| 7362 | |
| 7363 | default: |
| 7364 | /* unsupported! */ |
| 7365 | WARN_ON_ONCE(1); |
| 7366 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7367 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7368 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7369 | if (xprt) { |
| 7370 | calldata->xprt = xprt; |
| 7371 | task_setup_data.rpc_xprt = xprt; |
| 7372 | task_setup_data.flags = |
| 7373 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7374 | calldata->args.verifier = &clp->cl_confirm; |
| 7375 | } else { |
| 7376 | calldata->args.verifier = &verifier; |
| 7377 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7378 | calldata->args.client = clp; |
| 7379 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7380 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7381 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7382 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7383 | #else |
| 7384 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7385 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7386 | #endif |
| 7387 | msg.rpc_argp = &calldata->args; |
| 7388 | msg.rpc_resp = &calldata->res; |
| 7389 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7390 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7391 | task = rpc_run_task(&task_setup_data); |
| 7392 | if (IS_ERR(task)) { |
| 7393 | status = PTR_ERR(task); |
| 7394 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7395 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7396 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7397 | if (!xprt) { |
| 7398 | status = rpc_wait_for_completion_task(task); |
| 7399 | if (!status) |
| 7400 | status = calldata->rpc_status; |
| 7401 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7402 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7403 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7404 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7405 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7406 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7407 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7408 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7409 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7410 | clp->cl_implid->date.seconds, |
| 7411 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7412 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7413 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7414 | |
| 7415 | out_impl_id: |
| 7416 | kfree(calldata->res.impl_id); |
| 7417 | out_server_scope: |
| 7418 | kfree(calldata->res.server_scope); |
| 7419 | out_server_owner: |
| 7420 | kfree(calldata->res.server_owner); |
| 7421 | out_calldata: |
| 7422 | kfree(calldata); |
| 7423 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7424 | } |
| 7425 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7426 | /* |
| 7427 | * nfs4_proc_exchange_id() |
| 7428 | * |
| 7429 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7430 | * |
| 7431 | * Since the clientid has expired, all compounds using sessions |
| 7432 | * associated with the stale clientid will be returning |
| 7433 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7434 | * be in some phase of session reset. |
| 7435 | * |
| 7436 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7437 | */ |
| 7438 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7439 | { |
| 7440 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7441 | int status; |
| 7442 | |
| 7443 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7444 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7445 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7446 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7447 | if (!status) |
| 7448 | return 0; |
| 7449 | } |
| 7450 | |
| 7451 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7452 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7453 | } |
| 7454 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7455 | /** |
| 7456 | * nfs4_test_session_trunk |
| 7457 | * |
| 7458 | * This is an add_xprt_test() test function called from |
| 7459 | * rpc_clnt_setup_test_and_add_xprt. |
| 7460 | * |
| 7461 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7462 | * and is dereferrenced in nfs4_exchange_id_release |
| 7463 | * |
| 7464 | * Upon success, add the new transport to the rpc_clnt |
| 7465 | * |
| 7466 | * @clnt: struct rpc_clnt to get new transport |
| 7467 | * @xprt: the rpc_xprt to test |
| 7468 | * @data: call data for _nfs4_proc_exchange_id. |
| 7469 | */ |
| 7470 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7471 | void *data) |
| 7472 | { |
| 7473 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7474 | u32 sp4_how; |
| 7475 | |
| 7476 | dprintk("--> %s try %s\n", __func__, |
| 7477 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7478 | |
| 7479 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7480 | |
| 7481 | /* Test connection for session trunking. Async exchange_id call */ |
| 7482 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7483 | } |
| 7484 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7485 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7486 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7487 | struct rpc_cred *cred) |
| 7488 | { |
| 7489 | struct rpc_message msg = { |
| 7490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7491 | .rpc_argp = clp, |
| 7492 | .rpc_cred = cred, |
| 7493 | }; |
| 7494 | int status; |
| 7495 | |
| 7496 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7497 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7498 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7499 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7500 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7501 | return status; |
| 7502 | } |
| 7503 | |
| 7504 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7505 | struct rpc_cred *cred) |
| 7506 | { |
| 7507 | unsigned int loop; |
| 7508 | int ret; |
| 7509 | |
| 7510 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7511 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7512 | switch (ret) { |
| 7513 | case -NFS4ERR_DELAY: |
| 7514 | case -NFS4ERR_CLIENTID_BUSY: |
| 7515 | ssleep(1); |
| 7516 | break; |
| 7517 | default: |
| 7518 | return ret; |
| 7519 | } |
| 7520 | } |
| 7521 | return 0; |
| 7522 | } |
| 7523 | |
| 7524 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7525 | { |
| 7526 | struct rpc_cred *cred; |
| 7527 | int ret = 0; |
| 7528 | |
| 7529 | if (clp->cl_mvops->minor_version < 1) |
| 7530 | goto out; |
| 7531 | if (clp->cl_exchange_flags == 0) |
| 7532 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7533 | if (clp->cl_preserve_clid) |
| 7534 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7535 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7536 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7537 | if (cred) |
| 7538 | put_rpccred(cred); |
| 7539 | switch (ret) { |
| 7540 | case 0: |
| 7541 | case -NFS4ERR_STALE_CLIENTID: |
| 7542 | clp->cl_exchange_flags = 0; |
| 7543 | } |
| 7544 | out: |
| 7545 | return ret; |
| 7546 | } |
| 7547 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7548 | struct nfs4_get_lease_time_data { |
| 7549 | struct nfs4_get_lease_time_args *args; |
| 7550 | struct nfs4_get_lease_time_res *res; |
| 7551 | struct nfs_client *clp; |
| 7552 | }; |
| 7553 | |
| 7554 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7555 | void *calldata) |
| 7556 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7557 | struct nfs4_get_lease_time_data *data = |
| 7558 | (struct nfs4_get_lease_time_data *)calldata; |
| 7559 | |
| 7560 | dprintk("--> %s\n", __func__); |
| 7561 | /* just setup sequence, do not trigger session recovery |
| 7562 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7563 | nfs41_setup_sequence(data->clp->cl_session, |
| 7564 | &data->args->la_seq_args, |
| 7565 | &data->res->lr_seq_res, |
| 7566 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7567 | dprintk("<-- %s\n", __func__); |
| 7568 | } |
| 7569 | |
| 7570 | /* |
| 7571 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7572 | * from sequence operation or clientid errors. |
| 7573 | */ |
| 7574 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7575 | { |
| 7576 | struct nfs4_get_lease_time_data *data = |
| 7577 | (struct nfs4_get_lease_time_data *)calldata; |
| 7578 | |
| 7579 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7580 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7581 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7582 | switch (task->tk_status) { |
| 7583 | case -NFS4ERR_DELAY: |
| 7584 | case -NFS4ERR_GRACE: |
| 7585 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7586 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7587 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7588 | /* fall through */ |
| 7589 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7590 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7591 | return; |
| 7592 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7593 | dprintk("<-- %s\n", __func__); |
| 7594 | } |
| 7595 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7596 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7597 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7598 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7599 | }; |
| 7600 | |
| 7601 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7602 | { |
| 7603 | struct rpc_task *task; |
| 7604 | struct nfs4_get_lease_time_args args; |
| 7605 | struct nfs4_get_lease_time_res res = { |
| 7606 | .lr_fsinfo = fsinfo, |
| 7607 | }; |
| 7608 | struct nfs4_get_lease_time_data data = { |
| 7609 | .args = &args, |
| 7610 | .res = &res, |
| 7611 | .clp = clp, |
| 7612 | }; |
| 7613 | struct rpc_message msg = { |
| 7614 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7615 | .rpc_argp = &args, |
| 7616 | .rpc_resp = &res, |
| 7617 | }; |
| 7618 | struct rpc_task_setup task_setup = { |
| 7619 | .rpc_client = clp->cl_rpcclient, |
| 7620 | .rpc_message = &msg, |
| 7621 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7622 | .callback_data = &data, |
| 7623 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7624 | }; |
| 7625 | int status; |
| 7626 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7627 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7628 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7629 | dprintk("--> %s\n", __func__); |
| 7630 | task = rpc_run_task(&task_setup); |
| 7631 | |
| 7632 | if (IS_ERR(task)) |
| 7633 | status = PTR_ERR(task); |
| 7634 | else { |
| 7635 | status = task->tk_status; |
| 7636 | rpc_put_task(task); |
| 7637 | } |
| 7638 | dprintk("<-- %s return %d\n", __func__, status); |
| 7639 | |
| 7640 | return status; |
| 7641 | } |
| 7642 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7643 | /* |
| 7644 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7645 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7646 | * use them. |
| 7647 | * |
| 7648 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7649 | * always set csa_cachethis to FALSE because the current implementation |
| 7650 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7651 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7652 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7653 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7654 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7655 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7656 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7657 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7658 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7659 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7660 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7661 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7662 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7663 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7664 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7665 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7666 | |
| 7667 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7668 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7669 | __func__, |
| 7670 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7671 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7672 | |
| 7673 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7674 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7675 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7676 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7677 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7678 | 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] | 7679 | |
| 7680 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7681 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7682 | __func__, |
| 7683 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7684 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7685 | args->bc_attrs.max_reqs); |
| 7686 | } |
| 7687 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7688 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7689 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7690 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7691 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7692 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7693 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7694 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7695 | return -EINVAL; |
| 7696 | /* |
| 7697 | * Our requested max_ops is the minimum we need; we're not |
| 7698 | * prepared to break up compounds into smaller pieces than that. |
| 7699 | * So, no point even trying to continue if the server won't |
| 7700 | * cooperate: |
| 7701 | */ |
| 7702 | if (rcvd->max_ops < sent->max_ops) |
| 7703 | return -EINVAL; |
| 7704 | if (rcvd->max_reqs == 0) |
| 7705 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7706 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7707 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7708 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7709 | } |
| 7710 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7711 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7712 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7713 | { |
| 7714 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7715 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7716 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7717 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7718 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7719 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7720 | return -EINVAL; |
| 7721 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7722 | return -EINVAL; |
| 7723 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7724 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7725 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7726 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7727 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7728 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7729 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7730 | return 0; |
| 7731 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7732 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7733 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7734 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7735 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7736 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7737 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7738 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7739 | if (ret) |
| 7740 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7741 | return nfs4_verify_back_channel_attrs(args, res); |
| 7742 | } |
| 7743 | |
| 7744 | static void nfs4_update_session(struct nfs4_session *session, |
| 7745 | struct nfs41_create_session_res *res) |
| 7746 | { |
| 7747 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7748 | /* Mark client id and session as being confirmed */ |
| 7749 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7750 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7751 | session->flags = res->flags; |
| 7752 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7753 | if (res->flags & SESSION4_BACK_CHAN) |
| 7754 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7755 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7756 | } |
| 7757 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7758 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7759 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7760 | { |
| 7761 | struct nfs4_session *session = clp->cl_session; |
| 7762 | struct nfs41_create_session_args args = { |
| 7763 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7764 | .clientid = clp->cl_clientid, |
| 7765 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7766 | .cb_program = NFS4_CALLBACK, |
| 7767 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7768 | struct nfs41_create_session_res res; |
| 7769 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7770 | struct rpc_message msg = { |
| 7771 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7772 | .rpc_argp = &args, |
| 7773 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7774 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7775 | }; |
| 7776 | int status; |
| 7777 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7778 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7779 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7780 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7781 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7782 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7783 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7784 | switch (status) { |
| 7785 | case -NFS4ERR_STALE_CLIENTID: |
| 7786 | case -NFS4ERR_DELAY: |
| 7787 | case -ETIMEDOUT: |
| 7788 | case -EACCES: |
| 7789 | case -EAGAIN: |
| 7790 | goto out; |
| 7791 | }; |
| 7792 | |
| 7793 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7794 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7795 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7796 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7797 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7798 | if (status) |
| 7799 | goto out; |
| 7800 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7801 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7802 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7803 | return status; |
| 7804 | } |
| 7805 | |
| 7806 | /* |
| 7807 | * Issues a CREATE_SESSION operation to the server. |
| 7808 | * It is the responsibility of the caller to verify the session is |
| 7809 | * expired before calling this routine. |
| 7810 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7811 | 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] | 7812 | { |
| 7813 | int status; |
| 7814 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7815 | struct nfs4_session *session = clp->cl_session; |
| 7816 | |
| 7817 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7818 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7819 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7820 | if (status) |
| 7821 | goto out; |
| 7822 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7823 | /* Init or reset the session slot tables */ |
| 7824 | status = nfs4_setup_session_slot_tables(session); |
| 7825 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7826 | if (status) |
| 7827 | goto out; |
| 7828 | |
| 7829 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7830 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7831 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7832 | out: |
| 7833 | dprintk("<-- %s\n", __func__); |
| 7834 | return status; |
| 7835 | } |
| 7836 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7837 | /* |
| 7838 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7839 | * The caller must serialize access to this routine. |
| 7840 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7841 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7842 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7843 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7844 | struct rpc_message msg = { |
| 7845 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7846 | .rpc_argp = session, |
| 7847 | .rpc_cred = cred, |
| 7848 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7849 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7850 | |
| 7851 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7852 | |
| 7853 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7854 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7855 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7856 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7857 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7858 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7859 | |
| 7860 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7861 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7862 | "Session has been destroyed regardless...\n", status); |
| 7863 | |
| 7864 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7865 | return status; |
| 7866 | } |
| 7867 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7868 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7869 | * Renew the cl_session lease. |
| 7870 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7871 | struct nfs4_sequence_data { |
| 7872 | struct nfs_client *clp; |
| 7873 | struct nfs4_sequence_args args; |
| 7874 | struct nfs4_sequence_res res; |
| 7875 | }; |
| 7876 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7877 | static void nfs41_sequence_release(void *data) |
| 7878 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7879 | struct nfs4_sequence_data *calldata = data; |
| 7880 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7881 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7882 | if (atomic_read(&clp->cl_count) > 1) |
| 7883 | nfs4_schedule_state_renewal(clp); |
| 7884 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7885 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7886 | } |
| 7887 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7888 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7889 | { |
| 7890 | switch(task->tk_status) { |
| 7891 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7892 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7893 | return -EAGAIN; |
| 7894 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7895 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7896 | } |
| 7897 | return 0; |
| 7898 | } |
| 7899 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7900 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7901 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7902 | struct nfs4_sequence_data *calldata = data; |
| 7903 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7904 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7905 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7906 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7907 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7908 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7909 | if (task->tk_status < 0) { |
| 7910 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7911 | if (atomic_read(&clp->cl_count) == 1) |
| 7912 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7913 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7914 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7915 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7916 | return; |
| 7917 | } |
| 7918 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7919 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7920 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7921 | dprintk("<-- %s\n", __func__); |
| 7922 | } |
| 7923 | |
| 7924 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7925 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7926 | struct nfs4_sequence_data *calldata = data; |
| 7927 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7928 | struct nfs4_sequence_args *args; |
| 7929 | struct nfs4_sequence_res *res; |
| 7930 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7931 | args = task->tk_msg.rpc_argp; |
| 7932 | res = task->tk_msg.rpc_resp; |
| 7933 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7934 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7938 | .rpc_call_done = nfs41_sequence_call_done, |
| 7939 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7940 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7941 | }; |
| 7942 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7943 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7944 | struct rpc_cred *cred, |
| 7945 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7946 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7947 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7948 | struct rpc_message msg = { |
| 7949 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7950 | .rpc_cred = cred, |
| 7951 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7952 | struct rpc_task_setup task_setup_data = { |
| 7953 | .rpc_client = clp->cl_rpcclient, |
| 7954 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7955 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7956 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7957 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7958 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7959 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7960 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7961 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7962 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7963 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7964 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7965 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7966 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7967 | if (is_privileged) |
| 7968 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7969 | msg.rpc_argp = &calldata->args; |
| 7970 | msg.rpc_resp = &calldata->res; |
| 7971 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7972 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7973 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7974 | return rpc_run_task(&task_setup_data); |
| 7975 | } |
| 7976 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7977 | 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] | 7978 | { |
| 7979 | struct rpc_task *task; |
| 7980 | int ret = 0; |
| 7981 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7982 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7983 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7984 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7985 | if (IS_ERR(task)) |
| 7986 | ret = PTR_ERR(task); |
| 7987 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7988 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7989 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7990 | return ret; |
| 7991 | } |
| 7992 | |
| 7993 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7994 | { |
| 7995 | struct rpc_task *task; |
| 7996 | int ret; |
| 7997 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7998 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7999 | if (IS_ERR(task)) { |
| 8000 | ret = PTR_ERR(task); |
| 8001 | goto out; |
| 8002 | } |
| 8003 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8004 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8005 | ret = task->tk_status; |
| 8006 | rpc_put_task(task); |
| 8007 | out: |
| 8008 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8009 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8010 | } |
| 8011 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8012 | struct nfs4_reclaim_complete_data { |
| 8013 | struct nfs_client *clp; |
| 8014 | struct nfs41_reclaim_complete_args arg; |
| 8015 | struct nfs41_reclaim_complete_res res; |
| 8016 | }; |
| 8017 | |
| 8018 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8019 | { |
| 8020 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8021 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8022 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8023 | &calldata->arg.seq_args, |
| 8024 | &calldata->res.seq_res, |
| 8025 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8026 | } |
| 8027 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8028 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8029 | { |
| 8030 | switch(task->tk_status) { |
| 8031 | case 0: |
| 8032 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8033 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8034 | break; |
| 8035 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8036 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8037 | /* fall through */ |
| 8038 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8039 | return -EAGAIN; |
| 8040 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8041 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8042 | } |
| 8043 | return 0; |
| 8044 | } |
| 8045 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8046 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8047 | { |
| 8048 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8049 | struct nfs_client *clp = calldata->clp; |
| 8050 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8051 | |
| 8052 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8053 | if (!nfs41_sequence_done(task, res)) |
| 8054 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8055 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8056 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8057 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8058 | rpc_restart_call_prepare(task); |
| 8059 | return; |
| 8060 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8061 | dprintk("<-- %s\n", __func__); |
| 8062 | } |
| 8063 | |
| 8064 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8065 | { |
| 8066 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8067 | |
| 8068 | kfree(calldata); |
| 8069 | } |
| 8070 | |
| 8071 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8072 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8073 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8074 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8075 | }; |
| 8076 | |
| 8077 | /* |
| 8078 | * Issue a global reclaim complete. |
| 8079 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8080 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8081 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8082 | { |
| 8083 | struct nfs4_reclaim_complete_data *calldata; |
| 8084 | struct rpc_task *task; |
| 8085 | struct rpc_message msg = { |
| 8086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8087 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8088 | }; |
| 8089 | struct rpc_task_setup task_setup_data = { |
| 8090 | .rpc_client = clp->cl_rpcclient, |
| 8091 | .rpc_message = &msg, |
| 8092 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8093 | .flags = RPC_TASK_ASYNC, |
| 8094 | }; |
| 8095 | int status = -ENOMEM; |
| 8096 | |
| 8097 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8098 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8099 | if (calldata == NULL) |
| 8100 | goto out; |
| 8101 | calldata->clp = clp; |
| 8102 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8103 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8104 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8105 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8106 | msg.rpc_argp = &calldata->arg; |
| 8107 | msg.rpc_resp = &calldata->res; |
| 8108 | task_setup_data.callback_data = calldata; |
| 8109 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8110 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8111 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8112 | goto out; |
| 8113 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8114 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8115 | if (status == 0) |
| 8116 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8117 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8118 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8119 | out: |
| 8120 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8121 | return status; |
| 8122 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8123 | |
| 8124 | static void |
| 8125 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8126 | { |
| 8127 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8128 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8129 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8130 | |
| 8131 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8132 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8133 | &lgp->res.seq_res, task); |
| 8134 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8135 | } |
| 8136 | |
| 8137 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8138 | { |
| 8139 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8140 | |
| 8141 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8142 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8143 | dprintk("<-- %s\n", __func__); |
| 8144 | } |
| 8145 | |
| 8146 | static int |
| 8147 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8148 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8149 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8150 | struct inode *inode = lgp->args.inode; |
| 8151 | struct nfs_server *server = NFS_SERVER(inode); |
| 8152 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8153 | int nfs4err = task->tk_status; |
| 8154 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8155 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8156 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8157 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8158 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8159 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8160 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8161 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8162 | |
| 8163 | /* |
| 8164 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8165 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8166 | * retry go inband. |
| 8167 | */ |
| 8168 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8169 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8170 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8171 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8172 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8173 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8174 | */ |
| 8175 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8176 | status = -EOVERFLOW; |
| 8177 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8178 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8179 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8180 | * (or clients) writing to the same RAID stripe except when |
| 8181 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8182 | * |
| 8183 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8184 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8185 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8186 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8187 | if (lgp->args.minlength == 0) { |
| 8188 | status = -EOVERFLOW; |
| 8189 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8190 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8191 | status = -EBUSY; |
| 8192 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8193 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8194 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8195 | break; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8196 | case -NFS4ERR_EXPIRED: |
| 8197 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8198 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8199 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8200 | lo = NFS_I(inode)->layout; |
| 8201 | /* If the open stateid was bad, then recover it. */ |
| 8202 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8203 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8204 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8205 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8206 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8207 | break; |
| 8208 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8209 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8210 | /* |
| 8211 | * Mark the bad layout state as invalid, then retry |
| 8212 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8213 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8214 | spin_unlock(&inode->i_lock); |
| 8215 | pnfs_free_lseg_list(&head); |
| 8216 | status = -EAGAIN; |
| 8217 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8218 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8219 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8220 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8221 | if (!status) { |
| 8222 | if (exception->retry) |
| 8223 | status = -EAGAIN; |
| 8224 | else |
| 8225 | status = err; |
| 8226 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8227 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8228 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8229 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8230 | } |
| 8231 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8232 | static size_t max_response_pages(struct nfs_server *server) |
| 8233 | { |
| 8234 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8235 | return nfs_page_array_len(0, max_resp_sz); |
| 8236 | } |
| 8237 | |
| 8238 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8239 | { |
| 8240 | int i; |
| 8241 | |
| 8242 | if (!pages) |
| 8243 | return; |
| 8244 | |
| 8245 | for (i = 0; i < size; i++) { |
| 8246 | if (!pages[i]) |
| 8247 | break; |
| 8248 | __free_page(pages[i]); |
| 8249 | } |
| 8250 | kfree(pages); |
| 8251 | } |
| 8252 | |
| 8253 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8254 | { |
| 8255 | struct page **pages; |
| 8256 | int i; |
| 8257 | |
| 8258 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8259 | if (!pages) { |
| 8260 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8261 | return NULL; |
| 8262 | } |
| 8263 | |
| 8264 | for (i = 0; i < size; i++) { |
| 8265 | pages[i] = alloc_page(gfp_flags); |
| 8266 | if (!pages[i]) { |
| 8267 | dprintk("%s: failed to allocate page\n", __func__); |
| 8268 | nfs4_free_pages(pages, size); |
| 8269 | return NULL; |
| 8270 | } |
| 8271 | } |
| 8272 | |
| 8273 | return pages; |
| 8274 | } |
| 8275 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8276 | static void nfs4_layoutget_release(void *calldata) |
| 8277 | { |
| 8278 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8279 | struct inode *inode = lgp->args.inode; |
| 8280 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8281 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8282 | |
| 8283 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8284 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8285 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8286 | put_nfs_open_context(lgp->args.ctx); |
| 8287 | kfree(calldata); |
| 8288 | dprintk("<-- %s\n", __func__); |
| 8289 | } |
| 8290 | |
| 8291 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8292 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8293 | .rpc_call_done = nfs4_layoutget_done, |
| 8294 | .rpc_release = nfs4_layoutget_release, |
| 8295 | }; |
| 8296 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8297 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8298 | 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] | 8299 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8300 | struct inode *inode = lgp->args.inode; |
| 8301 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8302 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8303 | struct rpc_task *task; |
| 8304 | struct rpc_message msg = { |
| 8305 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8306 | .rpc_argp = &lgp->args, |
| 8307 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8308 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8309 | }; |
| 8310 | struct rpc_task_setup task_setup_data = { |
| 8311 | .rpc_client = server->client, |
| 8312 | .rpc_message = &msg, |
| 8313 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8314 | .callback_data = lgp, |
| 8315 | .flags = RPC_TASK_ASYNC, |
| 8316 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8317 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8318 | struct nfs4_exception exception = { |
| 8319 | .inode = inode, |
| 8320 | .timeout = *timeout, |
| 8321 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8322 | int status = 0; |
| 8323 | |
| 8324 | dprintk("--> %s\n", __func__); |
| 8325 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8326 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8327 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8328 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8329 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8330 | if (!lgp->args.layout.pages) { |
| 8331 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8332 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8333 | } |
| 8334 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8335 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8336 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8337 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8338 | 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] | 8339 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8340 | task = rpc_run_task(&task_setup_data); |
| 8341 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8342 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8343 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8344 | if (status == 0) { |
| 8345 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8346 | *timeout = exception.timeout; |
| 8347 | } |
| 8348 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8349 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8350 | &lgp->args.range, |
| 8351 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8352 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8353 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8354 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8355 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8356 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8357 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8358 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8359 | rpc_put_task(task); |
| 8360 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8361 | if (status) |
| 8362 | return ERR_PTR(status); |
| 8363 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8364 | } |
| 8365 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8366 | static void |
| 8367 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8368 | { |
| 8369 | struct nfs4_layoutreturn *lrp = calldata; |
| 8370 | |
| 8371 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8372 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8373 | &lrp->args.seq_args, |
| 8374 | &lrp->res.seq_res, |
| 8375 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8376 | } |
| 8377 | |
| 8378 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8379 | { |
| 8380 | struct nfs4_layoutreturn *lrp = calldata; |
| 8381 | struct nfs_server *server; |
| 8382 | |
| 8383 | dprintk("--> %s\n", __func__); |
| 8384 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8385 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8386 | return; |
| 8387 | |
| 8388 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8389 | switch (task->tk_status) { |
| 8390 | default: |
| 8391 | task->tk_status = 0; |
| 8392 | case 0: |
| 8393 | break; |
| 8394 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8395 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8396 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8397 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8398 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8399 | return; |
| 8400 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8401 | dprintk("<-- %s\n", __func__); |
| 8402 | } |
| 8403 | |
| 8404 | static void nfs4_layoutreturn_release(void *calldata) |
| 8405 | { |
| 8406 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8407 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8408 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8409 | |
| 8410 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8411 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8412 | if (lrp->res.lrs_present) { |
| 8413 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8414 | &lrp->args.range, |
| 8415 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8416 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8417 | } else |
| 8418 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8419 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8420 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8421 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8422 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8423 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8424 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8425 | kfree(calldata); |
| 8426 | dprintk("<-- %s\n", __func__); |
| 8427 | } |
| 8428 | |
| 8429 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8430 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8431 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8432 | .rpc_release = nfs4_layoutreturn_release, |
| 8433 | }; |
| 8434 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8435 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8436 | { |
| 8437 | struct rpc_task *task; |
| 8438 | struct rpc_message msg = { |
| 8439 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8440 | .rpc_argp = &lrp->args, |
| 8441 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8442 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8443 | }; |
| 8444 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8445 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8446 | .rpc_message = &msg, |
| 8447 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8448 | .callback_data = lrp, |
| 8449 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8450 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8451 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8452 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8453 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8454 | &task_setup_data.rpc_client, &msg); |
| 8455 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8456 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8457 | if (!sync) { |
| 8458 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8459 | if (!lrp->inode) { |
| 8460 | nfs4_layoutreturn_release(lrp); |
| 8461 | return -EAGAIN; |
| 8462 | } |
| 8463 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8464 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8465 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8466 | task = rpc_run_task(&task_setup_data); |
| 8467 | if (IS_ERR(task)) |
| 8468 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8469 | if (sync) |
| 8470 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8471 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8472 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8473 | rpc_put_task(task); |
| 8474 | return status; |
| 8475 | } |
| 8476 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8477 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8478 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8479 | struct pnfs_device *pdev, |
| 8480 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8481 | { |
| 8482 | struct nfs4_getdeviceinfo_args args = { |
| 8483 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8484 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8485 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8486 | }; |
| 8487 | struct nfs4_getdeviceinfo_res res = { |
| 8488 | .pdev = pdev, |
| 8489 | }; |
| 8490 | struct rpc_message msg = { |
| 8491 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8492 | .rpc_argp = &args, |
| 8493 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8494 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8495 | }; |
| 8496 | int status; |
| 8497 | |
| 8498 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8499 | 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] | 8500 | if (res.notification & ~args.notify_types) |
| 8501 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8502 | if (res.notification != args.notify_types) |
| 8503 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8504 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8505 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8506 | |
| 8507 | return status; |
| 8508 | } |
| 8509 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8510 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8511 | struct pnfs_device *pdev, |
| 8512 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8513 | { |
| 8514 | struct nfs4_exception exception = { }; |
| 8515 | int err; |
| 8516 | |
| 8517 | do { |
| 8518 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8519 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8520 | &exception); |
| 8521 | } while (exception.retry); |
| 8522 | return err; |
| 8523 | } |
| 8524 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8525 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8526 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8527 | { |
| 8528 | struct nfs4_layoutcommit_data *data = calldata; |
| 8529 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8530 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8531 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8532 | nfs41_setup_sequence(session, |
| 8533 | &data->args.seq_args, |
| 8534 | &data->res.seq_res, |
| 8535 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8536 | } |
| 8537 | |
| 8538 | static void |
| 8539 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8540 | { |
| 8541 | struct nfs4_layoutcommit_data *data = calldata; |
| 8542 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8543 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8544 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8545 | return; |
| 8546 | |
| 8547 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8548 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8549 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8550 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8551 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8552 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8553 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8554 | break; |
| 8555 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8556 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8557 | rpc_restart_call_prepare(task); |
| 8558 | return; |
| 8559 | } |
| 8560 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8561 | } |
| 8562 | |
| 8563 | static void nfs4_layoutcommit_release(void *calldata) |
| 8564 | { |
| 8565 | struct nfs4_layoutcommit_data *data = calldata; |
| 8566 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8567 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8568 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8569 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8570 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8571 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8572 | kfree(data); |
| 8573 | } |
| 8574 | |
| 8575 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8576 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8577 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8578 | .rpc_release = nfs4_layoutcommit_release, |
| 8579 | }; |
| 8580 | |
| 8581 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8582 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8583 | { |
| 8584 | struct rpc_message msg = { |
| 8585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8586 | .rpc_argp = &data->args, |
| 8587 | .rpc_resp = &data->res, |
| 8588 | .rpc_cred = data->cred, |
| 8589 | }; |
| 8590 | struct rpc_task_setup task_setup_data = { |
| 8591 | .task = &data->task, |
| 8592 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8593 | .rpc_message = &msg, |
| 8594 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8595 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8596 | }; |
| 8597 | struct rpc_task *task; |
| 8598 | int status = 0; |
| 8599 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8600 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8601 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8602 | data->args.lastbytewritten, |
| 8603 | data->args.inode->i_ino); |
| 8604 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8605 | if (!sync) { |
| 8606 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8607 | if (data->inode == NULL) { |
| 8608 | nfs4_layoutcommit_release(data); |
| 8609 | return -EAGAIN; |
| 8610 | } |
| 8611 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8612 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8613 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8614 | task = rpc_run_task(&task_setup_data); |
| 8615 | if (IS_ERR(task)) |
| 8616 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8617 | if (sync) |
| 8618 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8619 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8620 | dprintk("%s: status %d\n", __func__, status); |
| 8621 | rpc_put_task(task); |
| 8622 | return status; |
| 8623 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8624 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8625 | /** |
| 8626 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8627 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8628 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8629 | static int |
| 8630 | _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] | 8631 | struct nfs_fsinfo *info, |
| 8632 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8633 | { |
| 8634 | struct nfs41_secinfo_no_name_args args = { |
| 8635 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8636 | }; |
| 8637 | struct nfs4_secinfo_res res = { |
| 8638 | .flavors = flavors, |
| 8639 | }; |
| 8640 | struct rpc_message msg = { |
| 8641 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8642 | .rpc_argp = &args, |
| 8643 | .rpc_resp = &res, |
| 8644 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8645 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8646 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8647 | int status; |
| 8648 | |
| 8649 | if (use_integrity) { |
| 8650 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8651 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8652 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8653 | } |
| 8654 | |
| 8655 | dprintk("--> %s\n", __func__); |
| 8656 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8657 | &res.seq_res, 0); |
| 8658 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8659 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8660 | if (cred) |
| 8661 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8662 | |
| 8663 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8664 | } |
| 8665 | |
| 8666 | static int |
| 8667 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8668 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8669 | { |
| 8670 | struct nfs4_exception exception = { }; |
| 8671 | int err; |
| 8672 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8673 | /* first try using integrity protection */ |
| 8674 | err = -NFS4ERR_WRONGSEC; |
| 8675 | |
| 8676 | /* try to use integrity protection with machine cred */ |
| 8677 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8678 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8679 | flavors, true); |
| 8680 | |
| 8681 | /* |
| 8682 | * if unable to use integrity protection, or SECINFO with |
| 8683 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8684 | * disallowed by spec, but exists in deployed servers) use |
| 8685 | * the current filesystem's rpc_client and the user cred. |
| 8686 | */ |
| 8687 | if (err == -NFS4ERR_WRONGSEC) |
| 8688 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8689 | flavors, false); |
| 8690 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8691 | switch (err) { |
| 8692 | case 0: |
| 8693 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8694 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8695 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8696 | default: |
| 8697 | err = nfs4_handle_exception(server, err, &exception); |
| 8698 | } |
| 8699 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8700 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8701 | return err; |
| 8702 | } |
| 8703 | |
| 8704 | static int |
| 8705 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8706 | struct nfs_fsinfo *info) |
| 8707 | { |
| 8708 | int err; |
| 8709 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8710 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8711 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8712 | struct nfs4_secinfo4 *secinfo; |
| 8713 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8714 | |
| 8715 | page = alloc_page(GFP_KERNEL); |
| 8716 | if (!page) { |
| 8717 | err = -ENOMEM; |
| 8718 | goto out; |
| 8719 | } |
| 8720 | |
| 8721 | flavors = page_address(page); |
| 8722 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8723 | |
| 8724 | /* |
| 8725 | * Fall back on "guess and check" method if |
| 8726 | * the server doesn't support SECINFO_NO_NAME |
| 8727 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8728 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8729 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8730 | goto out_freepage; |
| 8731 | } |
| 8732 | if (err) |
| 8733 | goto out_freepage; |
| 8734 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8735 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8736 | secinfo = &flavors->flavors[i]; |
| 8737 | |
| 8738 | switch (secinfo->flavor) { |
| 8739 | case RPC_AUTH_NULL: |
| 8740 | case RPC_AUTH_UNIX: |
| 8741 | case RPC_AUTH_GSS: |
| 8742 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8743 | &secinfo->flavor_info); |
| 8744 | break; |
| 8745 | default: |
| 8746 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8747 | break; |
| 8748 | } |
| 8749 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8750 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8751 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8752 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8753 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8754 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8755 | info, flavor); |
| 8756 | if (!err) |
| 8757 | break; |
| 8758 | } |
| 8759 | } |
| 8760 | |
| 8761 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8762 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8763 | |
| 8764 | out_freepage: |
| 8765 | put_page(page); |
| 8766 | if (err == -EACCES) |
| 8767 | return -EPERM; |
| 8768 | out: |
| 8769 | return err; |
| 8770 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8771 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8772 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8773 | nfs4_stateid *stateid, |
| 8774 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8775 | { |
| 8776 | int status; |
| 8777 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8778 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8779 | }; |
| 8780 | struct nfs41_test_stateid_res res; |
| 8781 | struct rpc_message msg = { |
| 8782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8783 | .rpc_argp = &args, |
| 8784 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8785 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8786 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8787 | struct rpc_clnt *rpc_client = server->client; |
| 8788 | |
| 8789 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8790 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8791 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8792 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8793 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8794 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8795 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8796 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8797 | if (status != NFS_OK) { |
| 8798 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8799 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8800 | } |
| 8801 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8802 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8803 | } |
| 8804 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8805 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8806 | int err, struct nfs4_exception *exception) |
| 8807 | { |
| 8808 | exception->retry = 0; |
| 8809 | switch(err) { |
| 8810 | case -NFS4ERR_DELAY: |
| 8811 | nfs4_handle_exception(server, err, exception); |
| 8812 | break; |
| 8813 | case -NFS4ERR_BADSESSION: |
| 8814 | case -NFS4ERR_BADSLOT: |
| 8815 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8816 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8817 | case -NFS4ERR_DEADSESSION: |
| 8818 | nfs4_do_handle_exception(server, err, exception); |
| 8819 | } |
| 8820 | } |
| 8821 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8822 | /** |
| 8823 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8824 | * |
| 8825 | * @server: server / transport on which to perform the operation |
| 8826 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8827 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8828 | * |
| 8829 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8830 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8831 | * failed or the state ID is not currently valid. |
| 8832 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8833 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8834 | nfs4_stateid *stateid, |
| 8835 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8836 | { |
| 8837 | struct nfs4_exception exception = { }; |
| 8838 | int err; |
| 8839 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8840 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8841 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8842 | } while (exception.retry); |
| 8843 | return err; |
| 8844 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8845 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8846 | struct nfs_free_stateid_data { |
| 8847 | struct nfs_server *server; |
| 8848 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8849 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8850 | }; |
| 8851 | |
| 8852 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8853 | { |
| 8854 | struct nfs_free_stateid_data *data = calldata; |
| 8855 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8856 | &data->args.seq_args, |
| 8857 | &data->res.seq_res, |
| 8858 | task); |
| 8859 | } |
| 8860 | |
| 8861 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8862 | { |
| 8863 | struct nfs_free_stateid_data *data = calldata; |
| 8864 | |
| 8865 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8866 | |
| 8867 | switch (task->tk_status) { |
| 8868 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8869 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8870 | rpc_restart_call_prepare(task); |
| 8871 | } |
| 8872 | } |
| 8873 | |
| 8874 | static void nfs41_free_stateid_release(void *calldata) |
| 8875 | { |
| 8876 | kfree(calldata); |
| 8877 | } |
| 8878 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8879 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8880 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8881 | .rpc_call_done = nfs41_free_stateid_done, |
| 8882 | .rpc_release = nfs41_free_stateid_release, |
| 8883 | }; |
| 8884 | |
| 8885 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8886 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8887 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8888 | bool privileged) |
| 8889 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8890 | struct rpc_message msg = { |
| 8891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8892 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8893 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8894 | struct rpc_task_setup task_setup = { |
| 8895 | .rpc_client = server->client, |
| 8896 | .rpc_message = &msg, |
| 8897 | .callback_ops = &nfs41_free_stateid_ops, |
| 8898 | .flags = RPC_TASK_ASYNC, |
| 8899 | }; |
| 8900 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8901 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8902 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8903 | &task_setup.rpc_client, &msg); |
| 8904 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8905 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8906 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8907 | if (!data) |
| 8908 | return ERR_PTR(-ENOMEM); |
| 8909 | data->server = server; |
| 8910 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8911 | |
| 8912 | task_setup.callback_data = data; |
| 8913 | |
| 8914 | msg.rpc_argp = &data->args; |
| 8915 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8916 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8917 | if (privileged) |
| 8918 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8919 | |
| 8920 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8921 | } |
| 8922 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8923 | /** |
| 8924 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8925 | * |
| 8926 | * @server: server / transport on which to perform the operation |
| 8927 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8928 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8929 | * |
| 8930 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8931 | * negative NFS4ERR value is returned. |
| 8932 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8933 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8934 | nfs4_stateid *stateid, |
| 8935 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8936 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8937 | struct rpc_task *task; |
| 8938 | int ret; |
| 8939 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8940 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8941 | if (IS_ERR(task)) |
| 8942 | return PTR_ERR(task); |
| 8943 | ret = rpc_wait_for_completion_task(task); |
| 8944 | if (!ret) |
| 8945 | ret = task->tk_status; |
| 8946 | rpc_put_task(task); |
| 8947 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8948 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8949 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8950 | static void |
| 8951 | 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] | 8952 | { |
| 8953 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8954 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8955 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8956 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8957 | nfs4_free_lock_state(server, lsp); |
| 8958 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8959 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8960 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8961 | } |
| 8962 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8963 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8964 | const nfs4_stateid *s2) |
| 8965 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8966 | if (s1->type != s2->type) |
| 8967 | return false; |
| 8968 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8969 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8970 | return false; |
| 8971 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8972 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8973 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8974 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8975 | return true; |
| 8976 | |
| 8977 | return false; |
| 8978 | } |
| 8979 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8980 | #endif /* CONFIG_NFS_V4_1 */ |
| 8981 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8982 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8983 | const nfs4_stateid *s2) |
| 8984 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8985 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8986 | } |
| 8987 | |
| 8988 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8989 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8990 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8991 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8992 | .recover_open = nfs4_open_reclaim, |
| 8993 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8994 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8995 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8996 | }; |
| 8997 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8998 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8999 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9000 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9001 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9002 | .recover_open = nfs4_open_reclaim, |
| 9003 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9004 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9005 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9006 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9007 | }; |
| 9008 | #endif /* CONFIG_NFS_V4_1 */ |
| 9009 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9010 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9011 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9012 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9013 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9014 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9015 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9016 | }; |
| 9017 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9018 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9019 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9020 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9021 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9022 | .recover_open = nfs41_open_expired, |
| 9023 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9024 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9025 | }; |
| 9026 | #endif /* CONFIG_NFS_V4_1 */ |
| 9027 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9028 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9029 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9030 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9031 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9032 | }; |
| 9033 | |
| 9034 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9035 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9036 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9037 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9038 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9039 | }; |
| 9040 | #endif |
| 9041 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9042 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9043 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9044 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9045 | }; |
| 9046 | |
| 9047 | #if defined(CONFIG_NFS_V4_1) |
| 9048 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9049 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9050 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9051 | }; |
| 9052 | #endif /* CONFIG_NFS_V4_1 */ |
| 9053 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9054 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9055 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9056 | .init_caps = NFS_CAP_READDIRPLUS |
| 9057 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9058 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9059 | .init_client = nfs40_init_client, |
| 9060 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9061 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9062 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9063 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9064 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9065 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9066 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9067 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9068 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9069 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9070 | }; |
| 9071 | |
| 9072 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9073 | static struct nfs_seqid * |
| 9074 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9075 | { |
| 9076 | return NULL; |
| 9077 | } |
| 9078 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9079 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9080 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9081 | .init_caps = NFS_CAP_READDIRPLUS |
| 9082 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9083 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9084 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9085 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9086 | .init_client = nfs41_init_client, |
| 9087 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9088 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9089 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9090 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9091 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9092 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9093 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9094 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9095 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9096 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9097 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9098 | }; |
| 9099 | #endif |
| 9100 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9101 | #if defined(CONFIG_NFS_V4_2) |
| 9102 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9103 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9104 | .init_caps = NFS_CAP_READDIRPLUS |
| 9105 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9106 | | NFS_CAP_POSIX_LOCK |
| 9107 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9108 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9109 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9110 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9111 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9112 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9113 | | NFS_CAP_LAYOUTSTATS |
| 9114 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9115 | .init_client = nfs41_init_client, |
| 9116 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9117 | .match_stateid = nfs41_match_stateid, |
| 9118 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9119 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9120 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9121 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9122 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9123 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9124 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9125 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9126 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9127 | }; |
| 9128 | #endif |
| 9129 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9130 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9131 | [0] = &nfs_v4_0_minor_ops, |
| 9132 | #if defined(CONFIG_NFS_V4_1) |
| 9133 | [1] = &nfs_v4_1_minor_ops, |
| 9134 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9135 | #if defined(CONFIG_NFS_V4_2) |
| 9136 | [2] = &nfs_v4_2_minor_ops, |
| 9137 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9138 | }; |
| 9139 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9140 | 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] | 9141 | { |
| 9142 | ssize_t error, error2; |
| 9143 | |
| 9144 | error = generic_listxattr(dentry, list, size); |
| 9145 | if (error < 0) |
| 9146 | return error; |
| 9147 | if (list) { |
| 9148 | list += error; |
| 9149 | size -= error; |
| 9150 | } |
| 9151 | |
| 9152 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9153 | if (error2 < 0) |
| 9154 | return error2; |
| 9155 | return error + error2; |
| 9156 | } |
| 9157 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9158 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9159 | .create = nfs_create, |
| 9160 | .lookup = nfs_lookup, |
| 9161 | .atomic_open = nfs_atomic_open, |
| 9162 | .link = nfs_link, |
| 9163 | .unlink = nfs_unlink, |
| 9164 | .symlink = nfs_symlink, |
| 9165 | .mkdir = nfs_mkdir, |
| 9166 | .rmdir = nfs_rmdir, |
| 9167 | .mknod = nfs_mknod, |
| 9168 | .rename = nfs_rename, |
| 9169 | .permission = nfs_permission, |
| 9170 | .getattr = nfs_getattr, |
| 9171 | .setattr = nfs_setattr, |
| 9172 | .getxattr = generic_getxattr, |
| 9173 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9174 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9175 | .removexattr = generic_removexattr, |
| 9176 | }; |
| 9177 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9178 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9179 | .permission = nfs_permission, |
| 9180 | .getattr = nfs_getattr, |
| 9181 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9182 | .getxattr = generic_getxattr, |
| 9183 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9184 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9185 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9186 | }; |
| 9187 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9188 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9189 | .version = 4, /* protocol version */ |
| 9190 | .dentry_ops = &nfs4_dentry_operations, |
| 9191 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9192 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9193 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9194 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9195 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9196 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9197 | .getattr = nfs4_proc_getattr, |
| 9198 | .setattr = nfs4_proc_setattr, |
| 9199 | .lookup = nfs4_proc_lookup, |
| 9200 | .access = nfs4_proc_access, |
| 9201 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9202 | .create = nfs4_proc_create, |
| 9203 | .remove = nfs4_proc_remove, |
| 9204 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9205 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9206 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9207 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9208 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9209 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9210 | .link = nfs4_proc_link, |
| 9211 | .symlink = nfs4_proc_symlink, |
| 9212 | .mkdir = nfs4_proc_mkdir, |
| 9213 | .rmdir = nfs4_proc_remove, |
| 9214 | .readdir = nfs4_proc_readdir, |
| 9215 | .mknod = nfs4_proc_mknod, |
| 9216 | .statfs = nfs4_proc_statfs, |
| 9217 | .fsinfo = nfs4_proc_fsinfo, |
| 9218 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9219 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9220 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9221 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9222 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9223 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9224 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9225 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9226 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9227 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9228 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9229 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9230 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9231 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9232 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9233 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9234 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9235 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9236 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9237 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9238 | .create_server = nfs4_create_server, |
| 9239 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9240 | }; |
| 9241 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9242 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9243 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9244 | .list = nfs4_xattr_list_nfs4_acl, |
| 9245 | .get = nfs4_xattr_get_nfs4_acl, |
| 9246 | .set = nfs4_xattr_set_nfs4_acl, |
| 9247 | }; |
| 9248 | |
| 9249 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9250 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9251 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9252 | &nfs4_xattr_nfs4_label_handler, |
| 9253 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9254 | NULL |
| 9255 | }; |
| 9256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9257 | /* |
| 9258 | * Local variables: |
| 9259 | * c-basic-offset: 8 |
| 9260 | * End: |
| 9261 | */ |