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, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 97 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 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 *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 102 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 103 | struct rpc_cred *, bool); |
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 |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 229 | | FATTR4_WORD0_FILEID, |
| 230 | }; |
| 231 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 232 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | FATTR4_WORD0_FILES_AVAIL |
| 234 | | FATTR4_WORD0_FILES_FREE |
| 235 | | FATTR4_WORD0_FILES_TOTAL, |
| 236 | FATTR4_WORD1_SPACE_AVAIL |
| 237 | | FATTR4_WORD1_SPACE_FREE |
| 238 | | FATTR4_WORD1_SPACE_TOTAL |
| 239 | }; |
| 240 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 241 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | FATTR4_WORD0_MAXLINK |
| 243 | | FATTR4_WORD0_MAXNAME, |
| 244 | 0 |
| 245 | }; |
| 246 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 247 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | | FATTR4_WORD0_MAXREAD |
| 249 | | FATTR4_WORD0_MAXWRITE |
| 250 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 251 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 252 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 253 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 254 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | }; |
| 256 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 257 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 258 | FATTR4_WORD0_TYPE |
| 259 | | FATTR4_WORD0_CHANGE |
| 260 | | FATTR4_WORD0_SIZE |
| 261 | | FATTR4_WORD0_FSID |
| 262 | | FATTR4_WORD0_FILEID |
| 263 | | FATTR4_WORD0_FS_LOCATIONS, |
| 264 | FATTR4_WORD1_MODE |
| 265 | | FATTR4_WORD1_NUMLINKS |
| 266 | | FATTR4_WORD1_OWNER |
| 267 | | FATTR4_WORD1_OWNER_GROUP |
| 268 | | FATTR4_WORD1_RAWDEV |
| 269 | | FATTR4_WORD1_SPACE_USED |
| 270 | | FATTR4_WORD1_TIME_ACCESS |
| 271 | | FATTR4_WORD1_TIME_METADATA |
| 272 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 273 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 274 | }; |
| 275 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 276 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | struct nfs4_readdir_arg *readdir) |
| 278 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 279 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 282 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | readdir->cookie = 0; |
| 288 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 289 | if (cookie == 2) |
| 290 | return; |
| 291 | |
| 292 | /* |
| 293 | * NFSv4 servers do not return entries for '.' and '..' |
| 294 | * Therefore, we fake these entries here. We let '.' |
| 295 | * have cookie 0 and '..' have cookie 1. Note that |
| 296 | * when talking to the server, we always send cookie 0 |
| 297 | * instead of 1 or 2. |
| 298 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 299 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | if (cookie == 0) { |
| 302 | *p++ = xdr_one; /* next */ |
| 303 | *p++ = xdr_zero; /* cookie, first word */ |
| 304 | *p++ = xdr_one; /* cookie, second word */ |
| 305 | *p++ = xdr_one; /* entry len */ |
| 306 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 307 | p++; |
| 308 | *p++ = xdr_one; /* bitmap length */ |
| 309 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 310 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 311 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | *p++ = xdr_one; /* next */ |
| 315 | *p++ = xdr_zero; /* cookie, first word */ |
| 316 | *p++ = xdr_two; /* cookie, second word */ |
| 317 | *p++ = xdr_two; /* entry len */ |
| 318 | memcpy(p, "..\0\0", 4); /* entry */ |
| 319 | p++; |
| 320 | *p++ = xdr_one; /* bitmap length */ |
| 321 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 322 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 323 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | readdir->pgbase = (char *)p - (char *)start; |
| 326 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 327 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 330 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 331 | nfs4_stateid *stateid, |
| 332 | struct rpc_cred *cred) |
| 333 | { |
| 334 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 335 | |
| 336 | ops->test_and_free_expired(server, stateid, cred); |
| 337 | } |
| 338 | |
| 339 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 340 | nfs4_stateid *stateid, |
| 341 | struct rpc_cred *cred) |
| 342 | { |
| 343 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 344 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 345 | } |
| 346 | |
| 347 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 348 | const nfs4_stateid *stateid, |
| 349 | struct rpc_cred *cred) |
| 350 | { |
| 351 | nfs4_stateid tmp; |
| 352 | |
| 353 | nfs4_stateid_copy(&tmp, stateid); |
| 354 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 355 | } |
| 356 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 357 | static long nfs4_update_delay(long *timeout) |
| 358 | { |
| 359 | long ret; |
| 360 | if (!timeout) |
| 361 | return NFS4_POLL_RETRY_MAX; |
| 362 | if (*timeout <= 0) |
| 363 | *timeout = NFS4_POLL_RETRY_MIN; |
| 364 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 365 | *timeout = NFS4_POLL_RETRY_MAX; |
| 366 | ret = *timeout; |
| 367 | *timeout <<= 1; |
| 368 | return ret; |
| 369 | } |
| 370 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 371 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 372 | { |
| 373 | int res = 0; |
| 374 | |
| 375 | might_sleep(); |
| 376 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 377 | freezable_schedule_timeout_killable_unsafe( |
| 378 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 379 | if (fatal_signal_pending(current)) |
| 380 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 381 | return res; |
| 382 | } |
| 383 | |
| 384 | /* This is the error handling routine for processes that are allowed |
| 385 | * to sleep. |
| 386 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 387 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 388 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 389 | { |
| 390 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 391 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 392 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 393 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 394 | int ret = errorcode; |
| 395 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 396 | exception->delay = 0; |
| 397 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 398 | exception->retry = 0; |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 399 | |
| 400 | if (stateid == NULL && state != NULL) |
| 401 | stateid = &state->stateid; |
| 402 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 403 | switch(errorcode) { |
| 404 | case 0: |
| 405 | return 0; |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 406 | case -NFS4ERR_DELEG_REVOKED: |
| 407 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 408 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 409 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 272289a | 2016-09-22 13:39:15 -0400 | [diff] [blame] | 410 | if (inode != NULL && stateid != NULL) { |
| 411 | nfs_inode_find_state_and_recover(inode, |
| 412 | stateid); |
| 413 | goto wait_on_recovery; |
| 414 | } |
| 415 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 416 | if (inode) { |
| 417 | int err; |
| 418 | |
| 419 | err = nfs_async_inode_return_delegation(inode, |
| 420 | stateid); |
| 421 | if (err == 0) |
| 422 | goto wait_on_recovery; |
| 423 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 424 | exception->retry = 1; |
| 425 | break; |
| 426 | } |
| 427 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 428 | if (state == NULL) |
| 429 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 430 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 431 | if (ret < 0) |
| 432 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 433 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 434 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 435 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 436 | nfs4_schedule_lease_recovery(clp); |
| 437 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 438 | case -NFS4ERR_MOVED: |
| 439 | ret = nfs4_schedule_migration_recovery(server); |
| 440 | if (ret < 0) |
| 441 | break; |
| 442 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 443 | case -NFS4ERR_LEASE_MOVED: |
| 444 | nfs4_schedule_lease_moved_recovery(clp); |
| 445 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 446 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 447 | case -NFS4ERR_BADSESSION: |
| 448 | case -NFS4ERR_BADSLOT: |
| 449 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 450 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 451 | case -NFS4ERR_DEADSESSION: |
| 452 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 453 | case -NFS4ERR_SEQ_MISORDERED: |
| 454 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 455 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 456 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 457 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 458 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 459 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 460 | if (exception->timeout > HZ) { |
| 461 | /* We have retried a decent amount, time to |
| 462 | * fail |
| 463 | */ |
| 464 | ret = -EBUSY; |
| 465 | break; |
| 466 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 467 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 468 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 469 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 470 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 471 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 472 | exception->delay = 1; |
| 473 | return 0; |
| 474 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 475 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 476 | case -NFS4ERR_OLD_STATEID: |
| 477 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 478 | break; |
| 479 | case -NFS4ERR_BADOWNER: |
| 480 | /* The following works around a Linux server bug! */ |
| 481 | case -NFS4ERR_BADNAME: |
| 482 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 483 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 484 | exception->retry = 1; |
| 485 | printk(KERN_WARNING "NFS: v4 server %s " |
| 486 | "does not accept raw " |
| 487 | "uid/gids. " |
| 488 | "Reenabling the idmapper.\n", |
| 489 | server->nfs_client->cl_hostname); |
| 490 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 491 | } |
| 492 | /* We failed to handle the error */ |
| 493 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 494 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 495 | exception->recovering = 1; |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | /* This is the error handling routine for processes that are allowed |
| 500 | * to sleep. |
| 501 | */ |
| 502 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 503 | { |
| 504 | struct nfs_client *clp = server->nfs_client; |
| 505 | int ret; |
| 506 | |
| 507 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 508 | if (exception->delay) { |
| 509 | ret = nfs4_delay(server->client, &exception->timeout); |
| 510 | goto out_retry; |
| 511 | } |
| 512 | if (exception->recovering) { |
| 513 | ret = nfs4_wait_clnt_recover(clp); |
| 514 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 515 | return -EIO; |
| 516 | goto out_retry; |
| 517 | } |
| 518 | return ret; |
| 519 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 520 | if (ret == 0) |
| 521 | exception->retry = 1; |
| 522 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 525 | static int |
| 526 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 527 | int errorcode, struct nfs4_exception *exception) |
| 528 | { |
| 529 | struct nfs_client *clp = server->nfs_client; |
| 530 | int ret; |
| 531 | |
| 532 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 533 | if (exception->delay) { |
| 534 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 535 | goto out_retry; |
| 536 | } |
| 537 | if (exception->recovering) { |
| 538 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 539 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 540 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 541 | goto out_retry; |
| 542 | } |
| 543 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 544 | ret = -EIO; |
| 545 | return ret; |
| 546 | out_retry: |
| 547 | if (ret == 0) |
| 548 | exception->retry = 1; |
| 549 | return ret; |
| 550 | } |
| 551 | |
| 552 | static int |
| 553 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 554 | struct nfs4_state *state, long *timeout) |
| 555 | { |
| 556 | struct nfs4_exception exception = { |
| 557 | .state = state, |
| 558 | }; |
| 559 | |
| 560 | if (task->tk_status >= 0) |
| 561 | return 0; |
| 562 | if (timeout) |
| 563 | exception.timeout = *timeout; |
| 564 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 565 | task->tk_status, |
| 566 | &exception); |
| 567 | if (exception.delay && timeout) |
| 568 | *timeout = exception.timeout; |
| 569 | if (exception.retry) |
| 570 | return -EAGAIN; |
| 571 | return 0; |
| 572 | } |
| 573 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 574 | /* |
| 575 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 576 | * or 'false' otherwise. |
| 577 | */ |
| 578 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 579 | { |
| 580 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 581 | |
| 582 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 583 | flavor == RPC_AUTH_GSS_KRB5P) |
| 584 | return true; |
| 585 | |
| 586 | return false; |
| 587 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 588 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 589 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | spin_lock(&clp->cl_lock); |
| 592 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 593 | clp->cl_last_renewal = timestamp; |
| 594 | spin_unlock(&clp->cl_lock); |
| 595 | } |
| 596 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 597 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 598 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 599 | struct nfs_client *clp = server->nfs_client; |
| 600 | |
| 601 | if (!nfs4_has_session(clp)) |
| 602 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 605 | struct nfs4_call_sync_data { |
| 606 | const struct nfs_server *seq_server; |
| 607 | struct nfs4_sequence_args *seq_args; |
| 608 | struct nfs4_sequence_res *seq_res; |
| 609 | }; |
| 610 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 611 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 612 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 613 | { |
| 614 | args->sa_slot = NULL; |
| 615 | args->sa_cache_this = cache_reply; |
| 616 | args->sa_privileged = 0; |
| 617 | |
| 618 | res->sr_slot = NULL; |
| 619 | } |
| 620 | |
| 621 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 622 | { |
| 623 | args->sa_privileged = 1; |
| 624 | } |
| 625 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 626 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 627 | struct nfs4_sequence_args *args, |
| 628 | struct nfs4_sequence_res *res, |
| 629 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 630 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 631 | struct nfs4_slot *slot; |
| 632 | |
| 633 | /* slot already allocated? */ |
| 634 | if (res->sr_slot != NULL) |
| 635 | goto out_start; |
| 636 | |
| 637 | spin_lock(&tbl->slot_tbl_lock); |
| 638 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 639 | goto out_sleep; |
| 640 | |
| 641 | slot = nfs4_alloc_slot(tbl); |
| 642 | if (IS_ERR(slot)) { |
| 643 | if (slot == ERR_PTR(-ENOMEM)) |
| 644 | task->tk_timeout = HZ >> 2; |
| 645 | goto out_sleep; |
| 646 | } |
| 647 | spin_unlock(&tbl->slot_tbl_lock); |
| 648 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 649 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 650 | args->sa_slot = slot; |
| 651 | res->sr_slot = slot; |
| 652 | |
| 653 | out_start: |
| 654 | rpc_call_start(task); |
| 655 | return 0; |
| 656 | |
| 657 | out_sleep: |
| 658 | if (args->sa_privileged) |
| 659 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 660 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 661 | else |
| 662 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 663 | spin_unlock(&tbl->slot_tbl_lock); |
| 664 | return -EAGAIN; |
| 665 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 666 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 667 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 668 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 669 | { |
| 670 | struct nfs4_slot *slot = res->sr_slot; |
| 671 | struct nfs4_slot_table *tbl; |
| 672 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 673 | tbl = slot->table; |
| 674 | spin_lock(&tbl->slot_tbl_lock); |
| 675 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 676 | nfs4_free_slot(tbl, slot); |
| 677 | spin_unlock(&tbl->slot_tbl_lock); |
| 678 | |
| 679 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static int nfs40_sequence_done(struct rpc_task *task, |
| 683 | struct nfs4_sequence_res *res) |
| 684 | { |
| 685 | if (res->sr_slot != NULL) |
| 686 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 687 | return 1; |
| 688 | } |
| 689 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 690 | #if defined(CONFIG_NFS_V4_1) |
| 691 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 692 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 693 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 694 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 695 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 696 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 697 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 698 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 699 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 700 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 701 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 702 | /* Bump the slot sequence number */ |
| 703 | if (slot->seq_done) |
| 704 | slot->seq_nr++; |
| 705 | slot->seq_done = 0; |
| 706 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 707 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 708 | /* Be nice to the server: try to ensure that the last transmitted |
| 709 | * value for highest_user_slotid <= target_highest_slotid |
| 710 | */ |
| 711 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 712 | send_new_highest_used_slotid = true; |
| 713 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 714 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 715 | send_new_highest_used_slotid = false; |
| 716 | goto out_unlock; |
| 717 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 718 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 719 | |
| 720 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 721 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 722 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 723 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 724 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 725 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 726 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 727 | if (waitqueue_active(&tbl->slot_waitq)) |
| 728 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 731 | static int nfs41_sequence_process(struct rpc_task *task, |
| 732 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 733 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 734 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 735 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 736 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 737 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 738 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 739 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 740 | if (slot == NULL) |
| 741 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 742 | /* don't increment the sequence number if the task wasn't sent */ |
| 743 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 744 | goto out; |
| 745 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 746 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 747 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 748 | if (slot->interrupted) { |
| 749 | slot->interrupted = 0; |
| 750 | interrupted = true; |
| 751 | } |
| 752 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 753 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 754 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 755 | switch (res->sr_status) { |
| 756 | case 0: |
Olga Kornievskaia | a865880 | 2016-09-23 17:24:03 -0400 | [diff] [blame] | 757 | /* If previous op on slot was interrupted and we reused |
| 758 | * the seq# and got a reply from the cache, then retry |
| 759 | */ |
| 760 | if (task->tk_status == -EREMOTEIO && interrupted) { |
| 761 | ++slot->seq_nr; |
| 762 | goto retry_nowait; |
| 763 | } |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 764 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 765 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 766 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 767 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 768 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 769 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 770 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 771 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 772 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 773 | case 1: |
| 774 | /* |
| 775 | * sr_status remains 1 if an RPC level error occurred. |
| 776 | * The server may or may not have processed the sequence |
| 777 | * operation.. |
| 778 | * Mark the slot as having hosted an interrupted RPC call. |
| 779 | */ |
| 780 | slot->interrupted = 1; |
| 781 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 782 | case -NFS4ERR_DELAY: |
| 783 | /* The server detected a resend of the RPC call and |
| 784 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 785 | * of RFC5661. |
| 786 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 787 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 788 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 789 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 790 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 791 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 792 | case -NFS4ERR_BADSLOT: |
| 793 | /* |
| 794 | * The slot id we used was probably retired. Try again |
| 795 | * using a different slot id. |
| 796 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 797 | goto retry_nowait; |
| 798 | case -NFS4ERR_SEQ_MISORDERED: |
| 799 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 800 | * Was the last operation on this sequence interrupted? |
| 801 | * If so, retry after bumping the sequence number. |
| 802 | */ |
| 803 | if (interrupted) { |
| 804 | ++slot->seq_nr; |
| 805 | goto retry_nowait; |
| 806 | } |
| 807 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 808 | * Could this slot have been previously retired? |
| 809 | * If so, then the server may be expecting seq_nr = 1! |
| 810 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 811 | if (slot->seq_nr != 1) { |
| 812 | slot->seq_nr = 1; |
| 813 | goto retry_nowait; |
| 814 | } |
| 815 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 816 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 817 | ++slot->seq_nr; |
| 818 | goto retry_nowait; |
Trond Myklebust | 2cf10cd | 2016-12-04 19:26:40 -0500 | [diff] [blame] | 819 | case -NFS4ERR_DEADSESSION: |
| 820 | case -NFS4ERR_BADSESSION: |
| 821 | nfs4_schedule_session_recovery(session, res->sr_status); |
| 822 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 823 | default: |
| 824 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 825 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 826 | } |
| 827 | out: |
| 828 | /* The session may be reset by one of the error handlers. */ |
| 829 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 830 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 831 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 832 | retry_nowait: |
| 833 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 834 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 835 | task->tk_status = 0; |
| 836 | ret = 0; |
| 837 | } |
| 838 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 839 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 840 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 841 | goto out; |
| 842 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 843 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 844 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 845 | |
| 846 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 847 | { |
| 848 | if (!nfs41_sequence_process(task, res)) |
| 849 | return 0; |
| 850 | if (res->sr_slot != NULL) |
| 851 | nfs41_sequence_free_slot(res); |
| 852 | return 1; |
| 853 | |
| 854 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 855 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 856 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 857 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 858 | { |
| 859 | if (res->sr_slot == NULL) |
| 860 | return 1; |
| 861 | if (res->sr_slot->table->session != NULL) |
| 862 | return nfs41_sequence_process(task, res); |
| 863 | return nfs40_sequence_done(task, res); |
| 864 | } |
| 865 | |
| 866 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 867 | { |
| 868 | if (res->sr_slot != NULL) { |
| 869 | if (res->sr_slot->table->session != NULL) |
| 870 | nfs41_sequence_free_slot(res); |
| 871 | else |
| 872 | nfs40_sequence_free_slot(res); |
| 873 | } |
| 874 | } |
| 875 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 876 | 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] | 877 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 878 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 879 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 880 | if (!res->sr_slot->table->session) |
| 881 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 882 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 883 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 884 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 885 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 886 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 887 | struct nfs4_sequence_args *args, |
| 888 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 889 | struct rpc_task *task) |
| 890 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 891 | struct nfs4_slot *slot; |
| 892 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 893 | |
| 894 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 895 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 896 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 897 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 898 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 899 | tbl = &session->fc_slot_table; |
| 900 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 901 | task->tk_timeout = 0; |
| 902 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 903 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 904 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 905 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 906 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 907 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 908 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 909 | } |
| 910 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 911 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 912 | if (IS_ERR(slot)) { |
| 913 | /* If out of memory, try again in 1/4 second */ |
| 914 | if (slot == ERR_PTR(-ENOMEM)) |
| 915 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 916 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 917 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 918 | } |
| 919 | spin_unlock(&tbl->slot_tbl_lock); |
| 920 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 921 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 922 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 923 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 924 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 925 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 926 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 927 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 928 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 929 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 930 | /* |
| 931 | * sr_status is only set in decode_sequence, and so will remain |
| 932 | * set to 1 if an rpc level failure occurs. |
| 933 | */ |
| 934 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 935 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 936 | out_success: |
| 937 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 938 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 939 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 940 | /* Privileged tasks are queued with top priority */ |
| 941 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 942 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 943 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 944 | else |
| 945 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 946 | spin_unlock(&tbl->slot_tbl_lock); |
| 947 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 948 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 949 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 950 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 951 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 952 | struct nfs4_sequence_args *args, |
| 953 | struct nfs4_sequence_res *res, |
| 954 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 955 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 956 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 957 | int ret = 0; |
| 958 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 959 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 960 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 961 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 962 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 963 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 964 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 965 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 966 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 967 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 968 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 969 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 970 | return ret; |
| 971 | } |
| 972 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 973 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 974 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 975 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 976 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 977 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 978 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 979 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 980 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 981 | } |
| 982 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 983 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 984 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 985 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 986 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 987 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 988 | } |
| 989 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 990 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 991 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 992 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 993 | }; |
| 994 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 995 | #else /* !CONFIG_NFS_V4_1 */ |
| 996 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 997 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 998 | struct nfs4_sequence_args *args, |
| 999 | struct nfs4_sequence_res *res, |
| 1000 | struct rpc_task *task) |
| 1001 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1002 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 1003 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 1004 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1005 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1006 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1007 | { |
| 1008 | return nfs40_sequence_done(task, res); |
| 1009 | } |
| 1010 | |
| 1011 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1012 | { |
| 1013 | if (res->sr_slot != NULL) |
| 1014 | nfs40_sequence_free_slot(res); |
| 1015 | } |
| 1016 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1017 | int nfs4_sequence_done(struct rpc_task *task, |
| 1018 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1019 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1020 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1021 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1022 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1023 | |
| 1024 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1025 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1026 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1027 | { |
| 1028 | struct nfs4_call_sync_data *data = calldata; |
| 1029 | nfs4_setup_sequence(data->seq_server, |
| 1030 | data->seq_args, data->seq_res, task); |
| 1031 | } |
| 1032 | |
| 1033 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1034 | { |
| 1035 | struct nfs4_call_sync_data *data = calldata; |
| 1036 | nfs4_sequence_done(task, data->seq_res); |
| 1037 | } |
| 1038 | |
| 1039 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1040 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1041 | .rpc_call_done = nfs40_call_sync_done, |
| 1042 | }; |
| 1043 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1044 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1045 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1046 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1047 | struct nfs4_sequence_args *args, |
| 1048 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1049 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | int ret; |
| 1051 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1052 | struct nfs_client *clp = server->nfs_client; |
| 1053 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1054 | .seq_server = server, |
| 1055 | .seq_args = args, |
| 1056 | .seq_res = res, |
| 1057 | }; |
| 1058 | struct rpc_task_setup task_setup = { |
| 1059 | .rpc_client = clnt, |
| 1060 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1061 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1062 | .callback_data = &data |
| 1063 | }; |
| 1064 | |
| 1065 | task = rpc_run_task(&task_setup); |
| 1066 | if (IS_ERR(task)) |
| 1067 | ret = PTR_ERR(task); |
| 1068 | else { |
| 1069 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1070 | rpc_put_task(task); |
| 1071 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1072 | return ret; |
| 1073 | } |
| 1074 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1075 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1076 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1077 | struct rpc_message *msg, |
| 1078 | struct nfs4_sequence_args *args, |
| 1079 | struct nfs4_sequence_res *res, |
| 1080 | int cache_reply) |
| 1081 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1082 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1083 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
| 1086 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1087 | { |
| 1088 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1089 | |
| 1090 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1091 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1092 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1094 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1095 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1096 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | spin_unlock(&dir->i_lock); |
| 1098 | } |
| 1099 | |
| 1100 | struct nfs4_opendata { |
| 1101 | struct kref kref; |
| 1102 | struct nfs_openargs o_arg; |
| 1103 | struct nfs_openres o_res; |
| 1104 | struct nfs_open_confirmargs c_arg; |
| 1105 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1106 | struct nfs4_string owner_name; |
| 1107 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1108 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1110 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1112 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | struct nfs4_state_owner *owner; |
| 1114 | struct nfs4_state *state; |
| 1115 | struct iattr attrs; |
| 1116 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1117 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1118 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1119 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1120 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | int cancelled; |
| 1122 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1123 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1124 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1125 | int err, struct nfs4_exception *exception) |
| 1126 | { |
| 1127 | if (err != -EINVAL) |
| 1128 | return false; |
| 1129 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1130 | return false; |
| 1131 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1132 | exception->retry = 1; |
| 1133 | return true; |
| 1134 | } |
| 1135 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1136 | static u32 |
| 1137 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1138 | fmode_t fmode, int openflags) |
| 1139 | { |
| 1140 | u32 res = 0; |
| 1141 | |
| 1142 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1143 | case FMODE_READ: |
| 1144 | res = NFS4_SHARE_ACCESS_READ; |
| 1145 | break; |
| 1146 | case FMODE_WRITE: |
| 1147 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1148 | break; |
| 1149 | case FMODE_READ|FMODE_WRITE: |
| 1150 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1151 | } |
| 1152 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1153 | goto out; |
| 1154 | /* Want no delegation if we're using O_DIRECT */ |
| 1155 | if (openflags & O_DIRECT) |
| 1156 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1157 | out: |
| 1158 | return res; |
| 1159 | } |
| 1160 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1161 | static enum open_claim_type4 |
| 1162 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1163 | enum open_claim_type4 claim) |
| 1164 | { |
| 1165 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1166 | return claim; |
| 1167 | switch (claim) { |
| 1168 | default: |
| 1169 | return claim; |
| 1170 | case NFS4_OPEN_CLAIM_FH: |
| 1171 | return NFS4_OPEN_CLAIM_NULL; |
| 1172 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1173 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1174 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1175 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1176 | } |
| 1177 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1180 | { |
| 1181 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1182 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | p->o_res.seqid = p->o_arg.seqid; |
| 1184 | p->c_res.seqid = p->c_arg.seqid; |
| 1185 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1186 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1188 | 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] | 1189 | } |
| 1190 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1191 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1192 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1193 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1194 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1195 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1196 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1197 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1198 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1199 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1201 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1202 | struct nfs4_opendata *p; |
| 1203 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1204 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1205 | if (p == NULL) |
| 1206 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1209 | if (IS_ERR(p->f_label)) |
| 1210 | goto err_free_p; |
| 1211 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1212 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1213 | if (IS_ERR(p->a_label)) |
| 1214 | goto err_free_f; |
| 1215 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1216 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1217 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1218 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1219 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1220 | nfs_sb_active(dentry->d_sb); |
| 1221 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1222 | p->dir = parent; |
| 1223 | p->owner = sp; |
| 1224 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1225 | p->o_arg.open_flags = flags; |
| 1226 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 1227 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1228 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1229 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1230 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1231 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1232 | * will return permission denied for all bits until close */ |
| 1233 | if (!(flags & O_EXCL)) { |
| 1234 | /* ask server to check for all possible rights as results |
| 1235 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1236 | switch (p->o_arg.claim) { |
| 1237 | default: |
| 1238 | break; |
| 1239 | case NFS4_OPEN_CLAIM_NULL: |
| 1240 | case NFS4_OPEN_CLAIM_FH: |
| 1241 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1242 | NFS4_ACCESS_MODIFY | |
| 1243 | NFS4_ACCESS_EXTEND | |
| 1244 | NFS4_ACCESS_EXECUTE; |
| 1245 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1246 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1247 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1248 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1249 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1250 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1251 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1252 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1253 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1254 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1255 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1256 | case NFS4_OPEN_CLAIM_NULL: |
| 1257 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1258 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1259 | p->o_arg.fh = NFS_FH(dir); |
| 1260 | break; |
| 1261 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1262 | case NFS4_OPEN_CLAIM_FH: |
| 1263 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1264 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1265 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1266 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1267 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1268 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1269 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1270 | p->o_arg.u.attrs = &p->attrs; |
| 1271 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1272 | |
| 1273 | verf[0] = jiffies; |
| 1274 | verf[1] = current->pid; |
| 1275 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1276 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1277 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1278 | p->c_arg.fh = &p->o_res.fh; |
| 1279 | p->c_arg.stateid = &p->o_res.stateid; |
| 1280 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1281 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1282 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1283 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1284 | |
| 1285 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1286 | nfs4_label_free(p->a_label); |
| 1287 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1288 | nfs4_label_free(p->f_label); |
| 1289 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1290 | kfree(p); |
| 1291 | err: |
| 1292 | dput(parent); |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1296 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1297 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1298 | struct nfs4_opendata *p = container_of(kref, |
| 1299 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1300 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1301 | |
| 1302 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1303 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1304 | if (p->state != NULL) |
| 1305 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1306 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1307 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1308 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1309 | nfs4_label_free(p->f_label); |
| 1310 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1311 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1312 | dput(p->dentry); |
| 1313 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1314 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1315 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1316 | kfree(p); |
| 1317 | } |
| 1318 | |
| 1319 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1320 | { |
| 1321 | if (p != NULL) |
| 1322 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1325 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1326 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1327 | int ret; |
| 1328 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1329 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1330 | return ret; |
| 1331 | } |
| 1332 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1333 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1334 | fmode_t fmode) |
| 1335 | { |
| 1336 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1337 | case FMODE_READ|FMODE_WRITE: |
| 1338 | return state->n_rdwr != 0; |
| 1339 | case FMODE_WRITE: |
| 1340 | return state->n_wronly != 0; |
| 1341 | case FMODE_READ: |
| 1342 | return state->n_rdonly != 0; |
| 1343 | } |
| 1344 | WARN_ON_ONCE(1); |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | 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] | 1349 | { |
| 1350 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1351 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1352 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1353 | goto out; |
| 1354 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1355 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1356 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1357 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1358 | break; |
| 1359 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1360 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1361 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1362 | break; |
| 1363 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1364 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1365 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1366 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1367 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1368 | return ret; |
| 1369 | } |
| 1370 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1371 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1372 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1373 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1374 | if (delegation == NULL) |
| 1375 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1376 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1377 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1378 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1379 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1380 | switch (claim) { |
| 1381 | case NFS4_OPEN_CLAIM_NULL: |
| 1382 | case NFS4_OPEN_CLAIM_FH: |
| 1383 | break; |
| 1384 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1385 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1386 | break; |
| 1387 | default: |
| 1388 | return 0; |
| 1389 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1390 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1391 | return 1; |
| 1392 | } |
| 1393 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1394 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1395 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1396 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1397 | case FMODE_WRITE: |
| 1398 | state->n_wronly++; |
| 1399 | break; |
| 1400 | case FMODE_READ: |
| 1401 | state->n_rdonly++; |
| 1402 | break; |
| 1403 | case FMODE_READ|FMODE_WRITE: |
| 1404 | state->n_rdwr++; |
| 1405 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1406 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1409 | #ifdef CONFIG_NFS_V4_1 |
| 1410 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1411 | { |
| 1412 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1413 | return true; |
| 1414 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1415 | return true; |
| 1416 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1417 | return true; |
| 1418 | return false; |
| 1419 | } |
| 1420 | #endif /* CONFIG_NFS_V4_1 */ |
| 1421 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1422 | 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] | 1423 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1424 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1425 | bool need_recover = false; |
| 1426 | |
| 1427 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1428 | need_recover = true; |
| 1429 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1430 | need_recover = true; |
| 1431 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1432 | need_recover = true; |
| 1433 | if (need_recover) |
| 1434 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1435 | } |
| 1436 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1437 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1438 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1439 | { |
| 1440 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1441 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1442 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1443 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1444 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1445 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1446 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1447 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1448 | return true; |
| 1449 | return false; |
| 1450 | } |
| 1451 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1452 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1453 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1454 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1455 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1456 | if (state->n_wronly) |
| 1457 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1458 | if (state->n_rdonly) |
| 1459 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1460 | if (state->n_rdwr) |
| 1461 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1462 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1463 | } |
| 1464 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1465 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1466 | nfs4_stateid *stateid, fmode_t fmode) |
| 1467 | { |
| 1468 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1469 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1470 | case FMODE_WRITE: |
| 1471 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1472 | break; |
| 1473 | case FMODE_READ: |
| 1474 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1475 | break; |
| 1476 | case 0: |
| 1477 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1478 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1479 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1480 | } |
| 1481 | if (stateid == NULL) |
| 1482 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1483 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1484 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1485 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1486 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1487 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1488 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1489 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1490 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1491 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1492 | } |
| 1493 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1494 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1495 | nfs4_stateid *arg_stateid, |
| 1496 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1497 | { |
| 1498 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1499 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1500 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1501 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1502 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1503 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1504 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1507 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1508 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1509 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1510 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1511 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1512 | case FMODE_READ: |
| 1513 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1514 | break; |
| 1515 | case FMODE_WRITE: |
| 1516 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1517 | break; |
| 1518 | case FMODE_READ|FMODE_WRITE: |
| 1519 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1520 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1521 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1522 | return; |
| 1523 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1524 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1525 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1526 | } |
| 1527 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1528 | static void __update_open_stateid(struct nfs4_state *state, |
| 1529 | const nfs4_stateid *open_stateid, |
| 1530 | const nfs4_stateid *deleg_stateid, |
| 1531 | fmode_t fmode, |
| 1532 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1534 | /* |
| 1535 | * Protect the call to nfs4_state_set_mode_locked and |
| 1536 | * serialise the stateid update |
| 1537 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1538 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1539 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1540 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1541 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1542 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1543 | } |
| 1544 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1545 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1546 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1547 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1548 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1551 | static int update_open_stateid(struct nfs4_state *state, |
| 1552 | const nfs4_stateid *open_stateid, |
| 1553 | const nfs4_stateid *delegation, |
| 1554 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1555 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1556 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1557 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1558 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1559 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1560 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1561 | int ret = 0; |
| 1562 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1563 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1564 | |
| 1565 | rcu_read_lock(); |
| 1566 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1567 | if (deleg_cur == NULL) |
| 1568 | goto no_delegation; |
| 1569 | |
| 1570 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1571 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1572 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1573 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | goto no_delegation_unlock; |
| 1575 | |
| 1576 | if (delegation == NULL) |
| 1577 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1578 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1579 | goto no_delegation_unlock; |
| 1580 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1581 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1582 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1583 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1584 | ret = 1; |
| 1585 | no_delegation_unlock: |
| 1586 | spin_unlock(&deleg_cur->lock); |
| 1587 | no_delegation: |
| 1588 | rcu_read_unlock(); |
| 1589 | |
| 1590 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1591 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1592 | ret = 1; |
| 1593 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1594 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1595 | nfs4_schedule_state_manager(clp); |
| 1596 | if (freeme.type != 0) |
| 1597 | nfs4_test_and_free_stateid(server, &freeme, |
| 1598 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1599 | |
| 1600 | return ret; |
| 1601 | } |
| 1602 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1603 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1604 | const nfs4_stateid *stateid) |
| 1605 | { |
| 1606 | struct nfs4_state *state = lsp->ls_state; |
| 1607 | bool ret = false; |
| 1608 | |
| 1609 | spin_lock(&state->state_lock); |
| 1610 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1611 | goto out_noupdate; |
| 1612 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1613 | goto out_noupdate; |
| 1614 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1615 | ret = true; |
| 1616 | out_noupdate: |
| 1617 | spin_unlock(&state->state_lock); |
| 1618 | return ret; |
| 1619 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1620 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1621 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1622 | { |
| 1623 | struct nfs_delegation *delegation; |
| 1624 | |
| 1625 | rcu_read_lock(); |
| 1626 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1627 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1628 | rcu_read_unlock(); |
| 1629 | return; |
| 1630 | } |
| 1631 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1632 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1635 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1636 | { |
| 1637 | struct nfs4_state *state = opendata->state; |
| 1638 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1639 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1640 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1641 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1642 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1643 | nfs4_stateid stateid; |
| 1644 | int ret = -EAGAIN; |
| 1645 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1646 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1647 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1648 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1649 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1650 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1651 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1652 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1653 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1654 | rcu_read_lock(); |
| 1655 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1656 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1657 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1658 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1659 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1660 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1661 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1662 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1663 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1664 | if (!opendata->is_recover) { |
| 1665 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1666 | if (ret != 0) |
| 1667 | goto out; |
| 1668 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1670 | |
| 1671 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1672 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1673 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1674 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1675 | out: |
| 1676 | return ERR_PTR(ret); |
| 1677 | out_return_state: |
| 1678 | atomic_inc(&state->count); |
| 1679 | return state; |
| 1680 | } |
| 1681 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1682 | static void |
| 1683 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1684 | { |
| 1685 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1686 | struct nfs_delegation *delegation; |
| 1687 | int delegation_flags = 0; |
| 1688 | |
| 1689 | rcu_read_lock(); |
| 1690 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1691 | if (delegation) |
| 1692 | delegation_flags = delegation->flags; |
| 1693 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1694 | switch (data->o_arg.claim) { |
| 1695 | default: |
| 1696 | break; |
| 1697 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1698 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1699 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1700 | "returning a delegation for " |
| 1701 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1702 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1703 | return; |
| 1704 | } |
| 1705 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1706 | nfs_inode_set_delegation(state->inode, |
| 1707 | data->owner->so_cred, |
| 1708 | &data->o_res); |
| 1709 | else |
| 1710 | nfs_inode_reclaim_delegation(state->inode, |
| 1711 | data->owner->so_cred, |
| 1712 | &data->o_res); |
| 1713 | } |
| 1714 | |
| 1715 | /* |
| 1716 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1717 | * and update the nfs4_state. |
| 1718 | */ |
| 1719 | static struct nfs4_state * |
| 1720 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1721 | { |
| 1722 | struct inode *inode = data->state->inode; |
| 1723 | struct nfs4_state *state = data->state; |
| 1724 | int ret; |
| 1725 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1726 | if (!data->rpc_done) { |
| 1727 | if (data->rpc_status) { |
| 1728 | ret = data->rpc_status; |
| 1729 | goto err; |
| 1730 | } |
| 1731 | /* cached opens have already been processed */ |
| 1732 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1733 | } |
| 1734 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1735 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1736 | if (ret) |
| 1737 | goto err; |
| 1738 | |
| 1739 | if (data->o_res.delegation_type != 0) |
| 1740 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1741 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1742 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1743 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1744 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1745 | |
| 1746 | return state; |
| 1747 | err: |
| 1748 | return ERR_PTR(ret); |
| 1749 | |
| 1750 | } |
| 1751 | |
| 1752 | static struct nfs4_state * |
| 1753 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1754 | { |
| 1755 | struct inode *inode; |
| 1756 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1757 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1758 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1759 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1760 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1761 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1762 | goto out; |
| 1763 | } |
| 1764 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1765 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1766 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1767 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1768 | 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] | 1769 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1770 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1771 | goto err; |
| 1772 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1773 | state = nfs4_get_open_state(inode, data->owner); |
| 1774 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1775 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1776 | if (data->o_res.delegation_type != 0) |
| 1777 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1778 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1779 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1780 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1781 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1782 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1783 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1784 | err_put_inode: |
| 1785 | iput(inode); |
| 1786 | err: |
| 1787 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1790 | static struct nfs4_state * |
| 1791 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1792 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1793 | struct nfs4_state *ret; |
| 1794 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1795 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1796 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1797 | else |
| 1798 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1799 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1800 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1801 | } |
| 1802 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1803 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1804 | { |
| 1805 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1806 | struct nfs_open_context *ctx; |
| 1807 | |
| 1808 | spin_lock(&state->inode->i_lock); |
| 1809 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1810 | if (ctx->state != state) |
| 1811 | continue; |
| 1812 | get_nfs_open_context(ctx); |
| 1813 | spin_unlock(&state->inode->i_lock); |
| 1814 | return ctx; |
| 1815 | } |
| 1816 | spin_unlock(&state->inode->i_lock); |
| 1817 | return ERR_PTR(-ENOENT); |
| 1818 | } |
| 1819 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1820 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1821 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1822 | { |
| 1823 | struct nfs4_opendata *opendata; |
| 1824 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1825 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1826 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1827 | if (opendata == NULL) |
| 1828 | return ERR_PTR(-ENOMEM); |
| 1829 | opendata->state = state; |
| 1830 | atomic_inc(&state->count); |
| 1831 | return opendata; |
| 1832 | } |
| 1833 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1834 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1835 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1836 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1837 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1838 | int ret; |
| 1839 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1840 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1841 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1842 | opendata->o_arg.open_flags = 0; |
| 1843 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1844 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1845 | NFS_SB(opendata->dentry->d_sb), |
| 1846 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1847 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1848 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1849 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1850 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1851 | if (ret != 0) |
| 1852 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1853 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1854 | if (IS_ERR(newstate)) |
| 1855 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1856 | if (newstate != opendata->state) |
| 1857 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1858 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1859 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1863 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1864 | int ret; |
| 1865 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1866 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1867 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1868 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1869 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1870 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1871 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1872 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1873 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1874 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1875 | if (ret != 0) |
| 1876 | return ret; |
| 1877 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1878 | if (ret != 0) |
| 1879 | return ret; |
| 1880 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1881 | if (ret != 0) |
| 1882 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1883 | /* |
| 1884 | * We may have performed cached opens for all three recoveries. |
| 1885 | * Check if we need to update the current stateid. |
| 1886 | */ |
| 1887 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1888 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1889 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1890 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1891 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1892 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1893 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1894 | return 0; |
| 1895 | } |
| 1896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | /* |
| 1898 | * OPEN_RECLAIM: |
| 1899 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1901 | 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] | 1902 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1903 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1904 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1905 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | int status; |
| 1907 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1908 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1909 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1910 | if (IS_ERR(opendata)) |
| 1911 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1912 | rcu_read_lock(); |
| 1913 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1914 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1915 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1916 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1917 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1918 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1919 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | return status; |
| 1921 | } |
| 1922 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1923 | 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] | 1924 | { |
| 1925 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1926 | struct nfs4_exception exception = { }; |
| 1927 | int err; |
| 1928 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1929 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1930 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1931 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1932 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1933 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | } while (exception.retry); |
| 1937 | return err; |
| 1938 | } |
| 1939 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1940 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1941 | { |
| 1942 | struct nfs_open_context *ctx; |
| 1943 | int ret; |
| 1944 | |
| 1945 | ctx = nfs4_state_find_open_context(state); |
| 1946 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1947 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1948 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1949 | put_nfs_open_context(ctx); |
| 1950 | return ret; |
| 1951 | } |
| 1952 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1953 | 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] | 1954 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1955 | switch (err) { |
| 1956 | default: |
| 1957 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1958 | "%d.\n", __func__, err); |
| 1959 | case 0: |
| 1960 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1961 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1962 | case -ESTALE: |
| 1963 | break; |
| 1964 | case -NFS4ERR_BADSESSION: |
| 1965 | case -NFS4ERR_BADSLOT: |
| 1966 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1967 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1968 | case -NFS4ERR_DEADSESSION: |
| 1969 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1970 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1971 | return -EAGAIN; |
| 1972 | case -NFS4ERR_STALE_CLIENTID: |
| 1973 | case -NFS4ERR_STALE_STATEID: |
| 1974 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1975 | /* Don't recall a delegation if it was lost */ |
| 1976 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1977 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1978 | case -NFS4ERR_MOVED: |
| 1979 | nfs4_schedule_migration_recovery(server); |
| 1980 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1981 | case -NFS4ERR_LEASE_MOVED: |
| 1982 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1983 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1984 | case -NFS4ERR_DELEG_REVOKED: |
| 1985 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1986 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1987 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1988 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1989 | nfs_inode_find_state_and_recover(state->inode, |
| 1990 | stateid); |
| 1991 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1992 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1993 | case -NFS4ERR_DELAY: |
| 1994 | case -NFS4ERR_GRACE: |
| 1995 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1996 | ssleep(1); |
| 1997 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1998 | case -ENOMEM: |
| 1999 | case -NFS4ERR_DENIED: |
| 2000 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 2001 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | return err; |
| 2004 | } |
| 2005 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2006 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2007 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2008 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2009 | { |
| 2010 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2011 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2012 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2013 | |
| 2014 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2015 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2016 | if (IS_ERR(opendata)) |
| 2017 | return PTR_ERR(opendata); |
| 2018 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2019 | write_seqlock(&state->seqlock); |
| 2020 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2021 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2022 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2023 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2024 | case FMODE_READ|FMODE_WRITE: |
| 2025 | case FMODE_WRITE: |
| 2026 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2027 | if (err) |
| 2028 | break; |
| 2029 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2030 | if (err) |
| 2031 | break; |
| 2032 | case FMODE_READ: |
| 2033 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2034 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2035 | nfs4_opendata_put(opendata); |
| 2036 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2037 | } |
| 2038 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2039 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2040 | { |
| 2041 | struct nfs4_opendata *data = calldata; |
| 2042 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2043 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2044 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2045 | } |
| 2046 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2047 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2048 | { |
| 2049 | struct nfs4_opendata *data = calldata; |
| 2050 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2051 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2052 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2053 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2054 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2055 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2056 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2057 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2058 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2059 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | static void nfs4_open_confirm_release(void *calldata) |
| 2063 | { |
| 2064 | struct nfs4_opendata *data = calldata; |
| 2065 | struct nfs4_state *state = NULL; |
| 2066 | |
| 2067 | /* If this request hasn't been cancelled, do nothing */ |
| 2068 | if (data->cancelled == 0) |
| 2069 | goto out_free; |
| 2070 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2071 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2072 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2073 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2074 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2075 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2076 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2077 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2081 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2082 | .rpc_call_done = nfs4_open_confirm_done, |
| 2083 | .rpc_release = nfs4_open_confirm_release, |
| 2084 | }; |
| 2085 | |
| 2086 | /* |
| 2087 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2088 | */ |
| 2089 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2090 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2091 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2092 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2093 | struct rpc_message msg = { |
| 2094 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2095 | .rpc_argp = &data->c_arg, |
| 2096 | .rpc_resp = &data->c_res, |
| 2097 | .rpc_cred = data->owner->so_cred, |
| 2098 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2099 | struct rpc_task_setup task_setup_data = { |
| 2100 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2101 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2102 | .callback_ops = &nfs4_open_confirm_ops, |
| 2103 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2104 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2105 | .flags = RPC_TASK_ASYNC, |
| 2106 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | int status; |
| 2108 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2109 | 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] | 2110 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2111 | data->rpc_done = 0; |
| 2112 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2113 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2114 | if (data->is_recover) |
| 2115 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2116 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2117 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2118 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2119 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2120 | if (status != 0) { |
| 2121 | data->cancelled = 1; |
| 2122 | smp_wmb(); |
| 2123 | } else |
| 2124 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2125 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | return status; |
| 2127 | } |
| 2128 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2129 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2131 | struct nfs4_opendata *data = calldata; |
| 2132 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2133 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2134 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2135 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2136 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2137 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2138 | /* |
| 2139 | * Check if we still need to send an OPEN call, or if we can use |
| 2140 | * a delegation instead. |
| 2141 | */ |
| 2142 | if (data->state != NULL) { |
| 2143 | struct nfs_delegation *delegation; |
| 2144 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2145 | 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] | 2146 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2147 | rcu_read_lock(); |
| 2148 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2149 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2150 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2151 | rcu_read_unlock(); |
| 2152 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2153 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2154 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2155 | switch (claim) { |
| 2156 | default: |
| 2157 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2158 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2159 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2160 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2161 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2162 | case NFS4_OPEN_CLAIM_FH: |
| 2163 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2164 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2165 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2166 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2167 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2168 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2169 | &data->o_res.seq_res, |
| 2170 | task) != 0) |
| 2171 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2172 | |
| 2173 | /* Set the create mode (note dependency on the session type) */ |
| 2174 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2175 | if (data->o_arg.open_flags & O_EXCL) { |
| 2176 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2177 | if (nfs4_has_persistent_session(clp)) |
| 2178 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2179 | else if (clp->cl_mvops->minor_version > 0) |
| 2180 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2181 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2182 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2183 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2184 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2185 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2186 | out_no_action: |
| 2187 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2188 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2189 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2192 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2193 | { |
| 2194 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2196 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2197 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2198 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2199 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2200 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2201 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2202 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2203 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2204 | case S_IFREG: |
| 2205 | break; |
| 2206 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2207 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2208 | break; |
| 2209 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2210 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2211 | break; |
| 2212 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2213 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2214 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2215 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2216 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2217 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2218 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2219 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2220 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2221 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2222 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2223 | static void nfs4_open_release(void *calldata) |
| 2224 | { |
| 2225 | struct nfs4_opendata *data = calldata; |
| 2226 | struct nfs4_state *state = NULL; |
| 2227 | |
| 2228 | /* If this request hasn't been cancelled, do nothing */ |
| 2229 | if (data->cancelled == 0) |
| 2230 | goto out_free; |
| 2231 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2232 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2233 | goto out_free; |
| 2234 | /* In case we need an open_confirm, no cleanup! */ |
| 2235 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2236 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2237 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2238 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2239 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2240 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2241 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2245 | .rpc_call_prepare = nfs4_open_prepare, |
| 2246 | .rpc_call_done = nfs4_open_done, |
| 2247 | .rpc_release = nfs4_open_release, |
| 2248 | }; |
| 2249 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2250 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2251 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2252 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2253 | struct nfs_server *server = NFS_SERVER(dir); |
| 2254 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2255 | struct nfs_openres *o_res = &data->o_res; |
| 2256 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2257 | struct rpc_message msg = { |
| 2258 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2259 | .rpc_argp = o_arg, |
| 2260 | .rpc_resp = o_res, |
| 2261 | .rpc_cred = data->owner->so_cred, |
| 2262 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2263 | struct rpc_task_setup task_setup_data = { |
| 2264 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2265 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2266 | .callback_ops = &nfs4_open_ops, |
| 2267 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2268 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2269 | .flags = RPC_TASK_ASYNC, |
| 2270 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2271 | int status; |
| 2272 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2273 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2274 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2275 | data->rpc_done = 0; |
| 2276 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2277 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2278 | data->is_recover = 0; |
| 2279 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2280 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2281 | data->is_recover = 1; |
| 2282 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2283 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2284 | if (IS_ERR(task)) |
| 2285 | return PTR_ERR(task); |
| 2286 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2287 | if (status != 0) { |
| 2288 | data->cancelled = 1; |
| 2289 | smp_wmb(); |
| 2290 | } else |
| 2291 | status = data->rpc_status; |
| 2292 | rpc_put_task(task); |
| 2293 | |
| 2294 | return status; |
| 2295 | } |
| 2296 | |
| 2297 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2298 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2299 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2300 | struct nfs_openres *o_res = &data->o_res; |
| 2301 | int status; |
| 2302 | |
| 2303 | status = nfs4_run_open_task(data, 1); |
| 2304 | if (status != 0 || !data->rpc_done) |
| 2305 | return status; |
| 2306 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2307 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2308 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2309 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2310 | status = _nfs4_proc_open_confirm(data); |
| 2311 | if (status != 0) |
| 2312 | return status; |
| 2313 | } |
| 2314 | |
| 2315 | return status; |
| 2316 | } |
| 2317 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2318 | /* |
| 2319 | * Additional permission checks in order to distinguish between an |
| 2320 | * open for read, and an open for execute. This works around the |
| 2321 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2322 | * the same. |
| 2323 | * Note that in the non-execute case, we want to turn off permission |
| 2324 | * checking if we just created a new file (POSIX open() semantics). |
| 2325 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2326 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2327 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2328 | struct nfs4_state *state, fmode_t fmode, |
| 2329 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2330 | { |
| 2331 | struct nfs_access_entry cache; |
| 2332 | u32 mask; |
| 2333 | |
| 2334 | /* access call failed or for some reason the server doesn't |
| 2335 | * support any access modes -- defer access call until later */ |
| 2336 | if (opendata->o_res.access_supported == 0) |
| 2337 | return 0; |
| 2338 | |
| 2339 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2340 | /* |
| 2341 | * Use openflags to check for exec, because fmode won't |
| 2342 | * always have FMODE_EXEC set when file open for exec. |
| 2343 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2344 | if (openflags & __FMODE_EXEC) { |
| 2345 | /* ONLY check for exec rights */ |
| 2346 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2347 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2348 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2349 | |
| 2350 | cache.cred = cred; |
| 2351 | cache.jiffies = jiffies; |
| 2352 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2353 | nfs_access_add_cache(state->inode, &cache); |
| 2354 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2355 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2356 | return 0; |
| 2357 | |
| 2358 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2359 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2360 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2361 | } |
| 2362 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2363 | /* |
| 2364 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2365 | */ |
| 2366 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2367 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2368 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2369 | struct nfs_server *server = NFS_SERVER(dir); |
| 2370 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2371 | struct nfs_openres *o_res = &data->o_res; |
| 2372 | int status; |
| 2373 | |
| 2374 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2375 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2376 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2377 | if (status != 0) { |
| 2378 | if (status == -NFS4ERR_BADNAME && |
| 2379 | !(o_arg->open_flags & O_CREAT)) |
| 2380 | return -ENOENT; |
| 2381 | return status; |
| 2382 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2383 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2384 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2385 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2386 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2387 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2388 | if (o_arg->open_flags & O_EXCL) |
| 2389 | data->file_created = 1; |
| 2390 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2391 | data->file_created = 1; |
| 2392 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2393 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2394 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2396 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2398 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2401 | 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] | 2402 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2405 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2406 | { |
| 2407 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2408 | } |
| 2409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | /* |
| 2411 | * OPEN_EXPIRED: |
| 2412 | * reclaim state on the server after a network partition. |
| 2413 | * Assumes caller holds the appropriate lock |
| 2414 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2415 | 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] | 2416 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2417 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2418 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2420 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2421 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2422 | if (IS_ERR(opendata)) |
| 2423 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2424 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2425 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2426 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2427 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2428 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2431 | 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] | 2432 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2433 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2434 | struct nfs4_exception exception = { }; |
| 2435 | int err; |
| 2436 | |
| 2437 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2438 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2439 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2440 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2441 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2442 | switch (err) { |
| 2443 | default: |
| 2444 | goto out; |
| 2445 | case -NFS4ERR_GRACE: |
| 2446 | case -NFS4ERR_DELAY: |
| 2447 | nfs4_handle_exception(server, err, &exception); |
| 2448 | err = 0; |
| 2449 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2450 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2451 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2452 | return err; |
| 2453 | } |
| 2454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2456 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2458 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2460 | ctx = nfs4_state_find_open_context(state); |
| 2461 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2462 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2463 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2464 | put_nfs_open_context(ctx); |
| 2465 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2468 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2469 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2470 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2471 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2472 | write_seqlock(&state->seqlock); |
| 2473 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2474 | write_sequnlock(&state->seqlock); |
| 2475 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2476 | } |
| 2477 | |
| 2478 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2479 | { |
| 2480 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2481 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2485 | { |
| 2486 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2487 | nfs40_clear_delegation_stateid(state); |
| 2488 | return nfs4_open_expired(sp, state); |
| 2489 | } |
| 2490 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2491 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2492 | nfs4_stateid *stateid, |
| 2493 | struct rpc_cred *cred) |
| 2494 | { |
| 2495 | return -NFS4ERR_BAD_STATEID; |
| 2496 | } |
| 2497 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2498 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2499 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2500 | nfs4_stateid *stateid, |
| 2501 | struct rpc_cred *cred) |
| 2502 | { |
| 2503 | int status; |
| 2504 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2505 | switch (stateid->type) { |
| 2506 | default: |
| 2507 | break; |
| 2508 | case NFS4_INVALID_STATEID_TYPE: |
| 2509 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2510 | return -NFS4ERR_BAD_STATEID; |
| 2511 | case NFS4_REVOKED_STATEID_TYPE: |
| 2512 | goto out_free; |
| 2513 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2514 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2515 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2516 | switch (status) { |
| 2517 | case -NFS4ERR_EXPIRED: |
| 2518 | case -NFS4ERR_ADMIN_REVOKED: |
| 2519 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2520 | break; |
| 2521 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2522 | return status; |
| 2523 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2524 | out_free: |
| 2525 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2526 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2527 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2528 | } |
| 2529 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2530 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2531 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2532 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2533 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2534 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2535 | struct rpc_cred *cred; |
| 2536 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2537 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2538 | /* Get the delegation credential for use by test/free_stateid */ |
| 2539 | rcu_read_lock(); |
| 2540 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2541 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2542 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2543 | return; |
| 2544 | } |
| 2545 | |
| 2546 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2547 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2548 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2549 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2550 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2551 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2552 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2553 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2554 | rcu_read_unlock(); |
| 2555 | return; |
| 2556 | } |
| 2557 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2558 | cred = get_rpccred(delegation->cred); |
| 2559 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2560 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2561 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2562 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2563 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2564 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2565 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2569 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2570 | * |
| 2571 | * @state: NFSv4 state for an inode |
| 2572 | * |
| 2573 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2574 | * Otherwise a negative NFS4ERR value is returned. |
| 2575 | */ |
| 2576 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2577 | { |
| 2578 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2579 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2580 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2581 | |
| 2582 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2583 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2584 | |
| 2585 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2586 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2587 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2588 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2589 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2590 | atomic_inc(&lsp->ls_count); |
| 2591 | spin_unlock(&state->state_lock); |
| 2592 | |
| 2593 | nfs4_put_lock_state(prev); |
| 2594 | prev = lsp; |
| 2595 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2596 | status = nfs41_test_and_free_expired_stateid(server, |
| 2597 | &lsp->ls_stateid, |
| 2598 | cred); |
| 2599 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2600 | if (status == -NFS4ERR_EXPIRED || |
| 2601 | status == -NFS4ERR_BAD_STATEID) { |
| 2602 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2603 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2604 | if (!recover_lost_locks) |
| 2605 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2606 | } else if (status != NFS_OK) { |
| 2607 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2608 | nfs4_put_lock_state(prev); |
| 2609 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2610 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2611 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2612 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2613 | } |
| 2614 | spin_unlock(&state->state_lock); |
| 2615 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2616 | out: |
| 2617 | return ret; |
| 2618 | } |
| 2619 | |
| 2620 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2621 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2622 | * |
| 2623 | * @state: NFSv4 state for an inode |
| 2624 | * |
| 2625 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2626 | * Otherwise a negative NFS4ERR value is returned. |
| 2627 | */ |
| 2628 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2629 | { |
| 2630 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2631 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2632 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2633 | int status; |
| 2634 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2635 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2636 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2637 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2638 | return NFS_OK; |
| 2639 | return -NFS4ERR_OPENMODE; |
| 2640 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2641 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2642 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2643 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2644 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2645 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2646 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2647 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2648 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2649 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2650 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2651 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2652 | if (status != NFS_OK) |
| 2653 | return status; |
| 2654 | if (nfs_open_stateid_recover_openmode(state)) |
| 2655 | return -NFS4ERR_OPENMODE; |
| 2656 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2660 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2661 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2662 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2663 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2664 | status = nfs41_check_expired_locks(state); |
| 2665 | if (status != NFS_OK) |
| 2666 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2667 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2668 | if (status != NFS_OK) |
| 2669 | status = nfs4_open_expired(sp, state); |
| 2670 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2671 | } |
| 2672 | #endif |
| 2673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2675 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2676 | * fields corresponding to attributes that were used to store the verifier. |
| 2677 | * Make sure we clobber those fields in the later setattr call |
| 2678 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2679 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2680 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2681 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2682 | const u32 *attrset = opendata->o_res.attrset; |
| 2683 | |
| 2684 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2685 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2686 | sattr->ia_valid |= ATTR_ATIME; |
| 2687 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2688 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2689 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2690 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2691 | |
| 2692 | /* Except MODE, it seems harmless of setting twice. */ |
| 2693 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2694 | sattr->ia_valid &= ~ATTR_MODE; |
| 2695 | |
| 2696 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2697 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2698 | } |
| 2699 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2700 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2701 | fmode_t fmode, |
| 2702 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2703 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2704 | { |
| 2705 | struct nfs4_state_owner *sp = opendata->owner; |
| 2706 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2707 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2708 | struct nfs4_state *state; |
| 2709 | unsigned int seq; |
| 2710 | int ret; |
| 2711 | |
| 2712 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2713 | |
| 2714 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2715 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2716 | goto out; |
| 2717 | |
| 2718 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2719 | ret = PTR_ERR(state); |
| 2720 | if (IS_ERR(state)) |
| 2721 | goto out; |
| 2722 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2723 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2724 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2725 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2726 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2727 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2728 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2729 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2730 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2731 | alias = d_exact_alias(dentry, state->inode); |
| 2732 | if (!alias) |
| 2733 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2734 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2735 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2736 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2737 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2738 | } |
| 2739 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2740 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2741 | } |
| 2742 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2743 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2744 | if (ret != 0) |
| 2745 | goto out; |
| 2746 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2747 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2748 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2749 | nfs_inode_attach_open_context(ctx); |
| 2750 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2751 | nfs4_schedule_stateid_recovery(server, state); |
| 2752 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2753 | out: |
| 2754 | return ret; |
| 2755 | } |
| 2756 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2757 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2758 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2760 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2761 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2762 | int flags, |
| 2763 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2764 | struct nfs4_label *label, |
| 2765 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | { |
| 2767 | struct nfs4_state_owner *sp; |
| 2768 | struct nfs4_state *state = NULL; |
| 2769 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2770 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2771 | struct dentry *dentry = ctx->dentry; |
| 2772 | struct rpc_cred *cred = ctx->cred; |
| 2773 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2774 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2775 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2776 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2777 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | |
| 2779 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2781 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2782 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2784 | goto out_err; |
| 2785 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2786 | status = nfs4_recover_expired_lease(server); |
| 2787 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2788 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2789 | if (d_really_is_positive(dentry)) |
| 2790 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2791 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2792 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2793 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2794 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2795 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2796 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2797 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2799 | if (label) { |
| 2800 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2801 | if (IS_ERR(olabel)) { |
| 2802 | status = PTR_ERR(olabel); |
| 2803 | goto err_opendata_put; |
| 2804 | } |
| 2805 | } |
| 2806 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2807 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2808 | if (!opendata->f_attr.mdsthreshold) { |
| 2809 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2810 | if (!opendata->f_attr.mdsthreshold) |
| 2811 | goto err_free_label; |
| 2812 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2813 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2814 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2815 | if (d_really_is_positive(dentry)) |
| 2816 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2817 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2818 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2819 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2820 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2821 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2822 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2823 | 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] | 2824 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2825 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2826 | /* |
| 2827 | * send create attributes which was not set by open |
| 2828 | * with an extra setattr. |
| 2829 | */ |
| 2830 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2831 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2832 | status = nfs4_do_setattr(state->inode, cred, |
| 2833 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2834 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2835 | if (status == 0) { |
| 2836 | nfs_setattr_update_inode(state->inode, sattr, |
| 2837 | opendata->o_res.f_attr); |
| 2838 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2839 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2840 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2841 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2842 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2843 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2844 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2845 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2846 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2847 | opendata->f_attr.mdsthreshold = NULL; |
| 2848 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2849 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2850 | nfs4_label_free(olabel); |
| 2851 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2852 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2855 | err_free_label: |
| 2856 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2857 | err_opendata_put: |
| 2858 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2859 | err_put_state_owner: |
| 2860 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | return status; |
| 2863 | } |
| 2864 | |
| 2865 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2866 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2867 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2868 | int flags, |
| 2869 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2870 | struct nfs4_label *label, |
| 2871 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2873 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | struct nfs4_exception exception = { }; |
| 2875 | struct nfs4_state *res; |
| 2876 | int status; |
| 2877 | |
| 2878 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2879 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2880 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2881 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | if (status == 0) |
| 2883 | break; |
| 2884 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2885 | * book-keeping w.r.t. state-changing operations |
| 2886 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2887 | * It is actually a sign of a bug on the client or on the server. |
| 2888 | * |
| 2889 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2890 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | * have unhashed the old state_owner for us, and that we can |
| 2892 | * therefore safely retry using a new one. We should still warn |
| 2893 | * the user though... |
| 2894 | */ |
| 2895 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2896 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2897 | " returned a bad sequence-id error!\n", |
| 2898 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | exception.retry = 1; |
| 2900 | continue; |
| 2901 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2902 | /* |
| 2903 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2904 | * state before it received the OPEN_CONFIRM. |
| 2905 | * Recover by retrying the request as per the discussion |
| 2906 | * on Page 181 of RFC3530. |
| 2907 | */ |
| 2908 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2909 | exception.retry = 1; |
| 2910 | continue; |
| 2911 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2912 | if (status == -EAGAIN) { |
| 2913 | /* We must have found a delegation */ |
| 2914 | exception.retry = 1; |
| 2915 | continue; |
| 2916 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2917 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2918 | continue; |
| 2919 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | status, &exception)); |
| 2921 | } while (exception.retry); |
| 2922 | return res; |
| 2923 | } |
| 2924 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2925 | static int _nfs4_do_setattr(struct inode *inode, |
| 2926 | struct nfs_setattrargs *arg, |
| 2927 | struct nfs_setattrres *res, |
| 2928 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2929 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2930 | { |
| 2931 | struct nfs_server *server = NFS_SERVER(inode); |
| 2932 | struct rpc_message msg = { |
| 2933 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2934 | .rpc_argp = arg, |
| 2935 | .rpc_resp = res, |
| 2936 | .rpc_cred = cred, |
| 2937 | }; |
| 2938 | struct rpc_cred *delegation_cred = NULL; |
| 2939 | unsigned long timestamp = jiffies; |
| 2940 | fmode_t fmode; |
| 2941 | bool truncate; |
| 2942 | int status; |
| 2943 | |
| 2944 | nfs_fattr_init(res->fattr); |
| 2945 | |
| 2946 | /* Servers should only apply open mode checks for file size changes */ |
| 2947 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2948 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2949 | |
| 2950 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2951 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2952 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2953 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2954 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2955 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2956 | l_ctx = nfs_get_lock_context(ctx); |
| 2957 | if (IS_ERR(l_ctx)) |
| 2958 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2959 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2960 | &arg->stateid, &delegation_cred); |
| 2961 | nfs_put_lock_context(l_ctx); |
| 2962 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2963 | return -EBADF; |
| 2964 | } else |
| 2965 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2966 | if (delegation_cred) |
| 2967 | msg.rpc_cred = delegation_cred; |
| 2968 | |
| 2969 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2970 | |
| 2971 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2972 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2973 | renew_lease(server, timestamp); |
| 2974 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2975 | return status; |
| 2976 | } |
| 2977 | |
| 2978 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2979 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2980 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2981 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2983 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2984 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2986 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | .iap = sattr, |
| 2988 | .server = server, |
| 2989 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2990 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | }; |
| 2992 | struct nfs_setattrres res = { |
| 2993 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2994 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | .server = server, |
| 2996 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2997 | struct nfs4_exception exception = { |
| 2998 | .state = state, |
| 2999 | .inode = inode, |
| 3000 | .stateid = &arg.stateid, |
| 3001 | }; |
| 3002 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3004 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3005 | if (ilabel) |
| 3006 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3009 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3010 | switch (err) { |
| 3011 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3012 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3013 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3014 | "applying open mode checks to " |
| 3015 | "a SETATTR that is not " |
| 3016 | "changing file size.\n", |
| 3017 | server->nfs_client->cl_hostname); |
| 3018 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3019 | if (state && !(state->state & FMODE_WRITE)) { |
| 3020 | err = -EBADF; |
| 3021 | if (sattr->ia_valid & ATTR_OPEN) |
| 3022 | err = -EACCES; |
| 3023 | goto out; |
| 3024 | } |
| 3025 | } |
| 3026 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3028 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | return err; |
| 3030 | } |
| 3031 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3032 | static bool |
| 3033 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3034 | { |
| 3035 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3036 | return false; |
| 3037 | |
| 3038 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3039 | } |
| 3040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | struct nfs4_closedata { |
| 3042 | struct inode *inode; |
| 3043 | struct nfs4_state *state; |
| 3044 | struct nfs_closeargs arg; |
| 3045 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3046 | struct { |
| 3047 | struct nfs4_layoutreturn_args arg; |
| 3048 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3049 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3050 | u32 roc_barrier; |
| 3051 | bool roc; |
| 3052 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3053 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3054 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | }; |
| 3056 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3057 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3058 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3059 | struct nfs4_closedata *calldata = data; |
| 3060 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3061 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3062 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3063 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3064 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3065 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3066 | nfs4_put_open_state(calldata->state); |
| 3067 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3068 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3069 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3070 | kfree(calldata); |
| 3071 | } |
| 3072 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3073 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3075 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3078 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3080 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3081 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3082 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3083 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3084 | |
| 3085 | /* Handle Layoutreturn errors */ |
| 3086 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3087 | switch (calldata->res.lr_ret) { |
| 3088 | default: |
| 3089 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3090 | break; |
| 3091 | case 0: |
| 3092 | calldata->arg.lr_args = NULL; |
| 3093 | calldata->res.lr_res = NULL; |
| 3094 | break; |
| 3095 | case -NFS4ERR_ADMIN_REVOKED: |
| 3096 | case -NFS4ERR_DELEG_REVOKED: |
| 3097 | case -NFS4ERR_EXPIRED: |
| 3098 | case -NFS4ERR_BAD_STATEID: |
| 3099 | case -NFS4ERR_OLD_STATEID: |
| 3100 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3101 | case -NFS4ERR_WRONG_CRED: |
| 3102 | calldata->arg.lr_args = NULL; |
| 3103 | calldata->res.lr_res = NULL; |
| 3104 | calldata->res.lr_ret = 0; |
| 3105 | rpc_restart_call_prepare(task); |
| 3106 | return; |
| 3107 | } |
| 3108 | } |
| 3109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | /* hmm. we are done with the inode, and in the process of freeing |
| 3111 | * the state_owner. we keep this around to process errors |
| 3112 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | switch (task->tk_status) { |
| 3114 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3115 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3116 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3117 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3118 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3120 | case -NFS4ERR_EXPIRED: |
| 3121 | nfs4_free_revoked_stateid(server, |
| 3122 | &calldata->arg.stateid, |
| 3123 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3124 | case -NFS4ERR_OLD_STATEID: |
| 3125 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3126 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3127 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3128 | rpc_restart_call_prepare(task); |
| 3129 | goto out_release; |
| 3130 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3131 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3132 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3134 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3135 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3136 | goto out_release; |
| 3137 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3139 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3140 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3141 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3142 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3143 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3144 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3147 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3149 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3150 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3151 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3152 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3153 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3154 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3155 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3156 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3157 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3158 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3159 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3160 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3161 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3162 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3163 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3164 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3165 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3166 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3167 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3168 | if (state->n_rdonly == 0) |
| 3169 | call_close |= is_rdonly; |
| 3170 | else if (is_rdonly) |
| 3171 | calldata->arg.fmode |= FMODE_READ; |
| 3172 | if (state->n_wronly == 0) |
| 3173 | call_close |= is_wronly; |
| 3174 | else if (is_wronly) |
| 3175 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3176 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3177 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3178 | } else if (is_rdwr) |
| 3179 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3180 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3181 | if (!nfs4_valid_open_stateid(state) || |
| 3182 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3183 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3184 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3185 | |
| 3186 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3187 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3188 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3189 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3190 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3191 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3192 | nfs_release_seqid(calldata->arg.seqid); |
| 3193 | goto out_wait; |
| 3194 | } |
| 3195 | |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3196 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3197 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3198 | |
| 3199 | /* Close-to-open cache consistency revalidation */ |
| 3200 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3201 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3202 | else |
| 3203 | calldata->arg.bitmask = NULL; |
| 3204 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3205 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3206 | calldata->arg.share_access = |
| 3207 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3208 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3209 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3210 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3211 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3212 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3213 | &calldata->arg.seq_args, |
| 3214 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3215 | task) != 0) |
| 3216 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3217 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3218 | return; |
| 3219 | out_no_action: |
| 3220 | task->tk_action = NULL; |
| 3221 | out_wait: |
| 3222 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3225 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3226 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3227 | .rpc_call_done = nfs4_close_done, |
| 3228 | .rpc_release = nfs4_free_closedata, |
| 3229 | }; |
| 3230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | /* |
| 3232 | * It is possible for data to be read/written from a mem-mapped file |
| 3233 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3234 | * This means that we can't safely call nfsv4 close on a file until |
| 3235 | * the inode is cleared. This in turn means that we are not good |
| 3236 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3237 | * share state even when we are done with one of the three share |
| 3238 | * stateid's in the inode. |
| 3239 | * |
| 3240 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3241 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3242 | 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] | 3243 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3244 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3245 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3247 | struct nfs4_state_owner *sp = state->owner; |
| 3248 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3249 | struct rpc_message msg = { |
| 3250 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3251 | .rpc_cred = state->owner->so_cred, |
| 3252 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3253 | struct rpc_task_setup task_setup_data = { |
| 3254 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3255 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3256 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3257 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3258 | .flags = RPC_TASK_ASYNC, |
| 3259 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3260 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3262 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3263 | &task_setup_data.rpc_client, &msg); |
| 3264 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3265 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3267 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3268 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3269 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3271 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3273 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3274 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3275 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3276 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3277 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3278 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3279 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3280 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3281 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3282 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3283 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3284 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3285 | if (calldata->lr.roc) { |
| 3286 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3287 | calldata->res.lr_res = &calldata->lr.res; |
| 3288 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3289 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3290 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3291 | msg.rpc_argp = &calldata->arg; |
| 3292 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3293 | task_setup_data.callback_data = calldata; |
| 3294 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3295 | if (IS_ERR(task)) |
| 3296 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3297 | status = 0; |
| 3298 | if (wait) |
| 3299 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3300 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3301 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3302 | out_free_calldata: |
| 3303 | kfree(calldata); |
| 3304 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3305 | nfs4_put_open_state(state); |
| 3306 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3307 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3310 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3311 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3312 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3315 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3316 | |
| 3317 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3319 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3320 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3321 | |
| 3322 | nfs4_label_release_security(label); |
| 3323 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3324 | if (IS_ERR(state)) |
| 3325 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3326 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3329 | 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] | 3330 | { |
| 3331 | if (ctx->state == NULL) |
| 3332 | return; |
| 3333 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3334 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3335 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3336 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3339 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3340 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 3341 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3344 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3345 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3346 | struct nfs4_server_caps_arg args = { |
| 3347 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3348 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3349 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | struct nfs4_server_caps_res res = {}; |
| 3351 | struct rpc_message msg = { |
| 3352 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3353 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | .rpc_resp = &res, |
| 3355 | }; |
| 3356 | int status; |
| 3357 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3358 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3359 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3360 | FATTR4_WORD0_LINK_SUPPORT | |
| 3361 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3362 | FATTR4_WORD0_ACLSUPPORT; |
| 3363 | if (minorversion) |
| 3364 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3365 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3366 | 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] | 3367 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3368 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3369 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3370 | case 0: |
| 3371 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3372 | res.attr_bitmask[2] = 0; |
| 3373 | break; |
| 3374 | case 1: |
| 3375 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3376 | break; |
| 3377 | case 2: |
| 3378 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3381 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3382 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3383 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3384 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3385 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3386 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3387 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3388 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | server->caps |= NFS_CAP_ACLS; |
| 3390 | if (res.has_links != 0) |
| 3391 | server->caps |= NFS_CAP_HARDLINKS; |
| 3392 | if (res.has_symlinks != 0) |
| 3393 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3394 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3395 | server->caps |= NFS_CAP_FILEID; |
| 3396 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3397 | server->caps |= NFS_CAP_MODE; |
| 3398 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3399 | server->caps |= NFS_CAP_NLINK; |
| 3400 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3401 | server->caps |= NFS_CAP_OWNER; |
| 3402 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3403 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3404 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3405 | server->caps |= NFS_CAP_ATIME; |
| 3406 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3407 | server->caps |= NFS_CAP_CTIME; |
| 3408 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3409 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3410 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3411 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3412 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3413 | #endif |
| 3414 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3415 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3416 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3417 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3418 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3419 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3420 | 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] | 3421 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3422 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3423 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3425 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | return status; |
| 3429 | } |
| 3430 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3431 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | { |
| 3433 | struct nfs4_exception exception = { }; |
| 3434 | int err; |
| 3435 | do { |
| 3436 | err = nfs4_handle_exception(server, |
| 3437 | _nfs4_server_capabilities(server, fhandle), |
| 3438 | &exception); |
| 3439 | } while (exception.retry); |
| 3440 | return err; |
| 3441 | } |
| 3442 | |
| 3443 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3444 | struct nfs_fsinfo *info) |
| 3445 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3446 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3448 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | }; |
| 3450 | struct nfs4_lookup_res res = { |
| 3451 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3452 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | .fh = fhandle, |
| 3454 | }; |
| 3455 | struct rpc_message msg = { |
| 3456 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3457 | .rpc_argp = &args, |
| 3458 | .rpc_resp = &res, |
| 3459 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3460 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3461 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3462 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3463 | /* |
| 3464 | * Process the label in the upcoming getfattr |
| 3465 | */ |
| 3466 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3467 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3468 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3469 | 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] | 3470 | } |
| 3471 | |
| 3472 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3473 | struct nfs_fsinfo *info) |
| 3474 | { |
| 3475 | struct nfs4_exception exception = { }; |
| 3476 | int err; |
| 3477 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3478 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3479 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3480 | switch (err) { |
| 3481 | case 0: |
| 3482 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3483 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3484 | default: |
| 3485 | err = nfs4_handle_exception(server, err, &exception); |
| 3486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3488 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | return err; |
| 3490 | } |
| 3491 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3492 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3493 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3494 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3495 | struct rpc_auth_create_args auth_args = { |
| 3496 | .pseudoflavor = flavor, |
| 3497 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3498 | struct rpc_auth *auth; |
| 3499 | int ret; |
| 3500 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3501 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3502 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3503 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3504 | goto out; |
| 3505 | } |
| 3506 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3507 | out: |
| 3508 | return ret; |
| 3509 | } |
| 3510 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3511 | /* |
| 3512 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3513 | * |
| 3514 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3515 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3516 | * |
| 3517 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3518 | * negative errno value. |
| 3519 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3520 | 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] | 3521 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3523 | /* Per 3530bis 15.33.5 */ |
| 3524 | static const rpc_authflavor_t flav_array[] = { |
| 3525 | RPC_AUTH_GSS_KRB5P, |
| 3526 | RPC_AUTH_GSS_KRB5I, |
| 3527 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3528 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3529 | RPC_AUTH_NULL, |
| 3530 | }; |
| 3531 | int status = -EPERM; |
| 3532 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3534 | if (server->auth_info.flavor_len > 0) { |
| 3535 | /* try each flavor specified by user */ |
| 3536 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3537 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3538 | server->auth_info.flavors[i]); |
| 3539 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3540 | continue; |
| 3541 | break; |
| 3542 | } |
| 3543 | } else { |
| 3544 | /* no flavors specified by user, try default list */ |
| 3545 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3546 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3547 | flav_array[i]); |
| 3548 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3549 | continue; |
| 3550 | break; |
| 3551 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3552 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3553 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3554 | /* |
| 3555 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3556 | * to access the mount. It could also mean that we tried to mount |
| 3557 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3558 | * existing mount programs don't handle -EACCES very well so it should |
| 3559 | * be mapped to -EPERM instead. |
| 3560 | */ |
| 3561 | if (status == -EACCES) |
| 3562 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3563 | return status; |
| 3564 | } |
| 3565 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3566 | /** |
| 3567 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3568 | * @server: initialized nfs_server handle |
| 3569 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3570 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3571 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3572 | * |
| 3573 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3574 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3575 | 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] | 3576 | struct nfs_fsinfo *info, |
| 3577 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3578 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3579 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3580 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3581 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3582 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3583 | |
| 3584 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3585 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3586 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | if (status == 0) |
| 3589 | status = nfs4_server_capabilities(server, fhandle); |
| 3590 | if (status == 0) |
| 3591 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3592 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3593 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3596 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3597 | struct nfs_fsinfo *info) |
| 3598 | { |
| 3599 | int error; |
| 3600 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3601 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3602 | |
| 3603 | error = nfs4_server_capabilities(server, mntfh); |
| 3604 | if (error < 0) { |
| 3605 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3606 | return error; |
| 3607 | } |
| 3608 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3609 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3610 | if (IS_ERR(label)) |
| 3611 | return PTR_ERR(label); |
| 3612 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3613 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3614 | if (error < 0) { |
| 3615 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3616 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3620 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3621 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3622 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3623 | err_free_label: |
| 3624 | nfs4_label_free(label); |
| 3625 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3626 | return error; |
| 3627 | } |
| 3628 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3629 | /* |
| 3630 | * Get locations and (maybe) other attributes of a referral. |
| 3631 | * Note that we'll actually follow the referral later when |
| 3632 | * we detect fsid mismatch in inode revalidation |
| 3633 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3634 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3635 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3636 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3637 | { |
| 3638 | int status = -ENOMEM; |
| 3639 | struct page *page = NULL; |
| 3640 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3641 | |
| 3642 | page = alloc_page(GFP_KERNEL); |
| 3643 | if (page == NULL) |
| 3644 | goto out; |
| 3645 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3646 | if (locations == NULL) |
| 3647 | goto out; |
| 3648 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3649 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3650 | if (status != 0) |
| 3651 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3652 | |
| 3653 | /* |
| 3654 | * If the fsid didn't change, this is a migration event, not a |
| 3655 | * referral. Cause us to drop into the exception handler, which |
| 3656 | * will kick off migration recovery. |
| 3657 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3658 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3659 | dprintk("%s: server did not return a different fsid for" |
| 3660 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3661 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3662 | goto out; |
| 3663 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3664 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3665 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3666 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3667 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3668 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3669 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3670 | out: |
| 3671 | if (page) |
| 3672 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3673 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3674 | return status; |
| 3675 | } |
| 3676 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3677 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3678 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | { |
| 3680 | struct nfs4_getattr_arg args = { |
| 3681 | .fh = fhandle, |
| 3682 | .bitmask = server->attr_bitmask, |
| 3683 | }; |
| 3684 | struct nfs4_getattr_res res = { |
| 3685 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3686 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | .server = server, |
| 3688 | }; |
| 3689 | struct rpc_message msg = { |
| 3690 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3691 | .rpc_argp = &args, |
| 3692 | .rpc_resp = &res, |
| 3693 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3694 | |
| 3695 | args.bitmask = nfs4_bitmask(server, label); |
| 3696 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3697 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3698 | 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] | 3699 | } |
| 3700 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3701 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3702 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | { |
| 3704 | struct nfs4_exception exception = { }; |
| 3705 | int err; |
| 3706 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3707 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3708 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3709 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | &exception); |
| 3711 | } while (exception.retry); |
| 3712 | return err; |
| 3713 | } |
| 3714 | |
| 3715 | /* |
| 3716 | * The file is not closed if it is opened due to the a request to change |
| 3717 | * the size of the file. The open call will not be needed once the |
| 3718 | * VFS layer lookup-intents are implemented. |
| 3719 | * |
| 3720 | * Close is called when the inode is destroyed. |
| 3721 | * If we haven't opened the file for O_WRONLY, we |
| 3722 | * need to in the size_change case to obtain a stateid. |
| 3723 | * |
| 3724 | * Got race? |
| 3725 | * Because OPEN is always done by name in nfsv4, it is |
| 3726 | * possible that we opened a different file by the same |
| 3727 | * name. We can recognize this race condition, but we |
| 3728 | * can't do anything about it besides returning an error. |
| 3729 | * |
| 3730 | * This will be fixed with VFS changes (lookup-intent). |
| 3731 | */ |
| 3732 | static int |
| 3733 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3734 | struct iattr *sattr) |
| 3735 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3736 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3737 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3738 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3739 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | int status; |
| 3741 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3742 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3743 | sattr->ia_valid & ATTR_SIZE && |
| 3744 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3745 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3746 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3747 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3749 | /* Deal with open(O_TRUNC) */ |
| 3750 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3751 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3752 | |
| 3753 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3754 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3755 | return 0; |
| 3756 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3757 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3758 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3759 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3760 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3761 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3762 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3763 | } |
| 3764 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3765 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3766 | if (IS_ERR(label)) |
| 3767 | return PTR_ERR(label); |
| 3768 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3769 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3770 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3771 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3772 | nfs_setsecurity(inode, fattr, label); |
| 3773 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3774 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | return status; |
| 3776 | } |
| 3777 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3778 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3779 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3780 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3781 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3782 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3783 | int status; |
| 3784 | struct nfs4_lookup_arg args = { |
| 3785 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3786 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3787 | .name = name, |
| 3788 | }; |
| 3789 | struct nfs4_lookup_res res = { |
| 3790 | .server = server, |
| 3791 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3792 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3793 | .fh = fhandle, |
| 3794 | }; |
| 3795 | struct rpc_message msg = { |
| 3796 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3797 | .rpc_argp = &args, |
| 3798 | .rpc_resp = &res, |
| 3799 | }; |
| 3800 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3801 | args.bitmask = nfs4_bitmask(server, label); |
| 3802 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3803 | nfs_fattr_init(fattr); |
| 3804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3806 | 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] | 3807 | dprintk("NFS reply lookup: %d\n", status); |
| 3808 | return status; |
| 3809 | } |
| 3810 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3811 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3812 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3813 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3814 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3815 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3816 | fattr->nlink = 2; |
| 3817 | } |
| 3818 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3819 | 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] | 3820 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3821 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3822 | { |
| 3823 | struct nfs4_exception exception = { }; |
| 3824 | struct rpc_clnt *client = *clnt; |
| 3825 | int err; |
| 3826 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3827 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3828 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3829 | switch (err) { |
| 3830 | case -NFS4ERR_BADNAME: |
| 3831 | err = -ENOENT; |
| 3832 | goto out; |
| 3833 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3834 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3835 | if (err == -NFS4ERR_MOVED) |
| 3836 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3837 | goto out; |
| 3838 | case -NFS4ERR_WRONGSEC: |
| 3839 | err = -EPERM; |
| 3840 | if (client != *clnt) |
| 3841 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3842 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3843 | if (IS_ERR(client)) |
| 3844 | return PTR_ERR(client); |
| 3845 | |
| 3846 | exception.retry = 1; |
| 3847 | break; |
| 3848 | default: |
| 3849 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3850 | } |
| 3851 | } while (exception.retry); |
| 3852 | |
| 3853 | out: |
| 3854 | if (err == 0) |
| 3855 | *clnt = client; |
| 3856 | else if (client != *clnt) |
| 3857 | rpc_shutdown_client(client); |
| 3858 | |
| 3859 | return err; |
| 3860 | } |
| 3861 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3862 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3863 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3864 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3866 | int status; |
| 3867 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3868 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3869 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3870 | if (client != NFS_CLIENT(dir)) { |
| 3871 | rpc_shutdown_client(client); |
| 3872 | nfs_fixup_secinfo_attributes(fattr); |
| 3873 | } |
| 3874 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3877 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3878 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3879 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3880 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3881 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3882 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3883 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3884 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3885 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3886 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3887 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3888 | } |
| 3889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3891 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3892 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | struct nfs4_accessargs args = { |
| 3894 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3895 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3897 | struct nfs4_accessres res = { |
| 3898 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3899 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | struct rpc_message msg = { |
| 3901 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3902 | .rpc_argp = &args, |
| 3903 | .rpc_resp = &res, |
| 3904 | .rpc_cred = entry->cred, |
| 3905 | }; |
| 3906 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3907 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | |
| 3909 | /* |
| 3910 | * Determine which access bits we want to ask for... |
| 3911 | */ |
| 3912 | if (mode & MAY_READ) |
| 3913 | args.access |= NFS4_ACCESS_READ; |
| 3914 | if (S_ISDIR(inode->i_mode)) { |
| 3915 | if (mode & MAY_WRITE) |
| 3916 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3917 | if (mode & MAY_EXEC) |
| 3918 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3919 | } else { |
| 3920 | if (mode & MAY_WRITE) |
| 3921 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3922 | if (mode & MAY_EXEC) |
| 3923 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3924 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3925 | |
| 3926 | res.fattr = nfs_alloc_fattr(); |
| 3927 | if (res.fattr == NULL) |
| 3928 | return -ENOMEM; |
| 3929 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3930 | 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] | 3931 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3932 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3933 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3935 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | return status; |
| 3937 | } |
| 3938 | |
| 3939 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3940 | { |
| 3941 | struct nfs4_exception exception = { }; |
| 3942 | int err; |
| 3943 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3944 | err = _nfs4_proc_access(inode, entry); |
| 3945 | trace_nfs4_access(inode, err); |
| 3946 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | &exception); |
| 3948 | } while (exception.retry); |
| 3949 | return err; |
| 3950 | } |
| 3951 | |
| 3952 | /* |
| 3953 | * TODO: For the time being, we don't try to get any attributes |
| 3954 | * along with any of the zero-copy operations READ, READDIR, |
| 3955 | * READLINK, WRITE. |
| 3956 | * |
| 3957 | * In the case of the first three, we want to put the GETATTR |
| 3958 | * after the read-type operation -- this is because it is hard |
| 3959 | * to predict the length of a GETATTR response in v4, and thus |
| 3960 | * align the READ data correctly. This means that the GETATTR |
| 3961 | * may end up partially falling into the page cache, and we should |
| 3962 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3963 | * To do this efficiently, we need to know the total length |
| 3964 | * of data received, which doesn't seem to be available outside |
| 3965 | * of the RPC layer. |
| 3966 | * |
| 3967 | * In the case of WRITE, we also want to put the GETATTR after |
| 3968 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3969 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | * |
| 3971 | * Both of these changes to the XDR layer would in fact be quite |
| 3972 | * minor, but I decided to leave them for a subsequent patch. |
| 3973 | */ |
| 3974 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3975 | unsigned int pgbase, unsigned int pglen) |
| 3976 | { |
| 3977 | struct nfs4_readlink args = { |
| 3978 | .fh = NFS_FH(inode), |
| 3979 | .pgbase = pgbase, |
| 3980 | .pglen = pglen, |
| 3981 | .pages = &page, |
| 3982 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3983 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | struct rpc_message msg = { |
| 3985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3986 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3987 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | }; |
| 3989 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3990 | 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] | 3991 | } |
| 3992 | |
| 3993 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3994 | unsigned int pgbase, unsigned int pglen) |
| 3995 | { |
| 3996 | struct nfs4_exception exception = { }; |
| 3997 | int err; |
| 3998 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3999 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4000 | trace_nfs4_readlink(inode, err); |
| 4001 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | &exception); |
| 4003 | } while (exception.retry); |
| 4004 | return err; |
| 4005 | } |
| 4006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4008 | * 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] | 4009 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | static int |
| 4011 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4012 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4014 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4015 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4016 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | int status = 0; |
| 4019 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4020 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4021 | if (IS_ERR(ctx)) |
| 4022 | return PTR_ERR(ctx); |
| 4023 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4024 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4025 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4026 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4027 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4028 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | if (IS_ERR(state)) { |
| 4030 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4031 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4034 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4035 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | return status; |
| 4037 | } |
| 4038 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4039 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4041 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4042 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4044 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4046 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4047 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4048 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4050 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4051 | .rpc_argp = &args, |
| 4052 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4054 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4055 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4056 | 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] | 4057 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4058 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | return status; |
| 4060 | } |
| 4061 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4062 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | { |
| 4064 | struct nfs4_exception exception = { }; |
| 4065 | int err; |
| 4066 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4067 | err = _nfs4_proc_remove(dir, name); |
| 4068 | trace_nfs4_remove(dir, name, err); |
| 4069 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | &exception); |
| 4071 | } while (exception.retry); |
| 4072 | return err; |
| 4073 | } |
| 4074 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4075 | 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] | 4076 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4077 | struct nfs_server *server = NFS_SERVER(dir); |
| 4078 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4079 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4081 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4083 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4084 | |
| 4085 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4088 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4089 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4090 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4091 | &data->args.seq_args, |
| 4092 | &data->res.seq_res, |
| 4093 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4096 | 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] | 4097 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4098 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4099 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4100 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4101 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4102 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4103 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4104 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4105 | return 0; |
| 4106 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4107 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4110 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4111 | { |
| 4112 | struct nfs_server *server = NFS_SERVER(dir); |
| 4113 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4114 | struct nfs_renameres *res = msg->rpc_resp; |
| 4115 | |
| 4116 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4117 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4118 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4119 | } |
| 4120 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4121 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4122 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4123 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4124 | &data->args.seq_args, |
| 4125 | &data->res.seq_res, |
| 4126 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4130 | struct inode *new_dir) |
| 4131 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4132 | struct nfs_renamedata *data = task->tk_calldata; |
| 4133 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4134 | |
| 4135 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4136 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4137 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4138 | return 0; |
| 4139 | |
| 4140 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4141 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4142 | return 1; |
| 4143 | } |
| 4144 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4145 | 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] | 4146 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4147 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | struct nfs4_link_arg arg = { |
| 4149 | .fh = NFS_FH(inode), |
| 4150 | .dir_fh = NFS_FH(dir), |
| 4151 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4152 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4154 | struct nfs4_link_res res = { |
| 4155 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4156 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4157 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | struct rpc_message msg = { |
| 4159 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4160 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4161 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4163 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4165 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4166 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4167 | goto out; |
| 4168 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4169 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4170 | if (IS_ERR(res.label)) { |
| 4171 | status = PTR_ERR(res.label); |
| 4172 | goto out; |
| 4173 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4174 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4175 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4176 | 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] | 4177 | if (!status) { |
| 4178 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4179 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4180 | if (!status) |
| 4181 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4182 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4183 | |
| 4184 | |
| 4185 | nfs4_label_free(res.label); |
| 4186 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4187 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4188 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | return status; |
| 4190 | } |
| 4191 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4192 | 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] | 4193 | { |
| 4194 | struct nfs4_exception exception = { }; |
| 4195 | int err; |
| 4196 | do { |
| 4197 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4198 | _nfs4_proc_link(inode, dir, name), |
| 4199 | &exception); |
| 4200 | } while (exception.retry); |
| 4201 | return err; |
| 4202 | } |
| 4203 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4204 | struct nfs4_createdata { |
| 4205 | struct rpc_message msg; |
| 4206 | struct nfs4_create_arg arg; |
| 4207 | struct nfs4_create_res res; |
| 4208 | struct nfs_fh fh; |
| 4209 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4210 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | }; |
| 4212 | |
| 4213 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4214 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4215 | { |
| 4216 | struct nfs4_createdata *data; |
| 4217 | |
| 4218 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4219 | if (data != NULL) { |
| 4220 | struct nfs_server *server = NFS_SERVER(dir); |
| 4221 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4222 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4223 | if (IS_ERR(data->label)) |
| 4224 | goto out_free; |
| 4225 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4226 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4227 | data->msg.rpc_argp = &data->arg; |
| 4228 | data->msg.rpc_resp = &data->res; |
| 4229 | data->arg.dir_fh = NFS_FH(dir); |
| 4230 | data->arg.server = server; |
| 4231 | data->arg.name = name; |
| 4232 | data->arg.attrs = sattr; |
| 4233 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4234 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4235 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4236 | data->res.server = server; |
| 4237 | data->res.fh = &data->fh; |
| 4238 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4239 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4240 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4241 | } |
| 4242 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4243 | out_free: |
| 4244 | kfree(data); |
| 4245 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4249 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4250 | 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] | 4251 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4252 | if (status == 0) { |
| 4253 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4254 | 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] | 4255 | } |
| 4256 | return status; |
| 4257 | } |
| 4258 | |
| 4259 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4260 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4261 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4262 | kfree(data); |
| 4263 | } |
| 4264 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4265 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4266 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4267 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4269 | struct nfs4_createdata *data; |
| 4270 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4272 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4273 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4274 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4275 | status = -ENOMEM; |
| 4276 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4277 | if (data == NULL) |
| 4278 | goto out; |
| 4279 | |
| 4280 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4281 | data->arg.u.symlink.pages = &page; |
| 4282 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4283 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4285 | status = nfs4_do_create(dir, dentry, data); |
| 4286 | |
| 4287 | nfs4_free_createdata(data); |
| 4288 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | return status; |
| 4290 | } |
| 4291 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4292 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4293 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | { |
| 4295 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4296 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4298 | |
| 4299 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4302 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4303 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4304 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | &exception); |
| 4306 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4307 | |
| 4308 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | return err; |
| 4310 | } |
| 4311 | |
| 4312 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4313 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4315 | struct nfs4_createdata *data; |
| 4316 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4318 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4319 | if (data == NULL) |
| 4320 | goto out; |
| 4321 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4322 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4323 | status = nfs4_do_create(dir, dentry, data); |
| 4324 | |
| 4325 | nfs4_free_createdata(data); |
| 4326 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | return status; |
| 4328 | } |
| 4329 | |
| 4330 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4331 | struct iattr *sattr) |
| 4332 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4333 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4335 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4337 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4338 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4339 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4340 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4341 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4343 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4344 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4345 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | &exception); |
| 4347 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4348 | nfs4_label_release_security(label); |
| 4349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | return err; |
| 4351 | } |
| 4352 | |
| 4353 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4354 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4356 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | struct nfs4_readdir_arg args = { |
| 4358 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4359 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | .pgbase = 0, |
| 4361 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4362 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4363 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | }; |
| 4365 | struct nfs4_readdir_res res; |
| 4366 | struct rpc_message msg = { |
| 4367 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4368 | .rpc_argp = &args, |
| 4369 | .rpc_resp = &res, |
| 4370 | .rpc_cred = cred, |
| 4371 | }; |
| 4372 | int status; |
| 4373 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4374 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4375 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4376 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4377 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4379 | 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] | 4380 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4381 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4382 | status += args.pgbase; |
| 4383 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4384 | |
| 4385 | nfs_invalidate_atime(dir); |
| 4386 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4387 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | return status; |
| 4389 | } |
| 4390 | |
| 4391 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4392 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | { |
| 4394 | struct nfs4_exception exception = { }; |
| 4395 | int err; |
| 4396 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4397 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4398 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4399 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4400 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | &exception); |
| 4402 | } while (exception.retry); |
| 4403 | return err; |
| 4404 | } |
| 4405 | |
| 4406 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4407 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4409 | struct nfs4_createdata *data; |
| 4410 | int mode = sattr->ia_mode; |
| 4411 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4413 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4414 | if (data == NULL) |
| 4415 | goto out; |
| 4416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4418 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4420 | data->arg.ftype = NF4BLK; |
| 4421 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4422 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | } |
| 4424 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4425 | data->arg.ftype = NF4CHR; |
| 4426 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4427 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4428 | } else if (!S_ISSOCK(mode)) { |
| 4429 | status = -EINVAL; |
| 4430 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4432 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4433 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4434 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4435 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4436 | nfs4_free_createdata(data); |
| 4437 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | return status; |
| 4439 | } |
| 4440 | |
| 4441 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4442 | struct iattr *sattr, dev_t rdev) |
| 4443 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4444 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4446 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4448 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4449 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4450 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame^] | 4451 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4452 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4454 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4455 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4456 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | &exception); |
| 4458 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4459 | |
| 4460 | nfs4_label_release_security(label); |
| 4461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | return err; |
| 4463 | } |
| 4464 | |
| 4465 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4466 | struct nfs_fsstat *fsstat) |
| 4467 | { |
| 4468 | struct nfs4_statfs_arg args = { |
| 4469 | .fh = fhandle, |
| 4470 | .bitmask = server->attr_bitmask, |
| 4471 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4472 | struct nfs4_statfs_res res = { |
| 4473 | .fsstat = fsstat, |
| 4474 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | struct rpc_message msg = { |
| 4476 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4477 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4478 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | }; |
| 4480 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4481 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4482 | 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] | 4483 | } |
| 4484 | |
| 4485 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4486 | { |
| 4487 | struct nfs4_exception exception = { }; |
| 4488 | int err; |
| 4489 | do { |
| 4490 | err = nfs4_handle_exception(server, |
| 4491 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4492 | &exception); |
| 4493 | } while (exception.retry); |
| 4494 | return err; |
| 4495 | } |
| 4496 | |
| 4497 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4498 | struct nfs_fsinfo *fsinfo) |
| 4499 | { |
| 4500 | struct nfs4_fsinfo_arg args = { |
| 4501 | .fh = fhandle, |
| 4502 | .bitmask = server->attr_bitmask, |
| 4503 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4504 | struct nfs4_fsinfo_res res = { |
| 4505 | .fsinfo = fsinfo, |
| 4506 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | struct rpc_message msg = { |
| 4508 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4509 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4510 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | }; |
| 4512 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4513 | 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] | 4514 | } |
| 4515 | |
| 4516 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4517 | { |
| 4518 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4519 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | int err; |
| 4521 | |
| 4522 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4523 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4524 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4525 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4526 | nfs4_set_lease_period(server->nfs_client, |
| 4527 | fsinfo->lease_time * HZ, |
| 4528 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4529 | break; |
| 4530 | } |
| 4531 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | } while (exception.retry); |
| 4533 | return err; |
| 4534 | } |
| 4535 | |
| 4536 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4537 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4538 | int error; |
| 4539 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4540 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4541 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4542 | if (error == 0) { |
| 4543 | /* block layout checks this! */ |
| 4544 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4545 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4546 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4547 | |
| 4548 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4552 | struct nfs_pathconf *pathconf) |
| 4553 | { |
| 4554 | struct nfs4_pathconf_arg args = { |
| 4555 | .fh = fhandle, |
| 4556 | .bitmask = server->attr_bitmask, |
| 4557 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4558 | struct nfs4_pathconf_res res = { |
| 4559 | .pathconf = pathconf, |
| 4560 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | struct rpc_message msg = { |
| 4562 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4563 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4564 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | }; |
| 4566 | |
| 4567 | /* None of the pathconf attributes are mandatory to implement */ |
| 4568 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4569 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4570 | return 0; |
| 4571 | } |
| 4572 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4573 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4574 | 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] | 4575 | } |
| 4576 | |
| 4577 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4578 | struct nfs_pathconf *pathconf) |
| 4579 | { |
| 4580 | struct nfs4_exception exception = { }; |
| 4581 | int err; |
| 4582 | |
| 4583 | do { |
| 4584 | err = nfs4_handle_exception(server, |
| 4585 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4586 | &exception); |
| 4587 | } while (exception.retry); |
| 4588 | return err; |
| 4589 | } |
| 4590 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4591 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4592 | const struct nfs_open_context *ctx, |
| 4593 | const struct nfs_lock_context *l_ctx, |
| 4594 | fmode_t fmode) |
| 4595 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4596 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4597 | } |
| 4598 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4599 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4600 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4601 | const struct nfs_open_context *ctx, |
| 4602 | const struct nfs_lock_context *l_ctx, |
| 4603 | fmode_t fmode) |
| 4604 | { |
| 4605 | nfs4_stateid current_stateid; |
| 4606 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4607 | /* If the current stateid represents a lost lock, then exit */ |
| 4608 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4609 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4610 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4611 | } |
| 4612 | |
| 4613 | static bool nfs4_error_stateid_expired(int err) |
| 4614 | { |
| 4615 | switch (err) { |
| 4616 | case -NFS4ERR_DELEG_REVOKED: |
| 4617 | case -NFS4ERR_ADMIN_REVOKED: |
| 4618 | case -NFS4ERR_BAD_STATEID: |
| 4619 | case -NFS4ERR_STALE_STATEID: |
| 4620 | case -NFS4ERR_OLD_STATEID: |
| 4621 | case -NFS4ERR_OPENMODE: |
| 4622 | case -NFS4ERR_EXPIRED: |
| 4623 | return true; |
| 4624 | } |
| 4625 | return false; |
| 4626 | } |
| 4627 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4628 | 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] | 4629 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4630 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4632 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4633 | if (task->tk_status < 0) { |
| 4634 | struct nfs4_exception exception = { |
| 4635 | .inode = hdr->inode, |
| 4636 | .state = hdr->args.context->state, |
| 4637 | .stateid = &hdr->args.stateid, |
| 4638 | }; |
| 4639 | task->tk_status = nfs4_async_handle_exception(task, |
| 4640 | server, task->tk_status, &exception); |
| 4641 | if (exception.retry) { |
| 4642 | rpc_restart_call_prepare(task); |
| 4643 | return -EAGAIN; |
| 4644 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4648 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4649 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4652 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4653 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4654 | { |
| 4655 | |
| 4656 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4657 | nfs4_stateid_is_current(&args->stateid, |
| 4658 | args->context, |
| 4659 | args->lock_context, |
| 4660 | FMODE_READ)) |
| 4661 | return false; |
| 4662 | rpc_restart_call_prepare(task); |
| 4663 | return true; |
| 4664 | } |
| 4665 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4666 | 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] | 4667 | { |
| 4668 | |
| 4669 | dprintk("--> %s\n", __func__); |
| 4670 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4672 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4673 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4674 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4675 | if (task->tk_status > 0) |
| 4676 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4677 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4678 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4681 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4682 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4684 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4685 | if (!hdr->pgio_done_cb) |
| 4686 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4687 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4688 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4691 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4692 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4693 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4694 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4695 | &hdr->args.seq_args, |
| 4696 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4697 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4698 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4699 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4700 | hdr->args.lock_context, |
| 4701 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4702 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4703 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4704 | return -EIO; |
| 4705 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | } |
| 4707 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4708 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4709 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4711 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4712 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4713 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4714 | if (task->tk_status < 0) { |
| 4715 | struct nfs4_exception exception = { |
| 4716 | .inode = hdr->inode, |
| 4717 | .state = hdr->args.context->state, |
| 4718 | .stateid = &hdr->args.stateid, |
| 4719 | }; |
| 4720 | task->tk_status = nfs4_async_handle_exception(task, |
| 4721 | NFS_SERVER(inode), task->tk_status, |
| 4722 | &exception); |
| 4723 | if (exception.retry) { |
| 4724 | rpc_restart_call_prepare(task); |
| 4725 | return -EAGAIN; |
| 4726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4728 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4729 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4730 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4731 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4732 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4735 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4736 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4737 | { |
| 4738 | |
| 4739 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4740 | nfs4_stateid_is_current(&args->stateid, |
| 4741 | args->context, |
| 4742 | args->lock_context, |
| 4743 | FMODE_WRITE)) |
| 4744 | return false; |
| 4745 | rpc_restart_call_prepare(task); |
| 4746 | return true; |
| 4747 | } |
| 4748 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4749 | 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] | 4750 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4751 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4752 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4753 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4754 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4755 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4756 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4757 | } |
| 4758 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4759 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4760 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4761 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4762 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4763 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4764 | return false; |
| 4765 | /* Otherwise, request attributes if and only if we don't hold |
| 4766 | * a delegation |
| 4767 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4768 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4769 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4770 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4771 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4772 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4774 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4775 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4776 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4777 | hdr->args.bitmask = NULL; |
| 4778 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4779 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4780 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4781 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4782 | if (!hdr->pgio_done_cb) |
| 4783 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4784 | hdr->res.server = server; |
| 4785 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4787 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4788 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4791 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4792 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4793 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4794 | &data->args.seq_args, |
| 4795 | &data->res.seq_res, |
| 4796 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | } |
| 4798 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4799 | 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] | 4800 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4802 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4803 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4804 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4805 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4806 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4807 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4809 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4812 | 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] | 4813 | { |
| 4814 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4815 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4816 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4819 | 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] | 4820 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4821 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4822 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4823 | if (data->commit_done_cb == NULL) |
| 4824 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4825 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4826 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4827 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | } |
| 4829 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4830 | struct nfs4_renewdata { |
| 4831 | struct nfs_client *client; |
| 4832 | unsigned long timestamp; |
| 4833 | }; |
| 4834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | /* |
| 4836 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4837 | * standalone procedure for queueing an asynchronous RENEW. |
| 4838 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4839 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4840 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4841 | struct nfs4_renewdata *data = calldata; |
| 4842 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4843 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4844 | if (atomic_read(&clp->cl_count) > 1) |
| 4845 | nfs4_schedule_state_renewal(clp); |
| 4846 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4847 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4848 | } |
| 4849 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4850 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4852 | struct nfs4_renewdata *data = calldata; |
| 4853 | struct nfs_client *clp = data->client; |
| 4854 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4856 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4857 | switch (task->tk_status) { |
| 4858 | case 0: |
| 4859 | break; |
| 4860 | case -NFS4ERR_LEASE_MOVED: |
| 4861 | nfs4_schedule_lease_moved_recovery(clp); |
| 4862 | break; |
| 4863 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4864 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4865 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4866 | return; |
| 4867 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4868 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4869 | return; |
| 4870 | } |
| 4871 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4873 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4876 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4877 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4878 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4879 | }; |
| 4880 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4881 | 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] | 4882 | { |
| 4883 | struct rpc_message msg = { |
| 4884 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4885 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4886 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4888 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4890 | if (renew_flags == 0) |
| 4891 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4892 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4893 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4894 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4895 | if (data == NULL) |
| 4896 | return -ENOMEM; |
| 4897 | data->client = clp; |
| 4898 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4899 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4900 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4903 | 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] | 4904 | { |
| 4905 | struct rpc_message msg = { |
| 4906 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4907 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4908 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | }; |
| 4910 | unsigned long now = jiffies; |
| 4911 | int status; |
| 4912 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4913 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | if (status < 0) |
| 4915 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4916 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | return 0; |
| 4918 | } |
| 4919 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4920 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4921 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4922 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4925 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4926 | * 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] | 4927 | * the stack. |
| 4928 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4929 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4930 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4931 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4932 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4933 | { |
| 4934 | struct page *newpage, **spages; |
| 4935 | int rc = 0; |
| 4936 | size_t len; |
| 4937 | spages = pages; |
| 4938 | |
| 4939 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4940 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4941 | newpage = alloc_page(GFP_KERNEL); |
| 4942 | |
| 4943 | if (newpage == NULL) |
| 4944 | goto unwind; |
| 4945 | memcpy(page_address(newpage), buf, len); |
| 4946 | buf += len; |
| 4947 | buflen -= len; |
| 4948 | *pages++ = newpage; |
| 4949 | rc++; |
| 4950 | } while (buflen != 0); |
| 4951 | |
| 4952 | return rc; |
| 4953 | |
| 4954 | unwind: |
| 4955 | for(; rc > 0; rc--) |
| 4956 | __free_page(spages[rc-1]); |
| 4957 | return -ENOMEM; |
| 4958 | } |
| 4959 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4960 | struct nfs4_cached_acl { |
| 4961 | int cached; |
| 4962 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4963 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4964 | }; |
| 4965 | |
| 4966 | 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] | 4967 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4968 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4969 | |
| 4970 | spin_lock(&inode->i_lock); |
| 4971 | kfree(nfsi->nfs4_acl); |
| 4972 | nfsi->nfs4_acl = acl; |
| 4973 | spin_unlock(&inode->i_lock); |
| 4974 | } |
| 4975 | |
| 4976 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4977 | { |
| 4978 | nfs4_set_cached_acl(inode, NULL); |
| 4979 | } |
| 4980 | |
| 4981 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4982 | { |
| 4983 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4984 | struct nfs4_cached_acl *acl; |
| 4985 | int ret = -ENOENT; |
| 4986 | |
| 4987 | spin_lock(&inode->i_lock); |
| 4988 | acl = nfsi->nfs4_acl; |
| 4989 | if (acl == NULL) |
| 4990 | goto out; |
| 4991 | if (buf == NULL) /* user is just asking for length */ |
| 4992 | goto out_len; |
| 4993 | if (acl->cached == 0) |
| 4994 | goto out; |
| 4995 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4996 | if (acl->len > buflen) |
| 4997 | goto out; |
| 4998 | memcpy(buf, acl->data, acl->len); |
| 4999 | out_len: |
| 5000 | ret = acl->len; |
| 5001 | out: |
| 5002 | spin_unlock(&inode->i_lock); |
| 5003 | return ret; |
| 5004 | } |
| 5005 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5006 | 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] | 5007 | { |
| 5008 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5009 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5010 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5011 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5012 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5013 | if (acl == NULL) |
| 5014 | goto out; |
| 5015 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5016 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5017 | } else { |
| 5018 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5019 | if (acl == NULL) |
| 5020 | goto out; |
| 5021 | acl->cached = 0; |
| 5022 | } |
| 5023 | acl->len = acl_len; |
| 5024 | out: |
| 5025 | nfs4_set_cached_acl(inode, acl); |
| 5026 | } |
| 5027 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5028 | /* |
| 5029 | * The getxattr API returns the required buffer length when called with a |
| 5030 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5031 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5032 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5033 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5034 | * the cache. If not so, we throw away the page, and cache the required |
| 5035 | * length. The next getxattr call will then produce another round trip to |
| 5036 | * the server, this time with the input buf of the required size. |
| 5037 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5038 | 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] | 5039 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5040 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5041 | struct nfs_getaclargs args = { |
| 5042 | .fh = NFS_FH(inode), |
| 5043 | .acl_pages = pages, |
| 5044 | .acl_len = buflen, |
| 5045 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5046 | struct nfs_getaclres res = { |
| 5047 | .acl_len = buflen, |
| 5048 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5049 | struct rpc_message msg = { |
| 5050 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5051 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5052 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5053 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5054 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5055 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5056 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5057 | /* As long as we're doing a round trip to the server anyway, |
| 5058 | * let's be prepared for a page of acl data. */ |
| 5059 | if (npages == 0) |
| 5060 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5061 | if (npages > ARRAY_SIZE(pages)) |
| 5062 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5063 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5064 | for (i = 0; i < npages; i++) { |
| 5065 | pages[i] = alloc_page(GFP_KERNEL); |
| 5066 | if (!pages[i]) |
| 5067 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5068 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5069 | |
| 5070 | /* for decoding across pages */ |
| 5071 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5072 | if (!res.acl_scratch) |
| 5073 | goto out_free; |
| 5074 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5075 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5076 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5077 | 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] | 5078 | __func__, buf, buflen, npages, args.acl_len); |
| 5079 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5080 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5081 | if (ret) |
| 5082 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5083 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5084 | /* Handle the case where the passed-in buffer is too short */ |
| 5085 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5086 | /* Did the user only issue a request for the acl length? */ |
| 5087 | if (buf == NULL) |
| 5088 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5089 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5090 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5091 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5092 | 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] | 5093 | if (buf) { |
| 5094 | if (res.acl_len > buflen) { |
| 5095 | ret = -ERANGE; |
| 5096 | goto out_free; |
| 5097 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5098 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5099 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5100 | out_ok: |
| 5101 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5102 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5103 | for (i = 0; i < npages; i++) |
| 5104 | if (pages[i]) |
| 5105 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5106 | if (res.acl_scratch) |
| 5107 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5108 | return ret; |
| 5109 | } |
| 5110 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5111 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5112 | { |
| 5113 | struct nfs4_exception exception = { }; |
| 5114 | ssize_t ret; |
| 5115 | do { |
| 5116 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5117 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5118 | if (ret >= 0) |
| 5119 | break; |
| 5120 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5121 | } while (exception.retry); |
| 5122 | return ret; |
| 5123 | } |
| 5124 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5125 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5126 | { |
| 5127 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5128 | int ret; |
| 5129 | |
| 5130 | if (!nfs4_server_supports_acls(server)) |
| 5131 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5132 | ret = nfs_revalidate_inode(server, inode); |
| 5133 | if (ret < 0) |
| 5134 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5135 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5136 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5137 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5138 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5139 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5140 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5141 | return ret; |
| 5142 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5145 | 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] | 5146 | { |
| 5147 | struct nfs_server *server = NFS_SERVER(inode); |
| 5148 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5149 | struct nfs_setaclargs arg = { |
| 5150 | .fh = NFS_FH(inode), |
| 5151 | .acl_pages = pages, |
| 5152 | .acl_len = buflen, |
| 5153 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5154 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5155 | struct rpc_message msg = { |
| 5156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5157 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5158 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5159 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5160 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5161 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5162 | |
| 5163 | if (!nfs4_server_supports_acls(server)) |
| 5164 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5165 | if (npages > ARRAY_SIZE(pages)) |
| 5166 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5167 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5168 | if (i < 0) |
| 5169 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5170 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5171 | 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] | 5172 | |
| 5173 | /* |
| 5174 | * Free each page after tx, so the only ref left is |
| 5175 | * held by the network stack |
| 5176 | */ |
| 5177 | for (; i > 0; i--) |
| 5178 | put_page(pages[i-1]); |
| 5179 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5180 | /* |
| 5181 | * Acl update can result in inode attribute update. |
| 5182 | * so mark the attribute cache invalid. |
| 5183 | */ |
| 5184 | spin_lock(&inode->i_lock); |
| 5185 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5186 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5187 | nfs_access_zap_cache(inode); |
| 5188 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5189 | return ret; |
| 5190 | } |
| 5191 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5192 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5193 | { |
| 5194 | struct nfs4_exception exception = { }; |
| 5195 | int err; |
| 5196 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5197 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5198 | trace_nfs4_set_acl(inode, err); |
| 5199 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5200 | &exception); |
| 5201 | } while (exception.retry); |
| 5202 | return err; |
| 5203 | } |
| 5204 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5205 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5206 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5207 | size_t buflen) |
| 5208 | { |
| 5209 | struct nfs_server *server = NFS_SERVER(inode); |
| 5210 | struct nfs_fattr fattr; |
| 5211 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5212 | |
| 5213 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5214 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5215 | .fh = NFS_FH(inode), |
| 5216 | .bitmask = bitmask, |
| 5217 | }; |
| 5218 | struct nfs4_getattr_res res = { |
| 5219 | .fattr = &fattr, |
| 5220 | .label = &label, |
| 5221 | .server = server, |
| 5222 | }; |
| 5223 | struct rpc_message msg = { |
| 5224 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5225 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5226 | .rpc_resp = &res, |
| 5227 | }; |
| 5228 | int ret; |
| 5229 | |
| 5230 | nfs_fattr_init(&fattr); |
| 5231 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5232 | 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] | 5233 | if (ret) |
| 5234 | return ret; |
| 5235 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5236 | return -ENOENT; |
| 5237 | if (buflen < label.len) |
| 5238 | return -ERANGE; |
| 5239 | return 0; |
| 5240 | } |
| 5241 | |
| 5242 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5243 | size_t buflen) |
| 5244 | { |
| 5245 | struct nfs4_exception exception = { }; |
| 5246 | int err; |
| 5247 | |
| 5248 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5249 | return -EOPNOTSUPP; |
| 5250 | |
| 5251 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5252 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5253 | trace_nfs4_get_security_label(inode, err); |
| 5254 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5255 | &exception); |
| 5256 | } while (exception.retry); |
| 5257 | return err; |
| 5258 | } |
| 5259 | |
| 5260 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5261 | struct nfs4_label *ilabel, |
| 5262 | struct nfs_fattr *fattr, |
| 5263 | struct nfs4_label *olabel) |
| 5264 | { |
| 5265 | |
| 5266 | struct iattr sattr = {0}; |
| 5267 | struct nfs_server *server = NFS_SERVER(inode); |
| 5268 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5269 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5270 | .fh = NFS_FH(inode), |
| 5271 | .iap = &sattr, |
| 5272 | .server = server, |
| 5273 | .bitmask = bitmask, |
| 5274 | .label = ilabel, |
| 5275 | }; |
| 5276 | struct nfs_setattrres res = { |
| 5277 | .fattr = fattr, |
| 5278 | .label = olabel, |
| 5279 | .server = server, |
| 5280 | }; |
| 5281 | struct rpc_message msg = { |
| 5282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5283 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5284 | .rpc_resp = &res, |
| 5285 | }; |
| 5286 | int status; |
| 5287 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5288 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5289 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5290 | 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] | 5291 | if (status) |
| 5292 | dprintk("%s failed: %d\n", __func__, status); |
| 5293 | |
| 5294 | return status; |
| 5295 | } |
| 5296 | |
| 5297 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5298 | struct nfs4_label *ilabel, |
| 5299 | struct nfs_fattr *fattr, |
| 5300 | struct nfs4_label *olabel) |
| 5301 | { |
| 5302 | struct nfs4_exception exception = { }; |
| 5303 | int err; |
| 5304 | |
| 5305 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5306 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5307 | fattr, olabel); |
| 5308 | trace_nfs4_set_security_label(inode, err); |
| 5309 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5310 | &exception); |
| 5311 | } while (exception.retry); |
| 5312 | return err; |
| 5313 | } |
| 5314 | |
| 5315 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5316 | 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] | 5317 | { |
| 5318 | struct nfs4_label ilabel, *olabel = NULL; |
| 5319 | struct nfs_fattr fattr; |
| 5320 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5321 | int status; |
| 5322 | |
| 5323 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5324 | return -EOPNOTSUPP; |
| 5325 | |
| 5326 | nfs_fattr_init(&fattr); |
| 5327 | |
| 5328 | ilabel.pi = 0; |
| 5329 | ilabel.lfs = 0; |
| 5330 | ilabel.label = (char *)buf; |
| 5331 | ilabel.len = buflen; |
| 5332 | |
| 5333 | cred = rpc_lookup_cred(); |
| 5334 | if (IS_ERR(cred)) |
| 5335 | return PTR_ERR(cred); |
| 5336 | |
| 5337 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5338 | if (IS_ERR(olabel)) { |
| 5339 | status = -PTR_ERR(olabel); |
| 5340 | goto out; |
| 5341 | } |
| 5342 | |
| 5343 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5344 | if (status == 0) |
| 5345 | nfs_setsecurity(inode, &fattr, olabel); |
| 5346 | |
| 5347 | nfs4_label_free(olabel); |
| 5348 | out: |
| 5349 | put_rpccred(cred); |
| 5350 | return status; |
| 5351 | } |
| 5352 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5353 | |
| 5354 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5355 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5356 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5357 | { |
| 5358 | __be32 verf[2]; |
| 5359 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5360 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5361 | /* An impossible timestamp guarantees this value |
| 5362 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5363 | verf[0] = cpu_to_be32(U32_MAX); |
| 5364 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5365 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5366 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5367 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5368 | |
| 5369 | verf[0] = cpu_to_be32(ns >> 32); |
| 5370 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5371 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5372 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5373 | } |
| 5374 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5375 | static int |
| 5376 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5377 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5378 | size_t len; |
| 5379 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5380 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5381 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5382 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5383 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5384 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5385 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5386 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5387 | 1 + |
| 5388 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5389 | 1; |
| 5390 | rcu_read_unlock(); |
| 5391 | |
| 5392 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5393 | return -EINVAL; |
| 5394 | |
| 5395 | /* |
| 5396 | * Since this string is allocated at mount time, and held until the |
| 5397 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5398 | * about a memory-reclaim deadlock. |
| 5399 | */ |
| 5400 | str = kmalloc(len, GFP_KERNEL); |
| 5401 | if (!str) |
| 5402 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5403 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5404 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5405 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5406 | clp->cl_ipaddr, |
| 5407 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5408 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5409 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5410 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5411 | clp->cl_owner_id = str; |
| 5412 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5413 | } |
| 5414 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5415 | static int |
| 5416 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5417 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5418 | size_t len; |
| 5419 | char *str; |
| 5420 | |
| 5421 | len = 10 + 10 + 1 + 10 + 1 + |
| 5422 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5423 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5424 | |
| 5425 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5426 | return -EINVAL; |
| 5427 | |
| 5428 | /* |
| 5429 | * Since this string is allocated at mount time, and held until the |
| 5430 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5431 | * about a memory-reclaim deadlock. |
| 5432 | */ |
| 5433 | str = kmalloc(len, GFP_KERNEL); |
| 5434 | if (!str) |
| 5435 | return -ENOMEM; |
| 5436 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5437 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5438 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5439 | nfs4_client_id_uniquifier, |
| 5440 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5441 | clp->cl_owner_id = str; |
| 5442 | return 0; |
| 5443 | } |
| 5444 | |
| 5445 | static int |
| 5446 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5447 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5448 | size_t len; |
| 5449 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5450 | |
| 5451 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5452 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5453 | |
| 5454 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5455 | return nfs4_init_uniquifier_client_string(clp); |
| 5456 | |
| 5457 | len = 10 + 10 + 1 + 10 + 1 + |
| 5458 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5459 | |
| 5460 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5461 | return -EINVAL; |
| 5462 | |
| 5463 | /* |
| 5464 | * Since this string is allocated at mount time, and held until the |
| 5465 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5466 | * about a memory-reclaim deadlock. |
| 5467 | */ |
| 5468 | str = kmalloc(len, GFP_KERNEL); |
| 5469 | if (!str) |
| 5470 | return -ENOMEM; |
| 5471 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5472 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5473 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5474 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5475 | clp->cl_owner_id = str; |
| 5476 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5477 | } |
| 5478 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5479 | /* |
| 5480 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5481 | * services. Advertise one based on the address family of the |
| 5482 | * clientaddr. |
| 5483 | */ |
| 5484 | static unsigned int |
| 5485 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5486 | { |
| 5487 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5488 | return scnprintf(buf, len, "tcp6"); |
| 5489 | else |
| 5490 | return scnprintf(buf, len, "tcp"); |
| 5491 | } |
| 5492 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5493 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5494 | { |
| 5495 | struct nfs4_setclientid *sc = calldata; |
| 5496 | |
| 5497 | if (task->tk_status == 0) |
| 5498 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5499 | } |
| 5500 | |
| 5501 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5502 | .rpc_call_done = nfs4_setclientid_done, |
| 5503 | }; |
| 5504 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5505 | /** |
| 5506 | * nfs4_proc_setclientid - Negotiate client ID |
| 5507 | * @clp: state data structure |
| 5508 | * @program: RPC program for NFSv4 callback service |
| 5509 | * @port: IP port number for NFS4 callback service |
| 5510 | * @cred: RPC credential to use for this call |
| 5511 | * @res: where to place the result |
| 5512 | * |
| 5513 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5514 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5515 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5516 | unsigned short port, struct rpc_cred *cred, |
| 5517 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | { |
| 5519 | nfs4_verifier sc_verifier; |
| 5520 | struct nfs4_setclientid setclientid = { |
| 5521 | .sc_verifier = &sc_verifier, |
| 5522 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5523 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | }; |
| 5525 | struct rpc_message msg = { |
| 5526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5527 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5528 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5529 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5531 | struct rpc_task *task; |
| 5532 | struct rpc_task_setup task_setup_data = { |
| 5533 | .rpc_client = clp->cl_rpcclient, |
| 5534 | .rpc_message = &msg, |
| 5535 | .callback_ops = &nfs4_setclientid_ops, |
| 5536 | .callback_data = &setclientid, |
| 5537 | .flags = RPC_TASK_TIMEOUT, |
| 5538 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5539 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5541 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5542 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5543 | |
| 5544 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5545 | status = nfs4_init_uniform_client_string(clp); |
| 5546 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5547 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5548 | |
| 5549 | if (status) |
| 5550 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5551 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5552 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5553 | setclientid.sc_netid_len = |
| 5554 | nfs4_init_callback_netid(clp, |
| 5555 | setclientid.sc_netid, |
| 5556 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5557 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5558 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5560 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5561 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5562 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5563 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5564 | task = rpc_run_task(&task_setup_data); |
| 5565 | if (IS_ERR(task)) { |
| 5566 | status = PTR_ERR(task); |
| 5567 | goto out; |
| 5568 | } |
| 5569 | status = task->tk_status; |
| 5570 | if (setclientid.sc_cred) { |
| 5571 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5572 | put_rpccred(setclientid.sc_cred); |
| 5573 | } |
| 5574 | rpc_put_task(task); |
| 5575 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5576 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5577 | dprintk("NFS reply setclientid: %d\n", status); |
| 5578 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5579 | } |
| 5580 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5581 | /** |
| 5582 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5583 | * @clp: state data structure |
| 5584 | * @res: result of a previous SETCLIENTID |
| 5585 | * @cred: RPC credential to use for this call |
| 5586 | * |
| 5587 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5588 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5589 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5590 | struct nfs4_setclientid_res *arg, |
| 5591 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | struct rpc_message msg = { |
| 5594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5595 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5596 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | int status; |
| 5599 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5600 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5601 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5602 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5603 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5604 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5605 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | return status; |
| 5607 | } |
| 5608 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5609 | struct nfs4_delegreturndata { |
| 5610 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5611 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5612 | struct nfs_fh fh; |
| 5613 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5614 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5615 | struct { |
| 5616 | struct nfs4_layoutreturn_args arg; |
| 5617 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5618 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5619 | u32 roc_barrier; |
| 5620 | bool roc; |
| 5621 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5622 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5623 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5624 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5625 | }; |
| 5626 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5627 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5628 | { |
| 5629 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5630 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5631 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5632 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5633 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5634 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5635 | |
| 5636 | /* Handle Layoutreturn errors */ |
| 5637 | if (data->args.lr_args && task->tk_status != 0) { |
| 5638 | switch(data->res.lr_ret) { |
| 5639 | default: |
| 5640 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5641 | break; |
| 5642 | case 0: |
| 5643 | data->args.lr_args = NULL; |
| 5644 | data->res.lr_res = NULL; |
| 5645 | break; |
| 5646 | case -NFS4ERR_ADMIN_REVOKED: |
| 5647 | case -NFS4ERR_DELEG_REVOKED: |
| 5648 | case -NFS4ERR_EXPIRED: |
| 5649 | case -NFS4ERR_BAD_STATEID: |
| 5650 | case -NFS4ERR_OLD_STATEID: |
| 5651 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5652 | case -NFS4ERR_WRONG_CRED: |
| 5653 | data->args.lr_args = NULL; |
| 5654 | data->res.lr_res = NULL; |
| 5655 | data->res.lr_ret = 0; |
| 5656 | rpc_restart_call_prepare(task); |
| 5657 | return; |
| 5658 | } |
| 5659 | } |
| 5660 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5661 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5662 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5663 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5664 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5665 | case -NFS4ERR_ADMIN_REVOKED: |
| 5666 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5667 | case -NFS4ERR_EXPIRED: |
| 5668 | nfs4_free_revoked_stateid(data->res.server, |
| 5669 | data->args.stateid, |
| 5670 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5671 | case -NFS4ERR_BAD_STATEID: |
| 5672 | case -NFS4ERR_OLD_STATEID: |
| 5673 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5674 | task->tk_status = 0; |
| 5675 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5676 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5677 | if (nfs4_async_handle_error(task, data->res.server, |
| 5678 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5679 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5680 | return; |
| 5681 | } |
| 5682 | } |
| 5683 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | static void nfs4_delegreturn_release(void *calldata) |
| 5687 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5688 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5689 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5690 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5691 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5692 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5693 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5694 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5695 | nfs_iput_and_deactive(inode); |
| 5696 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5697 | kfree(calldata); |
| 5698 | } |
| 5699 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5700 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5701 | { |
| 5702 | struct nfs4_delegreturndata *d_data; |
| 5703 | |
| 5704 | d_data = (struct nfs4_delegreturndata *)data; |
| 5705 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5706 | if (!d_data->lr.roc && nfs4_wait_on_layoutreturn(d_data->inode, task)) |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5707 | return; |
| 5708 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5709 | nfs4_setup_sequence(d_data->res.server, |
| 5710 | &d_data->args.seq_args, |
| 5711 | &d_data->res.seq_res, |
| 5712 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5713 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5714 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5715 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5716 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5717 | .rpc_call_done = nfs4_delegreturn_done, |
| 5718 | .rpc_release = nfs4_delegreturn_release, |
| 5719 | }; |
| 5720 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5721 | 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] | 5722 | { |
| 5723 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5724 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5725 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5726 | struct rpc_message msg = { |
| 5727 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5728 | .rpc_cred = cred, |
| 5729 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5730 | struct rpc_task_setup task_setup_data = { |
| 5731 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5732 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5733 | .callback_ops = &nfs4_delegreturn_ops, |
| 5734 | .flags = RPC_TASK_ASYNC, |
| 5735 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5736 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5737 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5738 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5739 | if (data == NULL) |
| 5740 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5741 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5742 | |
| 5743 | nfs4_state_protect(server->nfs_client, |
| 5744 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5745 | &task_setup_data.rpc_client, &msg); |
| 5746 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5747 | data->args.fhandle = &data->fh; |
| 5748 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5749 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5750 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5751 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5752 | data->res.fattr = &data->fattr; |
| 5753 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5754 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5755 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5756 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5757 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5758 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5759 | data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, cred); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5760 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5761 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5762 | if (data->lr.roc) { |
| 5763 | data->args.lr_args = &data->lr.arg; |
| 5764 | data->res.lr_res = &data->lr.res; |
| 5765 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5766 | } else if (data->lr.roc) { |
| 5767 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5768 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5769 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5770 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5771 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5772 | msg.rpc_argp = &data->args; |
| 5773 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5774 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5775 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5776 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5777 | if (!issync) |
| 5778 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5779 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5780 | if (status != 0) |
| 5781 | goto out; |
| 5782 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5783 | if (status == 0) |
| 5784 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5785 | else |
| 5786 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5787 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5788 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5789 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5792 | 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] | 5793 | { |
| 5794 | struct nfs_server *server = NFS_SERVER(inode); |
| 5795 | struct nfs4_exception exception = { }; |
| 5796 | int err; |
| 5797 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5798 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5799 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | switch (err) { |
| 5801 | case -NFS4ERR_STALE_STATEID: |
| 5802 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | case 0: |
| 5804 | return 0; |
| 5805 | } |
| 5806 | err = nfs4_handle_exception(server, err, &exception); |
| 5807 | } while (exception.retry); |
| 5808 | return err; |
| 5809 | } |
| 5810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5811 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5812 | { |
| 5813 | struct inode *inode = state->inode; |
| 5814 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5815 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5816 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5818 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5820 | struct nfs_lockt_res res = { |
| 5821 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | }; |
| 5823 | struct rpc_message msg = { |
| 5824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5825 | .rpc_argp = &arg, |
| 5826 | .rpc_resp = &res, |
| 5827 | .rpc_cred = state->owner->so_cred, |
| 5828 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | struct nfs4_lock_state *lsp; |
| 5830 | int status; |
| 5831 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5832 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5833 | status = nfs4_set_lock_state(state, request); |
| 5834 | if (status != 0) |
| 5835 | goto out; |
| 5836 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5837 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5838 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5839 | 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] | 5840 | switch (status) { |
| 5841 | case 0: |
| 5842 | request->fl_type = F_UNLCK; |
| 5843 | break; |
| 5844 | case -NFS4ERR_DENIED: |
| 5845 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5847 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5848 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5849 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | return status; |
| 5851 | } |
| 5852 | |
| 5853 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5854 | { |
| 5855 | struct nfs4_exception exception = { }; |
| 5856 | int err; |
| 5857 | |
| 5858 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5859 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5860 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5861 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | &exception); |
| 5863 | } while (exception.retry); |
| 5864 | return err; |
| 5865 | } |
| 5866 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5867 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5868 | struct nfs_locku_args arg; |
| 5869 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5870 | struct nfs4_lock_state *lsp; |
| 5871 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5872 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5873 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5874 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5875 | }; |
| 5876 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5877 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5878 | struct nfs_open_context *ctx, |
| 5879 | struct nfs4_lock_state *lsp, |
| 5880 | struct nfs_seqid *seqid) |
| 5881 | { |
| 5882 | struct nfs4_unlockdata *p; |
| 5883 | struct inode *inode = lsp->ls_state->inode; |
| 5884 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5885 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5886 | if (p == NULL) |
| 5887 | return NULL; |
| 5888 | p->arg.fh = NFS_FH(inode); |
| 5889 | p->arg.fl = &p->fl; |
| 5890 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5891 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5892 | p->lsp = lsp; |
| 5893 | atomic_inc(&lsp->ls_count); |
| 5894 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5895 | p->ctx = get_nfs_open_context(ctx); |
| 5896 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5897 | p->server = NFS_SERVER(inode); |
| 5898 | return p; |
| 5899 | } |
| 5900 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5901 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5902 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5903 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5904 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5905 | nfs4_put_lock_state(calldata->lsp); |
| 5906 | put_nfs_open_context(calldata->ctx); |
| 5907 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5910 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5911 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5912 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5913 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5914 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5915 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5916 | switch (task->tk_status) { |
| 5917 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5918 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5919 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5920 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5921 | &calldata->res.stateid)) |
| 5922 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5923 | case -NFS4ERR_ADMIN_REVOKED: |
| 5924 | case -NFS4ERR_EXPIRED: |
| 5925 | nfs4_free_revoked_stateid(calldata->server, |
| 5926 | &calldata->arg.stateid, |
| 5927 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5928 | case -NFS4ERR_BAD_STATEID: |
| 5929 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5930 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5931 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5932 | &calldata->lsp->ls_stateid)) |
| 5933 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5934 | break; |
| 5935 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5936 | if (nfs4_async_handle_error(task, calldata->server, |
| 5937 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5938 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5939 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5940 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5943 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5944 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5945 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5947 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5948 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5949 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5950 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5951 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5952 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5953 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5954 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5955 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5956 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5957 | &calldata->res.seq_res, |
| 5958 | task) != 0) |
| 5959 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5960 | return; |
| 5961 | out_no_action: |
| 5962 | task->tk_action = NULL; |
| 5963 | out_wait: |
| 5964 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5967 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5968 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5969 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5970 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5971 | }; |
| 5972 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5973 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5974 | struct nfs_open_context *ctx, |
| 5975 | struct nfs4_lock_state *lsp, |
| 5976 | struct nfs_seqid *seqid) |
| 5977 | { |
| 5978 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5979 | struct rpc_message msg = { |
| 5980 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5981 | .rpc_cred = ctx->cred, |
| 5982 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5983 | struct rpc_task_setup task_setup_data = { |
| 5984 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5985 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5986 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5987 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5988 | .flags = RPC_TASK_ASYNC, |
| 5989 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5990 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5991 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5992 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5993 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5994 | /* Ensure this is an unlock - when canceling a lock, the |
| 5995 | * canceled lock is passed in, and it won't be an unlock. |
| 5996 | */ |
| 5997 | fl->fl_type = F_UNLCK; |
| 5998 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5999 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6000 | if (data == NULL) { |
| 6001 | nfs_free_seqid(seqid); |
| 6002 | return ERR_PTR(-ENOMEM); |
| 6003 | } |
| 6004 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6005 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6006 | msg.rpc_argp = &data->arg; |
| 6007 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6008 | task_setup_data.callback_data = data; |
| 6009 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6010 | } |
| 6011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6013 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6014 | struct inode *inode = state->inode; |
| 6015 | struct nfs4_state_owner *sp = state->owner; |
| 6016 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6017 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6018 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6019 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6020 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6021 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6022 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6024 | status = nfs4_set_lock_state(state, request); |
| 6025 | /* Unlock _before_ we do the RPC call */ |
| 6026 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6027 | /* Exclude nfs_delegation_claim_locks() */ |
| 6028 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6029 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6030 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6031 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6032 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6033 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6034 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6035 | } |
| 6036 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6037 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6038 | if (status != 0) |
| 6039 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6040 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6041 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6042 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6043 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6044 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6045 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6046 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6047 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6048 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6049 | 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] | 6050 | status = PTR_ERR(task); |
| 6051 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6052 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6053 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6054 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6055 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6056 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6057 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6058 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6061 | struct nfs4_lockdata { |
| 6062 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6063 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6064 | struct nfs4_lock_state *lsp; |
| 6065 | struct nfs_open_context *ctx; |
| 6066 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6067 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6068 | int rpc_status; |
| 6069 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6070 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6071 | }; |
| 6072 | |
| 6073 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6074 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6075 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6076 | { |
| 6077 | struct nfs4_lockdata *p; |
| 6078 | struct inode *inode = lsp->ls_state->inode; |
| 6079 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6080 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6081 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6082 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6083 | if (p == NULL) |
| 6084 | return NULL; |
| 6085 | |
| 6086 | p->arg.fh = NFS_FH(inode); |
| 6087 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6088 | 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] | 6089 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6090 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6091 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6092 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6093 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6094 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6095 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6096 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6097 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6098 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6099 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6100 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6101 | atomic_inc(&lsp->ls_count); |
| 6102 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6103 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6104 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6105 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6106 | out_free_seqid: |
| 6107 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6108 | out_free: |
| 6109 | kfree(p); |
| 6110 | return NULL; |
| 6111 | } |
| 6112 | |
| 6113 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6114 | { |
| 6115 | struct nfs4_lockdata *data = calldata; |
| 6116 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6118 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6119 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6120 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6121 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6122 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6123 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6124 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6125 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6126 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6127 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6128 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6129 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6130 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6131 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6132 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6133 | &data->lsp->ls_stateid); |
| 6134 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6135 | if (!nfs4_valid_open_stateid(state)) { |
| 6136 | data->rpc_status = -EBADF; |
| 6137 | task->tk_action = NULL; |
| 6138 | goto out_release_open_seqid; |
| 6139 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6140 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6141 | if (nfs4_setup_sequence(data->server, |
| 6142 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6143 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6144 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6145 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6146 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6147 | nfs_release_seqid(data->arg.open_seqid); |
| 6148 | out_release_lock_seqid: |
| 6149 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6150 | out_wait: |
| 6151 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6152 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6153 | } |
| 6154 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6155 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6156 | { |
| 6157 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6158 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6159 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6160 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6161 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6162 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6163 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6164 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6165 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6166 | switch (task->tk_status) { |
| 6167 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6168 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6169 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6170 | if (data->arg.new_lock) { |
| 6171 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6172 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6173 | rpc_restart_call_prepare(task); |
| 6174 | break; |
| 6175 | } |
| 6176 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6177 | if (data->arg.new_lock_owner != 0) { |
| 6178 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6179 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6180 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6181 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6182 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6183 | break; |
| 6184 | case -NFS4ERR_BAD_STATEID: |
| 6185 | case -NFS4ERR_OLD_STATEID: |
| 6186 | case -NFS4ERR_STALE_STATEID: |
| 6187 | case -NFS4ERR_EXPIRED: |
| 6188 | if (data->arg.new_lock_owner != 0) { |
| 6189 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6190 | &lsp->ls_state->open_stateid)) |
| 6191 | rpc_restart_call_prepare(task); |
| 6192 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6193 | &lsp->ls_stateid)) |
| 6194 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6195 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6196 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | static void nfs4_lock_release(void *calldata) |
| 6200 | { |
| 6201 | struct nfs4_lockdata *data = calldata; |
| 6202 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6203 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6204 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6205 | if (data->cancelled != 0) { |
| 6206 | struct rpc_task *task; |
| 6207 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6208 | data->arg.lock_seqid); |
| 6209 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6210 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6211 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6212 | } else |
| 6213 | nfs_free_seqid(data->arg.lock_seqid); |
| 6214 | nfs4_put_lock_state(data->lsp); |
| 6215 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6216 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6217 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6218 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6222 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6223 | .rpc_call_done = nfs4_lock_done, |
| 6224 | .rpc_release = nfs4_lock_release, |
| 6225 | }; |
| 6226 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6227 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6228 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6229 | switch (error) { |
| 6230 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6231 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6232 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6233 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6234 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6235 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6236 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6237 | break; |
| 6238 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6239 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6240 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6241 | }; |
| 6242 | } |
| 6243 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6244 | 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] | 6245 | { |
| 6246 | struct nfs4_lockdata *data; |
| 6247 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6248 | struct rpc_message msg = { |
| 6249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6250 | .rpc_cred = state->owner->so_cred, |
| 6251 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6252 | struct rpc_task_setup task_setup_data = { |
| 6253 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6254 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6255 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6256 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6257 | .flags = RPC_TASK_ASYNC, |
| 6258 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6259 | int ret; |
| 6260 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6261 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6262 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6263 | fl->fl_u.nfs4_fl.owner, |
| 6264 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6265 | if (data == NULL) |
| 6266 | return -ENOMEM; |
| 6267 | if (IS_SETLKW(cmd)) |
| 6268 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6269 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6270 | msg.rpc_argp = &data->arg; |
| 6271 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6272 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6273 | if (recovery_type > NFS_LOCK_NEW) { |
| 6274 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6275 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6276 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6277 | } else |
| 6278 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6279 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6280 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6281 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6282 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6283 | if (ret == 0) { |
| 6284 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6285 | if (ret) |
| 6286 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6287 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6288 | } else |
| 6289 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6290 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6291 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6292 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6293 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6297 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6298 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6299 | struct nfs4_exception exception = { |
| 6300 | .inode = state->inode, |
| 6301 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6302 | int err; |
| 6303 | |
| 6304 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6305 | /* Cache the lock if possible... */ |
| 6306 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6307 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6308 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6309 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6310 | break; |
| 6311 | nfs4_handle_exception(server, err, &exception); |
| 6312 | } while (exception.retry); |
| 6313 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | } |
| 6315 | |
| 6316 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6317 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6318 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6319 | struct nfs4_exception exception = { |
| 6320 | .inode = state->inode, |
| 6321 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6322 | int err; |
| 6323 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6324 | err = nfs4_set_lock_state(state, request); |
| 6325 | if (err != 0) |
| 6326 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6327 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6328 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6329 | return 0; |
| 6330 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6331 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6332 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6333 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6334 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6335 | switch (err) { |
| 6336 | default: |
| 6337 | goto out; |
| 6338 | case -NFS4ERR_GRACE: |
| 6339 | case -NFS4ERR_DELAY: |
| 6340 | nfs4_handle_exception(server, err, &exception); |
| 6341 | err = 0; |
| 6342 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6343 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6344 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6345 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | } |
| 6347 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6348 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6349 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6350 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6351 | struct nfs4_lock_state *lsp; |
| 6352 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6353 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6354 | status = nfs4_set_lock_state(state, request); |
| 6355 | if (status != 0) |
| 6356 | return status; |
| 6357 | lsp = request->fl_u.nfs4_fl.owner; |
| 6358 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6359 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6360 | return 0; |
| 6361 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6362 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6363 | } |
| 6364 | #endif |
| 6365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6367 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6368 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6369 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6370 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6371 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6373 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6374 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6375 | if (status < 0) |
| 6376 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6377 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6378 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6379 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6380 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6381 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6382 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6383 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6384 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6385 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6386 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6387 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6388 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6389 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6390 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6391 | out: |
| 6392 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6393 | return status; |
| 6394 | } |
| 6395 | |
| 6396 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6397 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6398 | struct nfs4_exception exception = { |
| 6399 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6400 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6401 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6402 | int err; |
| 6403 | |
| 6404 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6405 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6406 | if (err == -NFS4ERR_DENIED) |
| 6407 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6409 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6410 | } while (exception.retry); |
| 6411 | return err; |
| 6412 | } |
| 6413 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6414 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6415 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6416 | |
| 6417 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6418 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6419 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6420 | { |
| 6421 | int status = -ERESTARTSYS; |
| 6422 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6423 | |
| 6424 | while(!signalled()) { |
| 6425 | status = nfs4_proc_setlk(state, cmd, request); |
| 6426 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6427 | break; |
| 6428 | freezable_schedule_timeout_interruptible(timeout); |
| 6429 | timeout *= 2; |
| 6430 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6431 | status = -ERESTARTSYS; |
| 6432 | } |
| 6433 | return status; |
| 6434 | } |
| 6435 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6436 | #ifdef CONFIG_NFS_V4_1 |
| 6437 | struct nfs4_lock_waiter { |
| 6438 | struct task_struct *task; |
| 6439 | struct inode *inode; |
| 6440 | struct nfs_lowner *owner; |
| 6441 | bool notified; |
| 6442 | }; |
| 6443 | |
| 6444 | static int |
| 6445 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6446 | { |
| 6447 | int ret; |
| 6448 | struct cb_notify_lock_args *cbnl = key; |
| 6449 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6450 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6451 | *wowner = waiter->owner; |
| 6452 | |
| 6453 | /* Only wake if the callback was for the same owner */ |
| 6454 | if (lowner->clientid != wowner->clientid || |
| 6455 | lowner->id != wowner->id || |
| 6456 | lowner->s_dev != wowner->s_dev) |
| 6457 | return 0; |
| 6458 | |
| 6459 | /* Make sure it's for the right inode */ |
| 6460 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6461 | return 0; |
| 6462 | |
| 6463 | waiter->notified = true; |
| 6464 | |
| 6465 | /* override "private" so we can use default_wake_function */ |
| 6466 | wait->private = waiter->task; |
| 6467 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6468 | wait->private = waiter; |
| 6469 | return ret; |
| 6470 | } |
| 6471 | |
| 6472 | static int |
| 6473 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6474 | { |
| 6475 | int status = -ERESTARTSYS; |
| 6476 | unsigned long flags; |
| 6477 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6478 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6479 | struct nfs_client *clp = server->nfs_client; |
| 6480 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6481 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6482 | .id = lsp->ls_seqid.owner_id, |
| 6483 | .s_dev = server->s_dev }; |
| 6484 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6485 | .inode = state->inode, |
| 6486 | .owner = &owner, |
| 6487 | .notified = false }; |
| 6488 | wait_queue_t wait; |
| 6489 | |
| 6490 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6491 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6492 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6493 | |
| 6494 | init_wait(&wait); |
| 6495 | wait.private = &waiter; |
| 6496 | wait.func = nfs4_wake_lock_waiter; |
| 6497 | add_wait_queue(q, &wait); |
| 6498 | |
| 6499 | while(!signalled()) { |
| 6500 | status = nfs4_proc_setlk(state, cmd, request); |
| 6501 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6502 | break; |
| 6503 | |
| 6504 | status = -ERESTARTSYS; |
| 6505 | spin_lock_irqsave(&q->lock, flags); |
| 6506 | if (waiter.notified) { |
| 6507 | spin_unlock_irqrestore(&q->lock, flags); |
| 6508 | continue; |
| 6509 | } |
| 6510 | set_current_state(TASK_INTERRUPTIBLE); |
| 6511 | spin_unlock_irqrestore(&q->lock, flags); |
| 6512 | |
| 6513 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6514 | } |
| 6515 | |
| 6516 | finish_wait(q, &wait); |
| 6517 | return status; |
| 6518 | } |
| 6519 | #else /* !CONFIG_NFS_V4_1 */ |
| 6520 | static inline int |
| 6521 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6522 | { |
| 6523 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6524 | } |
| 6525 | #endif |
| 6526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6527 | static int |
| 6528 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6529 | { |
| 6530 | struct nfs_open_context *ctx; |
| 6531 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6532 | int status; |
| 6533 | |
| 6534 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6535 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | state = ctx->state; |
| 6537 | |
| 6538 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6539 | return -EINVAL; |
| 6540 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6541 | if (IS_GETLK(cmd)) { |
| 6542 | if (state != NULL) |
| 6543 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6544 | return 0; |
| 6545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6546 | |
| 6547 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6548 | return -EINVAL; |
| 6549 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6550 | if (request->fl_type == F_UNLCK) { |
| 6551 | if (state != NULL) |
| 6552 | return nfs4_proc_unlck(state, cmd, request); |
| 6553 | return 0; |
| 6554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6555 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6556 | if (state == NULL) |
| 6557 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6558 | |
| 6559 | if ((request->fl_flags & FL_POSIX) && |
| 6560 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6561 | return -ENOLCK; |
| 6562 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6563 | /* |
| 6564 | * Don't rely on the VFS having checked the file open mode, |
| 6565 | * since it won't do this for flock() locks. |
| 6566 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6567 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6568 | case F_RDLCK: |
| 6569 | if (!(filp->f_mode & FMODE_READ)) |
| 6570 | return -EBADF; |
| 6571 | break; |
| 6572 | case F_WRLCK: |
| 6573 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6574 | return -EBADF; |
| 6575 | } |
| 6576 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6577 | status = nfs4_set_lock_state(state, request); |
| 6578 | if (status != 0) |
| 6579 | return status; |
| 6580 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6581 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | } |
| 6583 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6584 | 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] | 6585 | { |
| 6586 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6587 | int err; |
| 6588 | |
| 6589 | err = nfs4_set_lock_state(state, fl); |
| 6590 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6591 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6592 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6593 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6594 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6595 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6596 | struct nfs_release_lockowner_data { |
| 6597 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6598 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6599 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6600 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6601 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6602 | }; |
| 6603 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6604 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6605 | { |
| 6606 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6607 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6608 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6609 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6610 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6611 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6615 | { |
| 6616 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6617 | struct nfs_server *server = data->server; |
| 6618 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6619 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6620 | |
| 6621 | switch (task->tk_status) { |
| 6622 | case 0: |
| 6623 | renew_lease(server, data->timestamp); |
| 6624 | break; |
| 6625 | case -NFS4ERR_STALE_CLIENTID: |
| 6626 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6627 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6628 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6629 | case -NFS4ERR_LEASE_MOVED: |
| 6630 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6631 | if (nfs4_async_handle_error(task, server, |
| 6632 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6633 | rpc_restart_call_prepare(task); |
| 6634 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6635 | } |
| 6636 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6637 | static void nfs4_release_lockowner_release(void *calldata) |
| 6638 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6639 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6640 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6641 | kfree(calldata); |
| 6642 | } |
| 6643 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6644 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6645 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6646 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6647 | .rpc_release = nfs4_release_lockowner_release, |
| 6648 | }; |
| 6649 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6650 | static void |
| 6651 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6652 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6653 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6654 | struct rpc_message msg = { |
| 6655 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6656 | }; |
| 6657 | |
| 6658 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6659 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6660 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6661 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6662 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6663 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6664 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6665 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6666 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6667 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6668 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6669 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6670 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6671 | msg.rpc_resp = &data->res; |
| 6672 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6673 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6674 | } |
| 6675 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6676 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6677 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6678 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6679 | struct dentry *unused, struct inode *inode, |
| 6680 | const char *key, const void *buf, |
| 6681 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6682 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6683 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6684 | } |
| 6685 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6686 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6687 | struct dentry *unused, struct inode *inode, |
| 6688 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6689 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6690 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6691 | } |
| 6692 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6693 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6694 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6695 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6696 | } |
| 6697 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6698 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6699 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6700 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6701 | struct dentry *unused, struct inode *inode, |
| 6702 | const char *key, const void *buf, |
| 6703 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6704 | { |
| 6705 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6706 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6707 | |
| 6708 | return -EOPNOTSUPP; |
| 6709 | } |
| 6710 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6711 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6712 | struct dentry *unused, struct inode *inode, |
| 6713 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6714 | { |
| 6715 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6716 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6717 | return -EOPNOTSUPP; |
| 6718 | } |
| 6719 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6720 | static ssize_t |
| 6721 | 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] | 6722 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6723 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6724 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6725 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6726 | len = security_inode_listsecurity(inode, list, list_len); |
| 6727 | if (list_len && len > list_len) |
| 6728 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6729 | } |
| 6730 | return len; |
| 6731 | } |
| 6732 | |
| 6733 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6734 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6735 | .get = nfs4_xattr_get_nfs4_label, |
| 6736 | .set = nfs4_xattr_set_nfs4_label, |
| 6737 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6738 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6739 | #else |
| 6740 | |
| 6741 | static ssize_t |
| 6742 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6743 | { |
| 6744 | return 0; |
| 6745 | } |
| 6746 | |
| 6747 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6748 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6749 | /* |
| 6750 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6751 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6752 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6753 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6754 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6755 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6756 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6757 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6758 | return; |
| 6759 | |
| 6760 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6761 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6762 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6763 | fattr->nlink = 2; |
| 6764 | } |
| 6765 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6766 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6767 | const struct qstr *name, |
| 6768 | struct nfs4_fs_locations *fs_locations, |
| 6769 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6770 | { |
| 6771 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6772 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6773 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6774 | }; |
| 6775 | struct nfs4_fs_locations_arg args = { |
| 6776 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6777 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6778 | .page = page, |
| 6779 | .bitmask = bitmask, |
| 6780 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6781 | struct nfs4_fs_locations_res res = { |
| 6782 | .fs_locations = fs_locations, |
| 6783 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6784 | struct rpc_message msg = { |
| 6785 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6786 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6787 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6788 | }; |
| 6789 | int status; |
| 6790 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6791 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6792 | |
| 6793 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6794 | * is not supported */ |
| 6795 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6796 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6797 | else |
| 6798 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6799 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6800 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6801 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6802 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6803 | 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] | 6804 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6805 | return status; |
| 6806 | } |
| 6807 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6808 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6809 | const struct qstr *name, |
| 6810 | struct nfs4_fs_locations *fs_locations, |
| 6811 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6812 | { |
| 6813 | struct nfs4_exception exception = { }; |
| 6814 | int err; |
| 6815 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6816 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6817 | fs_locations, page); |
| 6818 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6819 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6820 | &exception); |
| 6821 | } while (exception.retry); |
| 6822 | return err; |
| 6823 | } |
| 6824 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6825 | /* |
| 6826 | * This operation also signals the server that this client is |
| 6827 | * performing migration recovery. The server can stop returning |
| 6828 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6829 | * appended to this compound to identify the client ID which is |
| 6830 | * performing recovery. |
| 6831 | */ |
| 6832 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6833 | struct nfs4_fs_locations *locations, |
| 6834 | struct page *page, struct rpc_cred *cred) |
| 6835 | { |
| 6836 | struct nfs_server *server = NFS_SERVER(inode); |
| 6837 | struct rpc_clnt *clnt = server->client; |
| 6838 | u32 bitmask[2] = { |
| 6839 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6840 | }; |
| 6841 | struct nfs4_fs_locations_arg args = { |
| 6842 | .clientid = server->nfs_client->cl_clientid, |
| 6843 | .fh = NFS_FH(inode), |
| 6844 | .page = page, |
| 6845 | .bitmask = bitmask, |
| 6846 | .migration = 1, /* skip LOOKUP */ |
| 6847 | .renew = 1, /* append RENEW */ |
| 6848 | }; |
| 6849 | struct nfs4_fs_locations_res res = { |
| 6850 | .fs_locations = locations, |
| 6851 | .migration = 1, |
| 6852 | .renew = 1, |
| 6853 | }; |
| 6854 | struct rpc_message msg = { |
| 6855 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6856 | .rpc_argp = &args, |
| 6857 | .rpc_resp = &res, |
| 6858 | .rpc_cred = cred, |
| 6859 | }; |
| 6860 | unsigned long now = jiffies; |
| 6861 | int status; |
| 6862 | |
| 6863 | nfs_fattr_init(&locations->fattr); |
| 6864 | locations->server = server; |
| 6865 | locations->nlocations = 0; |
| 6866 | |
| 6867 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6868 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6869 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6870 | &args.seq_args, &res.seq_res); |
| 6871 | if (status) |
| 6872 | return status; |
| 6873 | |
| 6874 | renew_lease(server, now); |
| 6875 | return 0; |
| 6876 | } |
| 6877 | |
| 6878 | #ifdef CONFIG_NFS_V4_1 |
| 6879 | |
| 6880 | /* |
| 6881 | * This operation also signals the server that this client is |
| 6882 | * performing migration recovery. The server can stop asserting |
| 6883 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6884 | * performing this operation is identified in the SEQUENCE |
| 6885 | * operation in this compound. |
| 6886 | * |
| 6887 | * When the client supports GETATTR(fs_locations_info), it can |
| 6888 | * be plumbed in here. |
| 6889 | */ |
| 6890 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6891 | struct nfs4_fs_locations *locations, |
| 6892 | struct page *page, struct rpc_cred *cred) |
| 6893 | { |
| 6894 | struct nfs_server *server = NFS_SERVER(inode); |
| 6895 | struct rpc_clnt *clnt = server->client; |
| 6896 | u32 bitmask[2] = { |
| 6897 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6898 | }; |
| 6899 | struct nfs4_fs_locations_arg args = { |
| 6900 | .fh = NFS_FH(inode), |
| 6901 | .page = page, |
| 6902 | .bitmask = bitmask, |
| 6903 | .migration = 1, /* skip LOOKUP */ |
| 6904 | }; |
| 6905 | struct nfs4_fs_locations_res res = { |
| 6906 | .fs_locations = locations, |
| 6907 | .migration = 1, |
| 6908 | }; |
| 6909 | struct rpc_message msg = { |
| 6910 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6911 | .rpc_argp = &args, |
| 6912 | .rpc_resp = &res, |
| 6913 | .rpc_cred = cred, |
| 6914 | }; |
| 6915 | int status; |
| 6916 | |
| 6917 | nfs_fattr_init(&locations->fattr); |
| 6918 | locations->server = server; |
| 6919 | locations->nlocations = 0; |
| 6920 | |
| 6921 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6922 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6923 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6924 | &args.seq_args, &res.seq_res); |
| 6925 | if (status == NFS4_OK && |
| 6926 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6927 | status = -NFS4ERR_LEASE_MOVED; |
| 6928 | return status; |
| 6929 | } |
| 6930 | |
| 6931 | #endif /* CONFIG_NFS_V4_1 */ |
| 6932 | |
| 6933 | /** |
| 6934 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6935 | * @inode: inode on FSID that is migrating |
| 6936 | * @locations: result of query |
| 6937 | * @page: buffer |
| 6938 | * @cred: credential to use for this operation |
| 6939 | * |
| 6940 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6941 | * operation failed, or a negative errno if a local error occurred. |
| 6942 | * |
| 6943 | * On success, "locations" is filled in, but if the server has |
| 6944 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6945 | * asserted. |
| 6946 | * |
| 6947 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6948 | * from this client that require migration recovery. |
| 6949 | */ |
| 6950 | int nfs4_proc_get_locations(struct inode *inode, |
| 6951 | struct nfs4_fs_locations *locations, |
| 6952 | struct page *page, struct rpc_cred *cred) |
| 6953 | { |
| 6954 | struct nfs_server *server = NFS_SERVER(inode); |
| 6955 | struct nfs_client *clp = server->nfs_client; |
| 6956 | const struct nfs4_mig_recovery_ops *ops = |
| 6957 | clp->cl_mvops->mig_recovery_ops; |
| 6958 | struct nfs4_exception exception = { }; |
| 6959 | int status; |
| 6960 | |
| 6961 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6962 | (unsigned long long)server->fsid.major, |
| 6963 | (unsigned long long)server->fsid.minor, |
| 6964 | clp->cl_hostname); |
| 6965 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6966 | |
| 6967 | do { |
| 6968 | status = ops->get_locations(inode, locations, page, cred); |
| 6969 | if (status != -NFS4ERR_DELAY) |
| 6970 | break; |
| 6971 | nfs4_handle_exception(server, status, &exception); |
| 6972 | } while (exception.retry); |
| 6973 | return status; |
| 6974 | } |
| 6975 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6976 | /* |
| 6977 | * This operation also signals the server that this client is |
| 6978 | * performing "lease moved" recovery. The server can stop |
| 6979 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6980 | * is appended to this compound to identify the client ID which is |
| 6981 | * performing recovery. |
| 6982 | */ |
| 6983 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6984 | { |
| 6985 | struct nfs_server *server = NFS_SERVER(inode); |
| 6986 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6987 | struct rpc_clnt *clnt = server->client; |
| 6988 | struct nfs4_fsid_present_arg args = { |
| 6989 | .fh = NFS_FH(inode), |
| 6990 | .clientid = clp->cl_clientid, |
| 6991 | .renew = 1, /* append RENEW */ |
| 6992 | }; |
| 6993 | struct nfs4_fsid_present_res res = { |
| 6994 | .renew = 1, |
| 6995 | }; |
| 6996 | struct rpc_message msg = { |
| 6997 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6998 | .rpc_argp = &args, |
| 6999 | .rpc_resp = &res, |
| 7000 | .rpc_cred = cred, |
| 7001 | }; |
| 7002 | unsigned long now = jiffies; |
| 7003 | int status; |
| 7004 | |
| 7005 | res.fh = nfs_alloc_fhandle(); |
| 7006 | if (res.fh == NULL) |
| 7007 | return -ENOMEM; |
| 7008 | |
| 7009 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7010 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7011 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7012 | &args.seq_args, &res.seq_res); |
| 7013 | nfs_free_fhandle(res.fh); |
| 7014 | if (status) |
| 7015 | return status; |
| 7016 | |
| 7017 | do_renew_lease(clp, now); |
| 7018 | return 0; |
| 7019 | } |
| 7020 | |
| 7021 | #ifdef CONFIG_NFS_V4_1 |
| 7022 | |
| 7023 | /* |
| 7024 | * This operation also signals the server that this client is |
| 7025 | * performing "lease moved" recovery. The server can stop asserting |
| 7026 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7027 | * this operation is identified in the SEQUENCE operation in this |
| 7028 | * compound. |
| 7029 | */ |
| 7030 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7031 | { |
| 7032 | struct nfs_server *server = NFS_SERVER(inode); |
| 7033 | struct rpc_clnt *clnt = server->client; |
| 7034 | struct nfs4_fsid_present_arg args = { |
| 7035 | .fh = NFS_FH(inode), |
| 7036 | }; |
| 7037 | struct nfs4_fsid_present_res res = { |
| 7038 | }; |
| 7039 | struct rpc_message msg = { |
| 7040 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7041 | .rpc_argp = &args, |
| 7042 | .rpc_resp = &res, |
| 7043 | .rpc_cred = cred, |
| 7044 | }; |
| 7045 | int status; |
| 7046 | |
| 7047 | res.fh = nfs_alloc_fhandle(); |
| 7048 | if (res.fh == NULL) |
| 7049 | return -ENOMEM; |
| 7050 | |
| 7051 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7052 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7053 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7054 | &args.seq_args, &res.seq_res); |
| 7055 | nfs_free_fhandle(res.fh); |
| 7056 | if (status == NFS4_OK && |
| 7057 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7058 | status = -NFS4ERR_LEASE_MOVED; |
| 7059 | return status; |
| 7060 | } |
| 7061 | |
| 7062 | #endif /* CONFIG_NFS_V4_1 */ |
| 7063 | |
| 7064 | /** |
| 7065 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7066 | * @inode: inode on FSID to check |
| 7067 | * @cred: credential to use for this operation |
| 7068 | * |
| 7069 | * Server indicates whether the FSID is present, moved, or not |
| 7070 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7071 | * condition for this client ID. |
| 7072 | * |
| 7073 | * Returns NFS4_OK if the FSID is present on this server, |
| 7074 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7075 | * NFS4ERR code if some error occurred on the server, or a |
| 7076 | * negative errno if a local failure occurred. |
| 7077 | */ |
| 7078 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7079 | { |
| 7080 | struct nfs_server *server = NFS_SERVER(inode); |
| 7081 | struct nfs_client *clp = server->nfs_client; |
| 7082 | const struct nfs4_mig_recovery_ops *ops = |
| 7083 | clp->cl_mvops->mig_recovery_ops; |
| 7084 | struct nfs4_exception exception = { }; |
| 7085 | int status; |
| 7086 | |
| 7087 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7088 | (unsigned long long)server->fsid.major, |
| 7089 | (unsigned long long)server->fsid.minor, |
| 7090 | clp->cl_hostname); |
| 7091 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7092 | |
| 7093 | do { |
| 7094 | status = ops->fsid_present(inode, cred); |
| 7095 | if (status != -NFS4ERR_DELAY) |
| 7096 | break; |
| 7097 | nfs4_handle_exception(server, status, &exception); |
| 7098 | } while (exception.retry); |
| 7099 | return status; |
| 7100 | } |
| 7101 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7102 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7103 | * If 'use_integrity' is true and the state managment nfs_client |
| 7104 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7105 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7106 | * Considerations sections. Otherwise, just use the user cred with the |
| 7107 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7108 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7109 | 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] | 7110 | { |
| 7111 | int status; |
| 7112 | struct nfs4_secinfo_arg args = { |
| 7113 | .dir_fh = NFS_FH(dir), |
| 7114 | .name = name, |
| 7115 | }; |
| 7116 | struct nfs4_secinfo_res res = { |
| 7117 | .flavors = flavors, |
| 7118 | }; |
| 7119 | struct rpc_message msg = { |
| 7120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7121 | .rpc_argp = &args, |
| 7122 | .rpc_resp = &res, |
| 7123 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7124 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7125 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7126 | |
| 7127 | if (use_integrity) { |
| 7128 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7129 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7130 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7131 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7132 | |
| 7133 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7134 | |
| 7135 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7136 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7137 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7138 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7139 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7140 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7141 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7142 | if (cred) |
| 7143 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7144 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7145 | return status; |
| 7146 | } |
| 7147 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7148 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7149 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7150 | { |
| 7151 | struct nfs4_exception exception = { }; |
| 7152 | int err; |
| 7153 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7154 | err = -NFS4ERR_WRONGSEC; |
| 7155 | |
| 7156 | /* try to use integrity protection with machine cred */ |
| 7157 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7158 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7159 | |
| 7160 | /* |
| 7161 | * if unable to use integrity protection, or SECINFO with |
| 7162 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7163 | * disallowed by spec, but exists in deployed servers) use |
| 7164 | * the current filesystem's rpc_client and the user cred. |
| 7165 | */ |
| 7166 | if (err == -NFS4ERR_WRONGSEC) |
| 7167 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7168 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7169 | trace_nfs4_secinfo(dir, name, err); |
| 7170 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7171 | &exception); |
| 7172 | } while (exception.retry); |
| 7173 | return err; |
| 7174 | } |
| 7175 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7176 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7177 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7178 | * Check the exchange flags returned by the server for invalid flags, having |
| 7179 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7180 | * DS flags set. |
| 7181 | */ |
| 7182 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7183 | { |
| 7184 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7185 | goto out_inval; |
| 7186 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7187 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7188 | goto out_inval; |
| 7189 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7190 | goto out_inval; |
| 7191 | return NFS_OK; |
| 7192 | out_inval: |
| 7193 | return -NFS4ERR_INVAL; |
| 7194 | } |
| 7195 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7196 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7197 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7198 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7199 | { |
| 7200 | if (a->server_scope_sz == b->server_scope_sz && |
| 7201 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7202 | return true; |
| 7203 | |
| 7204 | return false; |
| 7205 | } |
| 7206 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7207 | static void |
| 7208 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7209 | { |
| 7210 | } |
| 7211 | |
| 7212 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7213 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7214 | }; |
| 7215 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7216 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7217 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7218 | * |
| 7219 | * The 4.1 client currently uses the same TCP connection for the |
| 7220 | * fore and backchannel. |
| 7221 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7222 | static |
| 7223 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7224 | struct rpc_xprt *xprt, |
| 7225 | struct nfs_client *clp, |
| 7226 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7227 | { |
| 7228 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7229 | struct nfs41_bind_conn_to_session_args args = { |
| 7230 | .client = clp, |
| 7231 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7232 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7233 | struct nfs41_bind_conn_to_session_res res; |
| 7234 | struct rpc_message msg = { |
| 7235 | .rpc_proc = |
| 7236 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7237 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7238 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7239 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7240 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7241 | struct rpc_task_setup task_setup_data = { |
| 7242 | .rpc_client = clnt, |
| 7243 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7244 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7245 | .rpc_message = &msg, |
| 7246 | .flags = RPC_TASK_TIMEOUT, |
| 7247 | }; |
| 7248 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7249 | |
| 7250 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7251 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7252 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7253 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7254 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7255 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7256 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7257 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7258 | args.dir = NFS4_CDFC4_FORE; |
| 7259 | |
| 7260 | task = rpc_run_task(&task_setup_data); |
| 7261 | if (!IS_ERR(task)) { |
| 7262 | status = task->tk_status; |
| 7263 | rpc_put_task(task); |
| 7264 | } else |
| 7265 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7266 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7268 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7269 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7270 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7271 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7272 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7273 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7274 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7275 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7276 | __func__); |
| 7277 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7278 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7279 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7280 | 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] | 7281 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7282 | __func__); |
| 7283 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7284 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7285 | } |
| 7286 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7287 | out: |
| 7288 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7289 | return status; |
| 7290 | } |
| 7291 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7292 | struct rpc_bind_conn_calldata { |
| 7293 | struct nfs_client *clp; |
| 7294 | struct rpc_cred *cred; |
| 7295 | }; |
| 7296 | |
| 7297 | static int |
| 7298 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7299 | struct rpc_xprt *xprt, |
| 7300 | void *calldata) |
| 7301 | { |
| 7302 | struct rpc_bind_conn_calldata *p = calldata; |
| 7303 | |
| 7304 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7305 | } |
| 7306 | |
| 7307 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7308 | { |
| 7309 | struct rpc_bind_conn_calldata data = { |
| 7310 | .clp = clp, |
| 7311 | .cred = cred, |
| 7312 | }; |
| 7313 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7314 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7315 | } |
| 7316 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7317 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7318 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7319 | * 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] | 7320 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7321 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7322 | .how = SP4_MACH_CRED, |
| 7323 | .enforce.u.words = { |
| 7324 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7325 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7326 | 1 << (OP_CREATE_SESSION - 32) | |
| 7327 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7328 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7329 | }, |
| 7330 | .allow.u.words = { |
| 7331 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7332 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7333 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7334 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7335 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7336 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7337 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7338 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7339 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7340 | 1 << (OP_FREE_STATEID - 32) | |
| 7341 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7342 | } |
| 7343 | }; |
| 7344 | |
| 7345 | /* |
| 7346 | * Select the state protection mode for client `clp' given the server results |
| 7347 | * from exchange_id in `sp'. |
| 7348 | * |
| 7349 | * Returns 0 on success, negative errno otherwise. |
| 7350 | */ |
| 7351 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7352 | struct nfs41_state_protection *sp) |
| 7353 | { |
| 7354 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7355 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7356 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7357 | 1 << (OP_CREATE_SESSION - 32) | |
| 7358 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7359 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7360 | }; |
| 7361 | unsigned int i; |
| 7362 | |
| 7363 | if (sp->how == SP4_MACH_CRED) { |
| 7364 | /* Print state protect result */ |
| 7365 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7366 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7367 | if (test_bit(i, sp->enforce.u.longs)) |
| 7368 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7369 | if (test_bit(i, sp->allow.u.longs)) |
| 7370 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7371 | } |
| 7372 | |
| 7373 | /* make sure nothing is on enforce list that isn't supported */ |
| 7374 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7375 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7376 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7377 | return -EINVAL; |
| 7378 | } |
| 7379 | } |
| 7380 | |
| 7381 | /* |
| 7382 | * Minimal mode - state operations are allowed to use machine |
| 7383 | * credential. Note this already happens by default, so the |
| 7384 | * client doesn't have to do anything more than the negotiation. |
| 7385 | * |
| 7386 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7387 | * we're already using the machine cred for exchange_id |
| 7388 | * and will never use a different cred. |
| 7389 | */ |
| 7390 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7391 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7392 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7393 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7394 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7395 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7396 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7397 | } else { |
| 7398 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7399 | return -EINVAL; |
| 7400 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7401 | |
| 7402 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7403 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7404 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7405 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7406 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7407 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7408 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7409 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7410 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7411 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7412 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7413 | &clp->cl_sp4_flags); |
| 7414 | } |
| 7415 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7416 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7417 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7418 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7419 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7420 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7421 | |
| 7422 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7423 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7424 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7425 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7426 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7427 | |
| 7428 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7429 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7430 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7431 | } |
| 7432 | |
| 7433 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7434 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7435 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7436 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | return 0; |
| 7440 | } |
| 7441 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7442 | struct nfs41_exchange_id_data { |
| 7443 | struct nfs41_exchange_id_res res; |
| 7444 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7445 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7446 | int rpc_status; |
| 7447 | }; |
| 7448 | |
| 7449 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7450 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7451 | struct nfs41_exchange_id_data *cdata = |
| 7452 | (struct nfs41_exchange_id_data *)data; |
| 7453 | struct nfs_client *clp = cdata->args.client; |
| 7454 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7455 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7456 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7457 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7458 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7459 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7460 | |
| 7461 | if (cdata->xprt && status == 0) { |
| 7462 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7463 | cdata->xprt); |
| 7464 | goto out; |
| 7465 | } |
| 7466 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7467 | if (status == 0) |
| 7468 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7469 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7470 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7471 | clp->cl_clientid = cdata->res.clientid; |
| 7472 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7473 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7474 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7475 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7476 | &clp->cl_session->session_state); |
| 7477 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7478 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7479 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7480 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7481 | clp->cl_serverowner = cdata->res.server_owner; |
| 7482 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7483 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7484 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7485 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7486 | clp->cl_implid = cdata->res.impl_id; |
| 7487 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7488 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7489 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7490 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7491 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7492 | dprintk("%s: server_scope mismatch detected\n", |
| 7493 | __func__); |
| 7494 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7495 | kfree(clp->cl_serverscope); |
| 7496 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7497 | } |
| 7498 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7499 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7500 | clp->cl_serverscope = cdata->res.server_scope; |
| 7501 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7502 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7503 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7504 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7505 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7506 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7507 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7508 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7509 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | static void nfs4_exchange_id_release(void *data) |
| 7513 | { |
| 7514 | struct nfs41_exchange_id_data *cdata = |
| 7515 | (struct nfs41_exchange_id_data *)data; |
| 7516 | |
| 7517 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7518 | if (cdata->xprt) { |
| 7519 | xprt_put(cdata->xprt); |
| 7520 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7521 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7522 | kfree(cdata->res.impl_id); |
| 7523 | kfree(cdata->res.server_scope); |
| 7524 | kfree(cdata->res.server_owner); |
| 7525 | kfree(cdata); |
| 7526 | } |
| 7527 | |
| 7528 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7529 | .rpc_call_done = nfs4_exchange_id_done, |
| 7530 | .rpc_release = nfs4_exchange_id_release, |
| 7531 | }; |
| 7532 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7533 | /* |
| 7534 | * _nfs4_proc_exchange_id() |
| 7535 | * |
| 7536 | * Wrapper for EXCHANGE_ID operation. |
| 7537 | */ |
| 7538 | 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] | 7539 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7540 | { |
| 7541 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7542 | struct rpc_message msg = { |
| 7543 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7544 | .rpc_cred = cred, |
| 7545 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7546 | struct rpc_task_setup task_setup_data = { |
| 7547 | .rpc_client = clp->cl_rpcclient, |
| 7548 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7549 | .rpc_message = &msg, |
| 7550 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7551 | }; |
| 7552 | struct nfs41_exchange_id_data *calldata; |
| 7553 | struct rpc_task *task; |
| 7554 | int status = -EIO; |
| 7555 | |
| 7556 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7557 | goto out; |
| 7558 | |
| 7559 | status = -ENOMEM; |
| 7560 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7561 | if (!calldata) |
| 7562 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7563 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7564 | if (!xprt) |
| 7565 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7566 | |
| 7567 | status = nfs4_init_uniform_client_string(clp); |
| 7568 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7569 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7570 | |
| 7571 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7572 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7573 | clp->cl_owner_id); |
| 7574 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7575 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7576 | GFP_NOFS); |
| 7577 | status = -ENOMEM; |
| 7578 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7579 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7580 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7581 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7582 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7583 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7584 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7585 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7586 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7587 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7588 | goto out_server_scope; |
| 7589 | |
| 7590 | switch (sp4_how) { |
| 7591 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7592 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7593 | break; |
| 7594 | |
| 7595 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7596 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7597 | break; |
| 7598 | |
| 7599 | default: |
| 7600 | /* unsupported! */ |
| 7601 | WARN_ON_ONCE(1); |
| 7602 | status = -EINVAL; |
| 7603 | goto out_impl_id; |
| 7604 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7605 | if (xprt) { |
| 7606 | calldata->xprt = xprt; |
| 7607 | task_setup_data.rpc_xprt = xprt; |
| 7608 | task_setup_data.flags = |
| 7609 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7610 | calldata->args.verifier = &clp->cl_confirm; |
| 7611 | } else { |
| 7612 | calldata->args.verifier = &verifier; |
| 7613 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7614 | calldata->args.client = clp; |
| 7615 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7616 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7617 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7618 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7619 | #else |
| 7620 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7621 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7622 | #endif |
| 7623 | msg.rpc_argp = &calldata->args; |
| 7624 | msg.rpc_resp = &calldata->res; |
| 7625 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7626 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7627 | task = rpc_run_task(&task_setup_data); |
| 7628 | if (IS_ERR(task)) { |
| 7629 | status = PTR_ERR(task); |
| 7630 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7631 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7632 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7633 | if (!xprt) { |
| 7634 | status = rpc_wait_for_completion_task(task); |
| 7635 | if (!status) |
| 7636 | status = calldata->rpc_status; |
| 7637 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7638 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7639 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7640 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7641 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7642 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7643 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7644 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7645 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7646 | clp->cl_implid->date.seconds, |
| 7647 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7648 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7649 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7650 | |
| 7651 | out_impl_id: |
| 7652 | kfree(calldata->res.impl_id); |
| 7653 | out_server_scope: |
| 7654 | kfree(calldata->res.server_scope); |
| 7655 | out_server_owner: |
| 7656 | kfree(calldata->res.server_owner); |
| 7657 | out_calldata: |
| 7658 | kfree(calldata); |
| 7659 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7660 | } |
| 7661 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7662 | /* |
| 7663 | * nfs4_proc_exchange_id() |
| 7664 | * |
| 7665 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7666 | * |
| 7667 | * Since the clientid has expired, all compounds using sessions |
| 7668 | * associated with the stale clientid will be returning |
| 7669 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7670 | * be in some phase of session reset. |
| 7671 | * |
| 7672 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7673 | */ |
| 7674 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7675 | { |
| 7676 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7677 | int status; |
| 7678 | |
| 7679 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7680 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7681 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7682 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7683 | if (!status) |
| 7684 | return 0; |
| 7685 | } |
| 7686 | |
| 7687 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7688 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7689 | } |
| 7690 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7691 | /** |
| 7692 | * nfs4_test_session_trunk |
| 7693 | * |
| 7694 | * This is an add_xprt_test() test function called from |
| 7695 | * rpc_clnt_setup_test_and_add_xprt. |
| 7696 | * |
| 7697 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7698 | * and is dereferrenced in nfs4_exchange_id_release |
| 7699 | * |
| 7700 | * Upon success, add the new transport to the rpc_clnt |
| 7701 | * |
| 7702 | * @clnt: struct rpc_clnt to get new transport |
| 7703 | * @xprt: the rpc_xprt to test |
| 7704 | * @data: call data for _nfs4_proc_exchange_id. |
| 7705 | */ |
| 7706 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7707 | void *data) |
| 7708 | { |
| 7709 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7710 | u32 sp4_how; |
| 7711 | |
| 7712 | dprintk("--> %s try %s\n", __func__, |
| 7713 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7714 | |
| 7715 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7716 | |
| 7717 | /* Test connection for session trunking. Async exchange_id call */ |
| 7718 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7719 | } |
| 7720 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7721 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7722 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7723 | struct rpc_cred *cred) |
| 7724 | { |
| 7725 | struct rpc_message msg = { |
| 7726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7727 | .rpc_argp = clp, |
| 7728 | .rpc_cred = cred, |
| 7729 | }; |
| 7730 | int status; |
| 7731 | |
| 7732 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7733 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7734 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7735 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7736 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7737 | return status; |
| 7738 | } |
| 7739 | |
| 7740 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7741 | struct rpc_cred *cred) |
| 7742 | { |
| 7743 | unsigned int loop; |
| 7744 | int ret; |
| 7745 | |
| 7746 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7747 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7748 | switch (ret) { |
| 7749 | case -NFS4ERR_DELAY: |
| 7750 | case -NFS4ERR_CLIENTID_BUSY: |
| 7751 | ssleep(1); |
| 7752 | break; |
| 7753 | default: |
| 7754 | return ret; |
| 7755 | } |
| 7756 | } |
| 7757 | return 0; |
| 7758 | } |
| 7759 | |
| 7760 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7761 | { |
| 7762 | struct rpc_cred *cred; |
| 7763 | int ret = 0; |
| 7764 | |
| 7765 | if (clp->cl_mvops->minor_version < 1) |
| 7766 | goto out; |
| 7767 | if (clp->cl_exchange_flags == 0) |
| 7768 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7769 | if (clp->cl_preserve_clid) |
| 7770 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7771 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7772 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7773 | if (cred) |
| 7774 | put_rpccred(cred); |
| 7775 | switch (ret) { |
| 7776 | case 0: |
| 7777 | case -NFS4ERR_STALE_CLIENTID: |
| 7778 | clp->cl_exchange_flags = 0; |
| 7779 | } |
| 7780 | out: |
| 7781 | return ret; |
| 7782 | } |
| 7783 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7784 | struct nfs4_get_lease_time_data { |
| 7785 | struct nfs4_get_lease_time_args *args; |
| 7786 | struct nfs4_get_lease_time_res *res; |
| 7787 | struct nfs_client *clp; |
| 7788 | }; |
| 7789 | |
| 7790 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7791 | void *calldata) |
| 7792 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7793 | struct nfs4_get_lease_time_data *data = |
| 7794 | (struct nfs4_get_lease_time_data *)calldata; |
| 7795 | |
| 7796 | dprintk("--> %s\n", __func__); |
| 7797 | /* just setup sequence, do not trigger session recovery |
| 7798 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7799 | nfs41_setup_sequence(data->clp->cl_session, |
| 7800 | &data->args->la_seq_args, |
| 7801 | &data->res->lr_seq_res, |
| 7802 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7803 | dprintk("<-- %s\n", __func__); |
| 7804 | } |
| 7805 | |
| 7806 | /* |
| 7807 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7808 | * from sequence operation or clientid errors. |
| 7809 | */ |
| 7810 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7811 | { |
| 7812 | struct nfs4_get_lease_time_data *data = |
| 7813 | (struct nfs4_get_lease_time_data *)calldata; |
| 7814 | |
| 7815 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7816 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7817 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7818 | switch (task->tk_status) { |
| 7819 | case -NFS4ERR_DELAY: |
| 7820 | case -NFS4ERR_GRACE: |
| 7821 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7822 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7823 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7824 | /* fall through */ |
| 7825 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7826 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7827 | return; |
| 7828 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7829 | dprintk("<-- %s\n", __func__); |
| 7830 | } |
| 7831 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7832 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7833 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7834 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7835 | }; |
| 7836 | |
| 7837 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7838 | { |
| 7839 | struct rpc_task *task; |
| 7840 | struct nfs4_get_lease_time_args args; |
| 7841 | struct nfs4_get_lease_time_res res = { |
| 7842 | .lr_fsinfo = fsinfo, |
| 7843 | }; |
| 7844 | struct nfs4_get_lease_time_data data = { |
| 7845 | .args = &args, |
| 7846 | .res = &res, |
| 7847 | .clp = clp, |
| 7848 | }; |
| 7849 | struct rpc_message msg = { |
| 7850 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7851 | .rpc_argp = &args, |
| 7852 | .rpc_resp = &res, |
| 7853 | }; |
| 7854 | struct rpc_task_setup task_setup = { |
| 7855 | .rpc_client = clp->cl_rpcclient, |
| 7856 | .rpc_message = &msg, |
| 7857 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7858 | .callback_data = &data, |
| 7859 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7860 | }; |
| 7861 | int status; |
| 7862 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7863 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7864 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7865 | dprintk("--> %s\n", __func__); |
| 7866 | task = rpc_run_task(&task_setup); |
| 7867 | |
| 7868 | if (IS_ERR(task)) |
| 7869 | status = PTR_ERR(task); |
| 7870 | else { |
| 7871 | status = task->tk_status; |
| 7872 | rpc_put_task(task); |
| 7873 | } |
| 7874 | dprintk("<-- %s return %d\n", __func__, status); |
| 7875 | |
| 7876 | return status; |
| 7877 | } |
| 7878 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7879 | /* |
| 7880 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7881 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7882 | * use them. |
| 7883 | * |
| 7884 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7885 | * always set csa_cachethis to FALSE because the current implementation |
| 7886 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7887 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7888 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7889 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7890 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7891 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7892 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7893 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7894 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7895 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7896 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7897 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7898 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7899 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7900 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7901 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7902 | |
| 7903 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7904 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7905 | __func__, |
| 7906 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7907 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7908 | |
| 7909 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7910 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7911 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7912 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7913 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7914 | 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] | 7915 | |
| 7916 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7917 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7918 | __func__, |
| 7919 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7920 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7921 | args->bc_attrs.max_reqs); |
| 7922 | } |
| 7923 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7924 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7925 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7926 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7927 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7928 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7929 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7930 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7931 | return -EINVAL; |
| 7932 | /* |
| 7933 | * Our requested max_ops is the minimum we need; we're not |
| 7934 | * prepared to break up compounds into smaller pieces than that. |
| 7935 | * So, no point even trying to continue if the server won't |
| 7936 | * cooperate: |
| 7937 | */ |
| 7938 | if (rcvd->max_ops < sent->max_ops) |
| 7939 | return -EINVAL; |
| 7940 | if (rcvd->max_reqs == 0) |
| 7941 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7942 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7943 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7944 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7945 | } |
| 7946 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7947 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7948 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7949 | { |
| 7950 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7951 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7952 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7953 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7954 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7955 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7956 | return -EINVAL; |
| 7957 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7958 | return -EINVAL; |
| 7959 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7960 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7961 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7962 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7963 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7964 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7965 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7966 | return 0; |
| 7967 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7968 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7969 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7970 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7971 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7972 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7973 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7974 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7975 | if (ret) |
| 7976 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7977 | return nfs4_verify_back_channel_attrs(args, res); |
| 7978 | } |
| 7979 | |
| 7980 | static void nfs4_update_session(struct nfs4_session *session, |
| 7981 | struct nfs41_create_session_res *res) |
| 7982 | { |
| 7983 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7984 | /* Mark client id and session as being confirmed */ |
| 7985 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7986 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7987 | session->flags = res->flags; |
| 7988 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7989 | if (res->flags & SESSION4_BACK_CHAN) |
| 7990 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7991 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7992 | } |
| 7993 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7994 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7995 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7996 | { |
| 7997 | struct nfs4_session *session = clp->cl_session; |
| 7998 | struct nfs41_create_session_args args = { |
| 7999 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8000 | .clientid = clp->cl_clientid, |
| 8001 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8002 | .cb_program = NFS4_CALLBACK, |
| 8003 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8004 | struct nfs41_create_session_res res; |
| 8005 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8006 | struct rpc_message msg = { |
| 8007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8008 | .rpc_argp = &args, |
| 8009 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8010 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8011 | }; |
| 8012 | int status; |
| 8013 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8014 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8015 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8016 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8017 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8018 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8019 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8020 | switch (status) { |
| 8021 | case -NFS4ERR_STALE_CLIENTID: |
| 8022 | case -NFS4ERR_DELAY: |
| 8023 | case -ETIMEDOUT: |
| 8024 | case -EACCES: |
| 8025 | case -EAGAIN: |
| 8026 | goto out; |
| 8027 | }; |
| 8028 | |
| 8029 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8030 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8031 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8032 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8033 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8034 | if (status) |
| 8035 | goto out; |
| 8036 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8037 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8038 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8039 | return status; |
| 8040 | } |
| 8041 | |
| 8042 | /* |
| 8043 | * Issues a CREATE_SESSION operation to the server. |
| 8044 | * It is the responsibility of the caller to verify the session is |
| 8045 | * expired before calling this routine. |
| 8046 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8047 | 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] | 8048 | { |
| 8049 | int status; |
| 8050 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8051 | struct nfs4_session *session = clp->cl_session; |
| 8052 | |
| 8053 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8054 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8055 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8056 | if (status) |
| 8057 | goto out; |
| 8058 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8059 | /* Init or reset the session slot tables */ |
| 8060 | status = nfs4_setup_session_slot_tables(session); |
| 8061 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8062 | if (status) |
| 8063 | goto out; |
| 8064 | |
| 8065 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8066 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8067 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8068 | out: |
| 8069 | dprintk("<-- %s\n", __func__); |
| 8070 | return status; |
| 8071 | } |
| 8072 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8073 | /* |
| 8074 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8075 | * The caller must serialize access to this routine. |
| 8076 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8077 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8078 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8079 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8080 | struct rpc_message msg = { |
| 8081 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8082 | .rpc_argp = session, |
| 8083 | .rpc_cred = cred, |
| 8084 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8085 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8086 | |
| 8087 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8088 | |
| 8089 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8090 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8091 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8092 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8093 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8094 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8095 | |
| 8096 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8097 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8098 | "Session has been destroyed regardless...\n", status); |
| 8099 | |
| 8100 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8101 | return status; |
| 8102 | } |
| 8103 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8104 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8105 | * Renew the cl_session lease. |
| 8106 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8107 | struct nfs4_sequence_data { |
| 8108 | struct nfs_client *clp; |
| 8109 | struct nfs4_sequence_args args; |
| 8110 | struct nfs4_sequence_res res; |
| 8111 | }; |
| 8112 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8113 | static void nfs41_sequence_release(void *data) |
| 8114 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8115 | struct nfs4_sequence_data *calldata = data; |
| 8116 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8117 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8118 | if (atomic_read(&clp->cl_count) > 1) |
| 8119 | nfs4_schedule_state_renewal(clp); |
| 8120 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8121 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8122 | } |
| 8123 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8124 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8125 | { |
| 8126 | switch(task->tk_status) { |
| 8127 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8128 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8129 | return -EAGAIN; |
| 8130 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8131 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8132 | } |
| 8133 | return 0; |
| 8134 | } |
| 8135 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8136 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8137 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8138 | struct nfs4_sequence_data *calldata = data; |
| 8139 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8140 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8141 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8142 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8143 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8144 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8145 | if (task->tk_status < 0) { |
| 8146 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8147 | if (atomic_read(&clp->cl_count) == 1) |
| 8148 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8149 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8150 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8151 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8152 | return; |
| 8153 | } |
| 8154 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8155 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8156 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8157 | dprintk("<-- %s\n", __func__); |
| 8158 | } |
| 8159 | |
| 8160 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8161 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8162 | struct nfs4_sequence_data *calldata = data; |
| 8163 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8164 | struct nfs4_sequence_args *args; |
| 8165 | struct nfs4_sequence_res *res; |
| 8166 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8167 | args = task->tk_msg.rpc_argp; |
| 8168 | res = task->tk_msg.rpc_resp; |
| 8169 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8170 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8171 | } |
| 8172 | |
| 8173 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8174 | .rpc_call_done = nfs41_sequence_call_done, |
| 8175 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8176 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8177 | }; |
| 8178 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8179 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8180 | struct rpc_cred *cred, |
| 8181 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8182 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8183 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8184 | struct rpc_message msg = { |
| 8185 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8186 | .rpc_cred = cred, |
| 8187 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8188 | struct rpc_task_setup task_setup_data = { |
| 8189 | .rpc_client = clp->cl_rpcclient, |
| 8190 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8191 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8192 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8193 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8194 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8195 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8196 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8197 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8198 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8199 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8200 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8201 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8202 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8203 | if (is_privileged) |
| 8204 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8205 | msg.rpc_argp = &calldata->args; |
| 8206 | msg.rpc_resp = &calldata->res; |
| 8207 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8208 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8209 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8210 | return rpc_run_task(&task_setup_data); |
| 8211 | } |
| 8212 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8213 | 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] | 8214 | { |
| 8215 | struct rpc_task *task; |
| 8216 | int ret = 0; |
| 8217 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8218 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8219 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8220 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8221 | if (IS_ERR(task)) |
| 8222 | ret = PTR_ERR(task); |
| 8223 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8224 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8225 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8226 | return ret; |
| 8227 | } |
| 8228 | |
| 8229 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8230 | { |
| 8231 | struct rpc_task *task; |
| 8232 | int ret; |
| 8233 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8234 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8235 | if (IS_ERR(task)) { |
| 8236 | ret = PTR_ERR(task); |
| 8237 | goto out; |
| 8238 | } |
| 8239 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8240 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8241 | ret = task->tk_status; |
| 8242 | rpc_put_task(task); |
| 8243 | out: |
| 8244 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8245 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8246 | } |
| 8247 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8248 | struct nfs4_reclaim_complete_data { |
| 8249 | struct nfs_client *clp; |
| 8250 | struct nfs41_reclaim_complete_args arg; |
| 8251 | struct nfs41_reclaim_complete_res res; |
| 8252 | }; |
| 8253 | |
| 8254 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8255 | { |
| 8256 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8257 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8258 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8259 | &calldata->arg.seq_args, |
| 8260 | &calldata->res.seq_res, |
| 8261 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8262 | } |
| 8263 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8264 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8265 | { |
| 8266 | switch(task->tk_status) { |
| 8267 | case 0: |
| 8268 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8269 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8270 | break; |
| 8271 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8272 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8273 | /* fall through */ |
| 8274 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8275 | return -EAGAIN; |
| 8276 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8277 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8278 | } |
| 8279 | return 0; |
| 8280 | } |
| 8281 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8282 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8283 | { |
| 8284 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8285 | struct nfs_client *clp = calldata->clp; |
| 8286 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8287 | |
| 8288 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8289 | if (!nfs41_sequence_done(task, res)) |
| 8290 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8291 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8292 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8293 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8294 | rpc_restart_call_prepare(task); |
| 8295 | return; |
| 8296 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8297 | dprintk("<-- %s\n", __func__); |
| 8298 | } |
| 8299 | |
| 8300 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8301 | { |
| 8302 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8303 | |
| 8304 | kfree(calldata); |
| 8305 | } |
| 8306 | |
| 8307 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8308 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8309 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8310 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8311 | }; |
| 8312 | |
| 8313 | /* |
| 8314 | * Issue a global reclaim complete. |
| 8315 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8316 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8317 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8318 | { |
| 8319 | struct nfs4_reclaim_complete_data *calldata; |
| 8320 | struct rpc_task *task; |
| 8321 | struct rpc_message msg = { |
| 8322 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8323 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8324 | }; |
| 8325 | struct rpc_task_setup task_setup_data = { |
| 8326 | .rpc_client = clp->cl_rpcclient, |
| 8327 | .rpc_message = &msg, |
| 8328 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8329 | .flags = RPC_TASK_ASYNC, |
| 8330 | }; |
| 8331 | int status = -ENOMEM; |
| 8332 | |
| 8333 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8334 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8335 | if (calldata == NULL) |
| 8336 | goto out; |
| 8337 | calldata->clp = clp; |
| 8338 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8339 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8340 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8341 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8342 | msg.rpc_argp = &calldata->arg; |
| 8343 | msg.rpc_resp = &calldata->res; |
| 8344 | task_setup_data.callback_data = calldata; |
| 8345 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8346 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8347 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8348 | goto out; |
| 8349 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8350 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8351 | if (status == 0) |
| 8352 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8353 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8354 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8355 | out: |
| 8356 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8357 | return status; |
| 8358 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8359 | |
| 8360 | static void |
| 8361 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8362 | { |
| 8363 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8364 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8365 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8366 | |
| 8367 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8368 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8369 | &lgp->res.seq_res, task); |
| 8370 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8374 | { |
| 8375 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8376 | |
| 8377 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8378 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8379 | dprintk("<-- %s\n", __func__); |
| 8380 | } |
| 8381 | |
| 8382 | static int |
| 8383 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8384 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8385 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8386 | struct inode *inode = lgp->args.inode; |
| 8387 | struct nfs_server *server = NFS_SERVER(inode); |
| 8388 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8389 | int nfs4err = task->tk_status; |
| 8390 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8391 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8392 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8393 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8394 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8395 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8396 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8397 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8398 | |
| 8399 | /* |
| 8400 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8401 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8402 | * retry go inband. |
| 8403 | */ |
| 8404 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8405 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8406 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8407 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8408 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8409 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8410 | */ |
| 8411 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8412 | status = -EOVERFLOW; |
| 8413 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8414 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8415 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8416 | * (or clients) writing to the same RAID stripe except when |
| 8417 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8418 | * |
| 8419 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8420 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8421 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8422 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8423 | if (lgp->args.minlength == 0) { |
| 8424 | status = -EOVERFLOW; |
| 8425 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8426 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8427 | status = -EBUSY; |
| 8428 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8429 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8430 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8431 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8432 | case -NFS4ERR_DELEG_REVOKED: |
| 8433 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8434 | case -NFS4ERR_EXPIRED: |
| 8435 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8436 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8437 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8438 | lo = NFS_I(inode)->layout; |
| 8439 | /* If the open stateid was bad, then recover it. */ |
| 8440 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8441 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8442 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8443 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8444 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8445 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8446 | break; |
| 8447 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8448 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8449 | /* |
| 8450 | * Mark the bad layout state as invalid, then retry |
| 8451 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8452 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8453 | spin_unlock(&inode->i_lock); |
| 8454 | pnfs_free_lseg_list(&head); |
| 8455 | status = -EAGAIN; |
| 8456 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8457 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8458 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8459 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8460 | if (!status) { |
| 8461 | if (exception->retry) |
| 8462 | status = -EAGAIN; |
| 8463 | else |
| 8464 | status = err; |
| 8465 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8466 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8467 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8468 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8469 | } |
| 8470 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8471 | static size_t max_response_pages(struct nfs_server *server) |
| 8472 | { |
| 8473 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8474 | return nfs_page_array_len(0, max_resp_sz); |
| 8475 | } |
| 8476 | |
| 8477 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8478 | { |
| 8479 | int i; |
| 8480 | |
| 8481 | if (!pages) |
| 8482 | return; |
| 8483 | |
| 8484 | for (i = 0; i < size; i++) { |
| 8485 | if (!pages[i]) |
| 8486 | break; |
| 8487 | __free_page(pages[i]); |
| 8488 | } |
| 8489 | kfree(pages); |
| 8490 | } |
| 8491 | |
| 8492 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8493 | { |
| 8494 | struct page **pages; |
| 8495 | int i; |
| 8496 | |
| 8497 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8498 | if (!pages) { |
| 8499 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8500 | return NULL; |
| 8501 | } |
| 8502 | |
| 8503 | for (i = 0; i < size; i++) { |
| 8504 | pages[i] = alloc_page(gfp_flags); |
| 8505 | if (!pages[i]) { |
| 8506 | dprintk("%s: failed to allocate page\n", __func__); |
| 8507 | nfs4_free_pages(pages, size); |
| 8508 | return NULL; |
| 8509 | } |
| 8510 | } |
| 8511 | |
| 8512 | return pages; |
| 8513 | } |
| 8514 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8515 | static void nfs4_layoutget_release(void *calldata) |
| 8516 | { |
| 8517 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8518 | struct inode *inode = lgp->args.inode; |
| 8519 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8520 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8521 | |
| 8522 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8523 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8524 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8525 | put_nfs_open_context(lgp->args.ctx); |
| 8526 | kfree(calldata); |
| 8527 | dprintk("<-- %s\n", __func__); |
| 8528 | } |
| 8529 | |
| 8530 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8531 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8532 | .rpc_call_done = nfs4_layoutget_done, |
| 8533 | .rpc_release = nfs4_layoutget_release, |
| 8534 | }; |
| 8535 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8536 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8537 | 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] | 8538 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8539 | struct inode *inode = lgp->args.inode; |
| 8540 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8541 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8542 | struct rpc_task *task; |
| 8543 | struct rpc_message msg = { |
| 8544 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8545 | .rpc_argp = &lgp->args, |
| 8546 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8547 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8548 | }; |
| 8549 | struct rpc_task_setup task_setup_data = { |
| 8550 | .rpc_client = server->client, |
| 8551 | .rpc_message = &msg, |
| 8552 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8553 | .callback_data = lgp, |
| 8554 | .flags = RPC_TASK_ASYNC, |
| 8555 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8556 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8557 | struct nfs4_exception exception = { |
| 8558 | .inode = inode, |
| 8559 | .timeout = *timeout, |
| 8560 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8561 | int status = 0; |
| 8562 | |
| 8563 | dprintk("--> %s\n", __func__); |
| 8564 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8565 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8566 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8567 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8568 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8569 | if (!lgp->args.layout.pages) { |
| 8570 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8571 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8572 | } |
| 8573 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8574 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8575 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8576 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8577 | 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] | 8578 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8579 | task = rpc_run_task(&task_setup_data); |
| 8580 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8581 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8582 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8583 | if (status == 0) { |
| 8584 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8585 | *timeout = exception.timeout; |
| 8586 | } |
| 8587 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8588 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8589 | &lgp->args.range, |
| 8590 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8591 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8592 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8593 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8594 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8595 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8596 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8597 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8598 | rpc_put_task(task); |
| 8599 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8600 | if (status) |
| 8601 | return ERR_PTR(status); |
| 8602 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8603 | } |
| 8604 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8605 | static void |
| 8606 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8607 | { |
| 8608 | struct nfs4_layoutreturn *lrp = calldata; |
| 8609 | |
| 8610 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8611 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8612 | &lrp->args.seq_args, |
| 8613 | &lrp->res.seq_res, |
| 8614 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8615 | } |
| 8616 | |
| 8617 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8618 | { |
| 8619 | struct nfs4_layoutreturn *lrp = calldata; |
| 8620 | struct nfs_server *server; |
| 8621 | |
| 8622 | dprintk("--> %s\n", __func__); |
| 8623 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8624 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8625 | return; |
| 8626 | |
| 8627 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8628 | switch (task->tk_status) { |
| 8629 | default: |
| 8630 | task->tk_status = 0; |
| 8631 | case 0: |
| 8632 | break; |
| 8633 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8634 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8635 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8636 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8637 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8638 | return; |
| 8639 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8640 | dprintk("<-- %s\n", __func__); |
| 8641 | } |
| 8642 | |
| 8643 | static void nfs4_layoutreturn_release(void *calldata) |
| 8644 | { |
| 8645 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8646 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8647 | |
| 8648 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8649 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8650 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8651 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8652 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8653 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8654 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8655 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8656 | kfree(calldata); |
| 8657 | dprintk("<-- %s\n", __func__); |
| 8658 | } |
| 8659 | |
| 8660 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8661 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8662 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8663 | .rpc_release = nfs4_layoutreturn_release, |
| 8664 | }; |
| 8665 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8666 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8667 | { |
| 8668 | struct rpc_task *task; |
| 8669 | struct rpc_message msg = { |
| 8670 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8671 | .rpc_argp = &lrp->args, |
| 8672 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8673 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8674 | }; |
| 8675 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8676 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8677 | .rpc_message = &msg, |
| 8678 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8679 | .callback_data = lrp, |
| 8680 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8681 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8682 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8683 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8684 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8685 | &task_setup_data.rpc_client, &msg); |
| 8686 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8687 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8688 | if (!sync) { |
| 8689 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8690 | if (!lrp->inode) { |
| 8691 | nfs4_layoutreturn_release(lrp); |
| 8692 | return -EAGAIN; |
| 8693 | } |
| 8694 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8695 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8696 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8697 | task = rpc_run_task(&task_setup_data); |
| 8698 | if (IS_ERR(task)) |
| 8699 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8700 | if (sync) |
| 8701 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8702 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8703 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8704 | rpc_put_task(task); |
| 8705 | return status; |
| 8706 | } |
| 8707 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8708 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8709 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8710 | struct pnfs_device *pdev, |
| 8711 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8712 | { |
| 8713 | struct nfs4_getdeviceinfo_args args = { |
| 8714 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8715 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8716 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8717 | }; |
| 8718 | struct nfs4_getdeviceinfo_res res = { |
| 8719 | .pdev = pdev, |
| 8720 | }; |
| 8721 | struct rpc_message msg = { |
| 8722 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8723 | .rpc_argp = &args, |
| 8724 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8725 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8726 | }; |
| 8727 | int status; |
| 8728 | |
| 8729 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8730 | 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] | 8731 | if (res.notification & ~args.notify_types) |
| 8732 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8733 | if (res.notification != args.notify_types) |
| 8734 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8735 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8736 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8737 | |
| 8738 | return status; |
| 8739 | } |
| 8740 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8741 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8742 | struct pnfs_device *pdev, |
| 8743 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8744 | { |
| 8745 | struct nfs4_exception exception = { }; |
| 8746 | int err; |
| 8747 | |
| 8748 | do { |
| 8749 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8750 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8751 | &exception); |
| 8752 | } while (exception.retry); |
| 8753 | return err; |
| 8754 | } |
| 8755 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8756 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8757 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8758 | { |
| 8759 | struct nfs4_layoutcommit_data *data = calldata; |
| 8760 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8761 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8762 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8763 | nfs41_setup_sequence(session, |
| 8764 | &data->args.seq_args, |
| 8765 | &data->res.seq_res, |
| 8766 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8767 | } |
| 8768 | |
| 8769 | static void |
| 8770 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8771 | { |
| 8772 | struct nfs4_layoutcommit_data *data = calldata; |
| 8773 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8774 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8775 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8776 | return; |
| 8777 | |
| 8778 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8779 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8780 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8781 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8782 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8783 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8784 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8785 | break; |
| 8786 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8787 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8788 | rpc_restart_call_prepare(task); |
| 8789 | return; |
| 8790 | } |
| 8791 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8792 | } |
| 8793 | |
| 8794 | static void nfs4_layoutcommit_release(void *calldata) |
| 8795 | { |
| 8796 | struct nfs4_layoutcommit_data *data = calldata; |
| 8797 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8798 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8799 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8800 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8801 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8802 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8803 | kfree(data); |
| 8804 | } |
| 8805 | |
| 8806 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8807 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8808 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8809 | .rpc_release = nfs4_layoutcommit_release, |
| 8810 | }; |
| 8811 | |
| 8812 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8813 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8814 | { |
| 8815 | struct rpc_message msg = { |
| 8816 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8817 | .rpc_argp = &data->args, |
| 8818 | .rpc_resp = &data->res, |
| 8819 | .rpc_cred = data->cred, |
| 8820 | }; |
| 8821 | struct rpc_task_setup task_setup_data = { |
| 8822 | .task = &data->task, |
| 8823 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8824 | .rpc_message = &msg, |
| 8825 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8826 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8827 | }; |
| 8828 | struct rpc_task *task; |
| 8829 | int status = 0; |
| 8830 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8831 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8832 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8833 | data->args.lastbytewritten, |
| 8834 | data->args.inode->i_ino); |
| 8835 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8836 | if (!sync) { |
| 8837 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8838 | if (data->inode == NULL) { |
| 8839 | nfs4_layoutcommit_release(data); |
| 8840 | return -EAGAIN; |
| 8841 | } |
| 8842 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8843 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8844 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8845 | task = rpc_run_task(&task_setup_data); |
| 8846 | if (IS_ERR(task)) |
| 8847 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8848 | if (sync) |
| 8849 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8850 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8851 | dprintk("%s: status %d\n", __func__, status); |
| 8852 | rpc_put_task(task); |
| 8853 | return status; |
| 8854 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8855 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8856 | /** |
| 8857 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8858 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8859 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8860 | static int |
| 8861 | _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] | 8862 | struct nfs_fsinfo *info, |
| 8863 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8864 | { |
| 8865 | struct nfs41_secinfo_no_name_args args = { |
| 8866 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8867 | }; |
| 8868 | struct nfs4_secinfo_res res = { |
| 8869 | .flavors = flavors, |
| 8870 | }; |
| 8871 | struct rpc_message msg = { |
| 8872 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8873 | .rpc_argp = &args, |
| 8874 | .rpc_resp = &res, |
| 8875 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8876 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8877 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8878 | int status; |
| 8879 | |
| 8880 | if (use_integrity) { |
| 8881 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8882 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8883 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8884 | } |
| 8885 | |
| 8886 | dprintk("--> %s\n", __func__); |
| 8887 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8888 | &res.seq_res, 0); |
| 8889 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8890 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8891 | if (cred) |
| 8892 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8893 | |
| 8894 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8895 | } |
| 8896 | |
| 8897 | static int |
| 8898 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8899 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8900 | { |
| 8901 | struct nfs4_exception exception = { }; |
| 8902 | int err; |
| 8903 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8904 | /* first try using integrity protection */ |
| 8905 | err = -NFS4ERR_WRONGSEC; |
| 8906 | |
| 8907 | /* try to use integrity protection with machine cred */ |
| 8908 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8909 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8910 | flavors, true); |
| 8911 | |
| 8912 | /* |
| 8913 | * if unable to use integrity protection, or SECINFO with |
| 8914 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8915 | * disallowed by spec, but exists in deployed servers) use |
| 8916 | * the current filesystem's rpc_client and the user cred. |
| 8917 | */ |
| 8918 | if (err == -NFS4ERR_WRONGSEC) |
| 8919 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8920 | flavors, false); |
| 8921 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8922 | switch (err) { |
| 8923 | case 0: |
| 8924 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8925 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8926 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8927 | default: |
| 8928 | err = nfs4_handle_exception(server, err, &exception); |
| 8929 | } |
| 8930 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8931 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8932 | return err; |
| 8933 | } |
| 8934 | |
| 8935 | static int |
| 8936 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8937 | struct nfs_fsinfo *info) |
| 8938 | { |
| 8939 | int err; |
| 8940 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8941 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8942 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8943 | struct nfs4_secinfo4 *secinfo; |
| 8944 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8945 | |
| 8946 | page = alloc_page(GFP_KERNEL); |
| 8947 | if (!page) { |
| 8948 | err = -ENOMEM; |
| 8949 | goto out; |
| 8950 | } |
| 8951 | |
| 8952 | flavors = page_address(page); |
| 8953 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8954 | |
| 8955 | /* |
| 8956 | * Fall back on "guess and check" method if |
| 8957 | * the server doesn't support SECINFO_NO_NAME |
| 8958 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8959 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8960 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8961 | goto out_freepage; |
| 8962 | } |
| 8963 | if (err) |
| 8964 | goto out_freepage; |
| 8965 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8966 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8967 | secinfo = &flavors->flavors[i]; |
| 8968 | |
| 8969 | switch (secinfo->flavor) { |
| 8970 | case RPC_AUTH_NULL: |
| 8971 | case RPC_AUTH_UNIX: |
| 8972 | case RPC_AUTH_GSS: |
| 8973 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8974 | &secinfo->flavor_info); |
| 8975 | break; |
| 8976 | default: |
| 8977 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8978 | break; |
| 8979 | } |
| 8980 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8981 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8982 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8983 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8984 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8985 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8986 | info, flavor); |
| 8987 | if (!err) |
| 8988 | break; |
| 8989 | } |
| 8990 | } |
| 8991 | |
| 8992 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8993 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8994 | |
| 8995 | out_freepage: |
| 8996 | put_page(page); |
| 8997 | if (err == -EACCES) |
| 8998 | return -EPERM; |
| 8999 | out: |
| 9000 | return err; |
| 9001 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9002 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9003 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9004 | nfs4_stateid *stateid, |
| 9005 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9006 | { |
| 9007 | int status; |
| 9008 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9009 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9010 | }; |
| 9011 | struct nfs41_test_stateid_res res; |
| 9012 | struct rpc_message msg = { |
| 9013 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9014 | .rpc_argp = &args, |
| 9015 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9016 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9017 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9018 | struct rpc_clnt *rpc_client = server->client; |
| 9019 | |
| 9020 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9021 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9022 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9023 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9024 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9025 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9026 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9027 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9028 | if (status != NFS_OK) { |
| 9029 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9030 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9031 | } |
| 9032 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9033 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9034 | } |
| 9035 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9036 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9037 | int err, struct nfs4_exception *exception) |
| 9038 | { |
| 9039 | exception->retry = 0; |
| 9040 | switch(err) { |
| 9041 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9042 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9043 | nfs4_handle_exception(server, err, exception); |
| 9044 | break; |
| 9045 | case -NFS4ERR_BADSESSION: |
| 9046 | case -NFS4ERR_BADSLOT: |
| 9047 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9048 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9049 | case -NFS4ERR_DEADSESSION: |
| 9050 | nfs4_do_handle_exception(server, err, exception); |
| 9051 | } |
| 9052 | } |
| 9053 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9054 | /** |
| 9055 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9056 | * |
| 9057 | * @server: server / transport on which to perform the operation |
| 9058 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9059 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9060 | * |
| 9061 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9062 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9063 | * failed or the state ID is not currently valid. |
| 9064 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9065 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9066 | nfs4_stateid *stateid, |
| 9067 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9068 | { |
| 9069 | struct nfs4_exception exception = { }; |
| 9070 | int err; |
| 9071 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9072 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9073 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9074 | } while (exception.retry); |
| 9075 | return err; |
| 9076 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9077 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9078 | struct nfs_free_stateid_data { |
| 9079 | struct nfs_server *server; |
| 9080 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9081 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9082 | }; |
| 9083 | |
| 9084 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9085 | { |
| 9086 | struct nfs_free_stateid_data *data = calldata; |
| 9087 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 9088 | &data->args.seq_args, |
| 9089 | &data->res.seq_res, |
| 9090 | task); |
| 9091 | } |
| 9092 | |
| 9093 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9094 | { |
| 9095 | struct nfs_free_stateid_data *data = calldata; |
| 9096 | |
| 9097 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9098 | |
| 9099 | switch (task->tk_status) { |
| 9100 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9101 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9102 | rpc_restart_call_prepare(task); |
| 9103 | } |
| 9104 | } |
| 9105 | |
| 9106 | static void nfs41_free_stateid_release(void *calldata) |
| 9107 | { |
| 9108 | kfree(calldata); |
| 9109 | } |
| 9110 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9111 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9112 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9113 | .rpc_call_done = nfs41_free_stateid_done, |
| 9114 | .rpc_release = nfs41_free_stateid_release, |
| 9115 | }; |
| 9116 | |
| 9117 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9118 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9119 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9120 | bool privileged) |
| 9121 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9122 | struct rpc_message msg = { |
| 9123 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9124 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9125 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9126 | struct rpc_task_setup task_setup = { |
| 9127 | .rpc_client = server->client, |
| 9128 | .rpc_message = &msg, |
| 9129 | .callback_ops = &nfs41_free_stateid_ops, |
| 9130 | .flags = RPC_TASK_ASYNC, |
| 9131 | }; |
| 9132 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9133 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9134 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9135 | &task_setup.rpc_client, &msg); |
| 9136 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9137 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9138 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9139 | if (!data) |
| 9140 | return ERR_PTR(-ENOMEM); |
| 9141 | data->server = server; |
| 9142 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9143 | |
| 9144 | task_setup.callback_data = data; |
| 9145 | |
| 9146 | msg.rpc_argp = &data->args; |
| 9147 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9148 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9149 | if (privileged) |
| 9150 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9151 | |
| 9152 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9153 | } |
| 9154 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9155 | /** |
| 9156 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9157 | * |
| 9158 | * @server: server / transport on which to perform the operation |
| 9159 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9160 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9161 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9162 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9163 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9164 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9165 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9166 | const nfs4_stateid *stateid, |
| 9167 | struct rpc_cred *cred, |
| 9168 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9169 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9170 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9171 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9172 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9173 | if (IS_ERR(task)) |
| 9174 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9175 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9176 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9177 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9178 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9179 | static void |
| 9180 | 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] | 9181 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9182 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9183 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9184 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9185 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9186 | } |
| 9187 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9188 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9189 | const nfs4_stateid *s2) |
| 9190 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9191 | if (s1->type != s2->type) |
| 9192 | return false; |
| 9193 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9194 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9195 | return false; |
| 9196 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9197 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9198 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9199 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9200 | return true; |
| 9201 | |
| 9202 | return false; |
| 9203 | } |
| 9204 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9205 | #endif /* CONFIG_NFS_V4_1 */ |
| 9206 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9207 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9208 | const nfs4_stateid *s2) |
| 9209 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9210 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9211 | } |
| 9212 | |
| 9213 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9214 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9215 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9216 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9217 | .recover_open = nfs4_open_reclaim, |
| 9218 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9219 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9220 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9221 | }; |
| 9222 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9223 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9224 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9225 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9226 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9227 | .recover_open = nfs4_open_reclaim, |
| 9228 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9229 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9230 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9231 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9232 | }; |
| 9233 | #endif /* CONFIG_NFS_V4_1 */ |
| 9234 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9235 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9236 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9237 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9238 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9239 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9240 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9241 | }; |
| 9242 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9243 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9244 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9245 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9246 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9247 | .recover_open = nfs41_open_expired, |
| 9248 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9249 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9250 | }; |
| 9251 | #endif /* CONFIG_NFS_V4_1 */ |
| 9252 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9253 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9254 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9255 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9256 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9257 | }; |
| 9258 | |
| 9259 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9260 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9261 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9262 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9263 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9264 | }; |
| 9265 | #endif |
| 9266 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9267 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9268 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9269 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9270 | }; |
| 9271 | |
| 9272 | #if defined(CONFIG_NFS_V4_1) |
| 9273 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9274 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9275 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9276 | }; |
| 9277 | #endif /* CONFIG_NFS_V4_1 */ |
| 9278 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9279 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9280 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9281 | .init_caps = NFS_CAP_READDIRPLUS |
| 9282 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9283 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9284 | .init_client = nfs40_init_client, |
| 9285 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9286 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9287 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9288 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9289 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9290 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9291 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9292 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9293 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9294 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9295 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9296 | }; |
| 9297 | |
| 9298 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9299 | static struct nfs_seqid * |
| 9300 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9301 | { |
| 9302 | return NULL; |
| 9303 | } |
| 9304 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9305 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9306 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9307 | .init_caps = NFS_CAP_READDIRPLUS |
| 9308 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9309 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9310 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9311 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9312 | .init_client = nfs41_init_client, |
| 9313 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9314 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9315 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9316 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9317 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9318 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9319 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9320 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9321 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9322 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9323 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9324 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9325 | }; |
| 9326 | #endif |
| 9327 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9328 | #if defined(CONFIG_NFS_V4_2) |
| 9329 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9330 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9331 | .init_caps = NFS_CAP_READDIRPLUS |
| 9332 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9333 | | NFS_CAP_POSIX_LOCK |
| 9334 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9335 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9336 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9337 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9338 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9339 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9340 | | NFS_CAP_LAYOUTSTATS |
| 9341 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9342 | .init_client = nfs41_init_client, |
| 9343 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9344 | .match_stateid = nfs41_match_stateid, |
| 9345 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9346 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9347 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9348 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9349 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9350 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9351 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9352 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9353 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9354 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9355 | }; |
| 9356 | #endif |
| 9357 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9358 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9359 | [0] = &nfs_v4_0_minor_ops, |
| 9360 | #if defined(CONFIG_NFS_V4_1) |
| 9361 | [1] = &nfs_v4_1_minor_ops, |
| 9362 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9363 | #if defined(CONFIG_NFS_V4_2) |
| 9364 | [2] = &nfs_v4_2_minor_ops, |
| 9365 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9366 | }; |
| 9367 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9368 | 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] | 9369 | { |
| 9370 | ssize_t error, error2; |
| 9371 | |
| 9372 | error = generic_listxattr(dentry, list, size); |
| 9373 | if (error < 0) |
| 9374 | return error; |
| 9375 | if (list) { |
| 9376 | list += error; |
| 9377 | size -= error; |
| 9378 | } |
| 9379 | |
| 9380 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9381 | if (error2 < 0) |
| 9382 | return error2; |
| 9383 | return error + error2; |
| 9384 | } |
| 9385 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9386 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9387 | .create = nfs_create, |
| 9388 | .lookup = nfs_lookup, |
| 9389 | .atomic_open = nfs_atomic_open, |
| 9390 | .link = nfs_link, |
| 9391 | .unlink = nfs_unlink, |
| 9392 | .symlink = nfs_symlink, |
| 9393 | .mkdir = nfs_mkdir, |
| 9394 | .rmdir = nfs_rmdir, |
| 9395 | .mknod = nfs_mknod, |
| 9396 | .rename = nfs_rename, |
| 9397 | .permission = nfs_permission, |
| 9398 | .getattr = nfs_getattr, |
| 9399 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9400 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9401 | }; |
| 9402 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9403 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9404 | .permission = nfs_permission, |
| 9405 | .getattr = nfs_getattr, |
| 9406 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9407 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9408 | }; |
| 9409 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9410 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9411 | .version = 4, /* protocol version */ |
| 9412 | .dentry_ops = &nfs4_dentry_operations, |
| 9413 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9414 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9415 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9416 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9417 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9418 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9419 | .getattr = nfs4_proc_getattr, |
| 9420 | .setattr = nfs4_proc_setattr, |
| 9421 | .lookup = nfs4_proc_lookup, |
| 9422 | .access = nfs4_proc_access, |
| 9423 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9424 | .create = nfs4_proc_create, |
| 9425 | .remove = nfs4_proc_remove, |
| 9426 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9427 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9428 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9429 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9430 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9431 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9432 | .link = nfs4_proc_link, |
| 9433 | .symlink = nfs4_proc_symlink, |
| 9434 | .mkdir = nfs4_proc_mkdir, |
| 9435 | .rmdir = nfs4_proc_remove, |
| 9436 | .readdir = nfs4_proc_readdir, |
| 9437 | .mknod = nfs4_proc_mknod, |
| 9438 | .statfs = nfs4_proc_statfs, |
| 9439 | .fsinfo = nfs4_proc_fsinfo, |
| 9440 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9441 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9442 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9443 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9444 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9445 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9446 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9447 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9448 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9449 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9450 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9451 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9452 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9453 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9454 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9455 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9456 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9457 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9458 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9459 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9460 | .create_server = nfs4_create_server, |
| 9461 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9462 | }; |
| 9463 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9464 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9465 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9466 | .list = nfs4_xattr_list_nfs4_acl, |
| 9467 | .get = nfs4_xattr_get_nfs4_acl, |
| 9468 | .set = nfs4_xattr_set_nfs4_acl, |
| 9469 | }; |
| 9470 | |
| 9471 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9472 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9473 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9474 | &nfs4_xattr_nfs4_label_handler, |
| 9475 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9476 | NULL |
| 9477 | }; |
| 9478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | /* |
| 9480 | * Local variables: |
| 9481 | * c-basic-offset: 8 |
| 9482 | * End: |
| 9483 | */ |