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 | 035168ab | 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 | 035168ab | 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 | 035168ab | 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 | 035168ab | 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 | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1092 | if (cinfo->atomic && cinfo->before == dir->i_version) { |
| 1093 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
| 1094 | nfsi->attrtimeo_timestamp = jiffies; |
| 1095 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | e603a4c | 2016-12-16 16:55:55 -0500 | [diff] [blame] | 1097 | if (cinfo->before != dir->i_version) |
| 1098 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
| 1099 | NFS_INO_INVALID_ACL; |
| 1100 | } |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1101 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1102 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1103 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | spin_unlock(&dir->i_lock); |
| 1105 | } |
| 1106 | |
| 1107 | struct nfs4_opendata { |
| 1108 | struct kref kref; |
| 1109 | struct nfs_openargs o_arg; |
| 1110 | struct nfs_openres o_res; |
| 1111 | struct nfs_open_confirmargs c_arg; |
| 1112 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1113 | struct nfs4_string owner_name; |
| 1114 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1115 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1117 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1119 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | struct nfs4_state_owner *owner; |
| 1121 | struct nfs4_state *state; |
| 1122 | struct iattr attrs; |
| 1123 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1124 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1125 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1126 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1127 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | int cancelled; |
| 1129 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1130 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1131 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1132 | int err, struct nfs4_exception *exception) |
| 1133 | { |
| 1134 | if (err != -EINVAL) |
| 1135 | return false; |
| 1136 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1137 | return false; |
| 1138 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1139 | exception->retry = 1; |
| 1140 | return true; |
| 1141 | } |
| 1142 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1143 | static u32 |
| 1144 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1145 | fmode_t fmode, int openflags) |
| 1146 | { |
| 1147 | u32 res = 0; |
| 1148 | |
| 1149 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1150 | case FMODE_READ: |
| 1151 | res = NFS4_SHARE_ACCESS_READ; |
| 1152 | break; |
| 1153 | case FMODE_WRITE: |
| 1154 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1155 | break; |
| 1156 | case FMODE_READ|FMODE_WRITE: |
| 1157 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1158 | } |
| 1159 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1160 | goto out; |
| 1161 | /* Want no delegation if we're using O_DIRECT */ |
| 1162 | if (openflags & O_DIRECT) |
| 1163 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1164 | out: |
| 1165 | return res; |
| 1166 | } |
| 1167 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1168 | static enum open_claim_type4 |
| 1169 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1170 | enum open_claim_type4 claim) |
| 1171 | { |
| 1172 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1173 | return claim; |
| 1174 | switch (claim) { |
| 1175 | default: |
| 1176 | return claim; |
| 1177 | case NFS4_OPEN_CLAIM_FH: |
| 1178 | return NFS4_OPEN_CLAIM_NULL; |
| 1179 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1180 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1181 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1182 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1183 | } |
| 1184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
| 1186 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1187 | { |
| 1188 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1189 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1190 | p->o_res.seqid = p->o_arg.seqid; |
| 1191 | p->c_res.seqid = p->c_arg.seqid; |
| 1192 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1193 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1194 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1195 | 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] | 1196 | } |
| 1197 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1198 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1199 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1200 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1201 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1202 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1203 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1204 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1205 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1206 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1207 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1208 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1209 | struct nfs4_opendata *p; |
| 1210 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1211 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1212 | if (p == NULL) |
| 1213 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1214 | |
| 1215 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1216 | if (IS_ERR(p->f_label)) |
| 1217 | goto err_free_p; |
| 1218 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1219 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1220 | if (IS_ERR(p->a_label)) |
| 1221 | goto err_free_f; |
| 1222 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1223 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1224 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1225 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1226 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1227 | nfs_sb_active(dentry->d_sb); |
| 1228 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1229 | p->dir = parent; |
| 1230 | p->owner = sp; |
| 1231 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1232 | p->o_arg.open_flags = flags; |
| 1233 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 1234 | p->o_arg.umask = current_umask(); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1235 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1236 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1237 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1238 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1239 | * will return permission denied for all bits until close */ |
| 1240 | if (!(flags & O_EXCL)) { |
| 1241 | /* ask server to check for all possible rights as results |
| 1242 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1243 | switch (p->o_arg.claim) { |
| 1244 | default: |
| 1245 | break; |
| 1246 | case NFS4_OPEN_CLAIM_NULL: |
| 1247 | case NFS4_OPEN_CLAIM_FH: |
| 1248 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1249 | NFS4_ACCESS_MODIFY | |
| 1250 | NFS4_ACCESS_EXTEND | |
| 1251 | NFS4_ACCESS_EXECUTE; |
| 1252 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1253 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1254 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1255 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1256 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1257 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1258 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1259 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1260 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1261 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1262 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1263 | case NFS4_OPEN_CLAIM_NULL: |
| 1264 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1265 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1266 | p->o_arg.fh = NFS_FH(dir); |
| 1267 | break; |
| 1268 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1269 | case NFS4_OPEN_CLAIM_FH: |
| 1270 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1271 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1272 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1273 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1274 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1275 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1276 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1277 | p->o_arg.u.attrs = &p->attrs; |
| 1278 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1279 | |
| 1280 | verf[0] = jiffies; |
| 1281 | verf[1] = current->pid; |
| 1282 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1283 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1284 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1285 | p->c_arg.fh = &p->o_res.fh; |
| 1286 | p->c_arg.stateid = &p->o_res.stateid; |
| 1287 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1288 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1289 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1290 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1291 | |
| 1292 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1293 | nfs4_label_free(p->a_label); |
| 1294 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1295 | nfs4_label_free(p->f_label); |
| 1296 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1297 | kfree(p); |
| 1298 | err: |
| 1299 | dput(parent); |
| 1300 | return NULL; |
| 1301 | } |
| 1302 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1303 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1304 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1305 | struct nfs4_opendata *p = container_of(kref, |
| 1306 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1307 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1308 | |
| 1309 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1310 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1311 | if (p->state != NULL) |
| 1312 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1313 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1314 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1315 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1316 | nfs4_label_free(p->f_label); |
| 1317 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1318 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1319 | dput(p->dentry); |
| 1320 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1321 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1322 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1323 | kfree(p); |
| 1324 | } |
| 1325 | |
| 1326 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1327 | { |
| 1328 | if (p != NULL) |
| 1329 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1332 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1333 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1334 | int ret; |
| 1335 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1336 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1337 | return ret; |
| 1338 | } |
| 1339 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1340 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1341 | fmode_t fmode) |
| 1342 | { |
| 1343 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1344 | case FMODE_READ|FMODE_WRITE: |
| 1345 | return state->n_rdwr != 0; |
| 1346 | case FMODE_WRITE: |
| 1347 | return state->n_wronly != 0; |
| 1348 | case FMODE_READ: |
| 1349 | return state->n_rdonly != 0; |
| 1350 | } |
| 1351 | WARN_ON_ONCE(1); |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | 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] | 1356 | { |
| 1357 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1358 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1359 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1360 | goto out; |
| 1361 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1362 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1363 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1364 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1365 | break; |
| 1366 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1367 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1368 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1369 | break; |
| 1370 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1371 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1372 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1373 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1374 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1375 | return ret; |
| 1376 | } |
| 1377 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1378 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1379 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1380 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1381 | if (delegation == NULL) |
| 1382 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1384 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1385 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1386 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1387 | switch (claim) { |
| 1388 | case NFS4_OPEN_CLAIM_NULL: |
| 1389 | case NFS4_OPEN_CLAIM_FH: |
| 1390 | break; |
| 1391 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1392 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1393 | break; |
| 1394 | default: |
| 1395 | return 0; |
| 1396 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1397 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
| 1400 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1401 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1402 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1403 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1404 | case FMODE_WRITE: |
| 1405 | state->n_wronly++; |
| 1406 | break; |
| 1407 | case FMODE_READ: |
| 1408 | state->n_rdonly++; |
| 1409 | break; |
| 1410 | case FMODE_READ|FMODE_WRITE: |
| 1411 | state->n_rdwr++; |
| 1412 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1413 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1414 | } |
| 1415 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1416 | #ifdef CONFIG_NFS_V4_1 |
| 1417 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1418 | { |
| 1419 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1420 | return true; |
| 1421 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1422 | return true; |
| 1423 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1424 | return true; |
| 1425 | return false; |
| 1426 | } |
| 1427 | #endif /* CONFIG_NFS_V4_1 */ |
| 1428 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1429 | 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] | 1430 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1431 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1432 | bool need_recover = false; |
| 1433 | |
| 1434 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1435 | need_recover = true; |
| 1436 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1437 | need_recover = true; |
| 1438 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1439 | need_recover = true; |
| 1440 | if (need_recover) |
| 1441 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1442 | } |
| 1443 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1444 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1445 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1446 | { |
| 1447 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1448 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1449 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1450 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1451 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1452 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1453 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1454 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1455 | return true; |
| 1456 | return false; |
| 1457 | } |
| 1458 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1459 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1460 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1461 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1462 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1463 | if (state->n_wronly) |
| 1464 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1465 | if (state->n_rdonly) |
| 1466 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1467 | if (state->n_rdwr) |
| 1468 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1469 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1470 | } |
| 1471 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1472 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1473 | nfs4_stateid *stateid, fmode_t fmode) |
| 1474 | { |
| 1475 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1476 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1477 | case FMODE_WRITE: |
| 1478 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1479 | break; |
| 1480 | case FMODE_READ: |
| 1481 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1482 | break; |
| 1483 | case 0: |
| 1484 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1485 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1486 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1487 | } |
| 1488 | if (stateid == NULL) |
| 1489 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1490 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1491 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1492 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1493 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1494 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1495 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1496 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1497 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1498 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1501 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1502 | nfs4_stateid *arg_stateid, |
| 1503 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1504 | { |
| 1505 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1506 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1507 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1508 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1509 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1510 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1511 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1514 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1515 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1516 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1517 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1518 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1519 | case FMODE_READ: |
| 1520 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1521 | break; |
| 1522 | case FMODE_WRITE: |
| 1523 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1524 | break; |
| 1525 | case FMODE_READ|FMODE_WRITE: |
| 1526 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1527 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1528 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1529 | return; |
| 1530 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1531 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1532 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1535 | static void __update_open_stateid(struct nfs4_state *state, |
| 1536 | const nfs4_stateid *open_stateid, |
| 1537 | const nfs4_stateid *deleg_stateid, |
| 1538 | fmode_t fmode, |
| 1539 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1541 | /* |
| 1542 | * Protect the call to nfs4_state_set_mode_locked and |
| 1543 | * serialise the stateid update |
| 1544 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1545 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1546 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1547 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1548 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1549 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1550 | } |
| 1551 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1552 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1553 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1554 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1555 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1558 | static int update_open_stateid(struct nfs4_state *state, |
| 1559 | const nfs4_stateid *open_stateid, |
| 1560 | const nfs4_stateid *delegation, |
| 1561 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1562 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1563 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1564 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1565 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1566 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1567 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1568 | int ret = 0; |
| 1569 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1570 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1571 | |
| 1572 | rcu_read_lock(); |
| 1573 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1574 | if (deleg_cur == NULL) |
| 1575 | goto no_delegation; |
| 1576 | |
| 1577 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1578 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1579 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1580 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1581 | goto no_delegation_unlock; |
| 1582 | |
| 1583 | if (delegation == NULL) |
| 1584 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1585 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1586 | goto no_delegation_unlock; |
| 1587 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1588 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1589 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1590 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1591 | ret = 1; |
| 1592 | no_delegation_unlock: |
| 1593 | spin_unlock(&deleg_cur->lock); |
| 1594 | no_delegation: |
| 1595 | rcu_read_unlock(); |
| 1596 | |
| 1597 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1598 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1599 | ret = 1; |
| 1600 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1601 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1602 | nfs4_schedule_state_manager(clp); |
| 1603 | if (freeme.type != 0) |
| 1604 | nfs4_test_and_free_stateid(server, &freeme, |
| 1605 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1606 | |
| 1607 | return ret; |
| 1608 | } |
| 1609 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1610 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1611 | const nfs4_stateid *stateid) |
| 1612 | { |
| 1613 | struct nfs4_state *state = lsp->ls_state; |
| 1614 | bool ret = false; |
| 1615 | |
| 1616 | spin_lock(&state->state_lock); |
| 1617 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1618 | goto out_noupdate; |
| 1619 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1620 | goto out_noupdate; |
| 1621 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1622 | ret = true; |
| 1623 | out_noupdate: |
| 1624 | spin_unlock(&state->state_lock); |
| 1625 | return ret; |
| 1626 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1627 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1628 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1629 | { |
| 1630 | struct nfs_delegation *delegation; |
| 1631 | |
| 1632 | rcu_read_lock(); |
| 1633 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1634 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1635 | rcu_read_unlock(); |
| 1636 | return; |
| 1637 | } |
| 1638 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1639 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1642 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1643 | { |
| 1644 | struct nfs4_state *state = opendata->state; |
| 1645 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1646 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1647 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1648 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1649 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1650 | nfs4_stateid stateid; |
| 1651 | int ret = -EAGAIN; |
| 1652 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1653 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1654 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1655 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1656 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1657 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1658 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1659 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1660 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1661 | rcu_read_lock(); |
| 1662 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1663 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1664 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1665 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1666 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1667 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1668 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1670 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1671 | if (!opendata->is_recover) { |
| 1672 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1673 | if (ret != 0) |
| 1674 | goto out; |
| 1675 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1676 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1677 | |
| 1678 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1679 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1680 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1681 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | out: |
| 1683 | return ERR_PTR(ret); |
| 1684 | out_return_state: |
| 1685 | atomic_inc(&state->count); |
| 1686 | return state; |
| 1687 | } |
| 1688 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1689 | static void |
| 1690 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1691 | { |
| 1692 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1693 | struct nfs_delegation *delegation; |
| 1694 | int delegation_flags = 0; |
| 1695 | |
| 1696 | rcu_read_lock(); |
| 1697 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1698 | if (delegation) |
| 1699 | delegation_flags = delegation->flags; |
| 1700 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1701 | switch (data->o_arg.claim) { |
| 1702 | default: |
| 1703 | break; |
| 1704 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1705 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1706 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1707 | "returning a delegation for " |
| 1708 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1709 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1710 | return; |
| 1711 | } |
| 1712 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1713 | nfs_inode_set_delegation(state->inode, |
| 1714 | data->owner->so_cred, |
| 1715 | &data->o_res); |
| 1716 | else |
| 1717 | nfs_inode_reclaim_delegation(state->inode, |
| 1718 | data->owner->so_cred, |
| 1719 | &data->o_res); |
| 1720 | } |
| 1721 | |
| 1722 | /* |
| 1723 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1724 | * and update the nfs4_state. |
| 1725 | */ |
| 1726 | static struct nfs4_state * |
| 1727 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1728 | { |
| 1729 | struct inode *inode = data->state->inode; |
| 1730 | struct nfs4_state *state = data->state; |
| 1731 | int ret; |
| 1732 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1733 | if (!data->rpc_done) { |
| 1734 | if (data->rpc_status) { |
| 1735 | ret = data->rpc_status; |
| 1736 | goto err; |
| 1737 | } |
| 1738 | /* cached opens have already been processed */ |
| 1739 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1742 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1743 | if (ret) |
| 1744 | goto err; |
| 1745 | |
| 1746 | if (data->o_res.delegation_type != 0) |
| 1747 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1748 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1749 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1750 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1751 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1752 | |
| 1753 | return state; |
| 1754 | err: |
| 1755 | return ERR_PTR(ret); |
| 1756 | |
| 1757 | } |
| 1758 | |
| 1759 | static struct nfs4_state * |
| 1760 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1761 | { |
| 1762 | struct inode *inode; |
| 1763 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1764 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1765 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1766 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1767 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1768 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1769 | goto out; |
| 1770 | } |
| 1771 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1772 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1773 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1774 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1775 | 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] | 1776 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1777 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1778 | goto err; |
| 1779 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1780 | state = nfs4_get_open_state(inode, data->owner); |
| 1781 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1782 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1783 | if (data->o_res.delegation_type != 0) |
| 1784 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1785 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1786 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1787 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1788 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1789 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1790 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1791 | err_put_inode: |
| 1792 | iput(inode); |
| 1793 | err: |
| 1794 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1797 | static struct nfs4_state * |
| 1798 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1799 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1800 | struct nfs4_state *ret; |
| 1801 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1802 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1803 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1804 | else |
| 1805 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1806 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1807 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1810 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1811 | { |
| 1812 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1813 | struct nfs_open_context *ctx; |
| 1814 | |
| 1815 | spin_lock(&state->inode->i_lock); |
| 1816 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1817 | if (ctx->state != state) |
| 1818 | continue; |
| 1819 | get_nfs_open_context(ctx); |
| 1820 | spin_unlock(&state->inode->i_lock); |
| 1821 | return ctx; |
| 1822 | } |
| 1823 | spin_unlock(&state->inode->i_lock); |
| 1824 | return ERR_PTR(-ENOENT); |
| 1825 | } |
| 1826 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1827 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1828 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1829 | { |
| 1830 | struct nfs4_opendata *opendata; |
| 1831 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1832 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1833 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1834 | if (opendata == NULL) |
| 1835 | return ERR_PTR(-ENOMEM); |
| 1836 | opendata->state = state; |
| 1837 | atomic_inc(&state->count); |
| 1838 | return opendata; |
| 1839 | } |
| 1840 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1841 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1842 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1843 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1844 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1845 | int ret; |
| 1846 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1847 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1848 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1849 | opendata->o_arg.open_flags = 0; |
| 1850 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1851 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1852 | NFS_SB(opendata->dentry->d_sb), |
| 1853 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1854 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1855 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1856 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1857 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1858 | if (ret != 0) |
| 1859 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1860 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1861 | if (IS_ERR(newstate)) |
| 1862 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1863 | if (newstate != opendata->state) |
| 1864 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1865 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1866 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1870 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1871 | int ret; |
| 1872 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1873 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1874 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1875 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1876 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1877 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1878 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1879 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1880 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1881 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1882 | if (ret != 0) |
| 1883 | return ret; |
| 1884 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1885 | if (ret != 0) |
| 1886 | return ret; |
| 1887 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1888 | if (ret != 0) |
| 1889 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1890 | /* |
| 1891 | * We may have performed cached opens for all three recoveries. |
| 1892 | * Check if we need to update the current stateid. |
| 1893 | */ |
| 1894 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1895 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1896 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1897 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1898 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1899 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1900 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1901 | return 0; |
| 1902 | } |
| 1903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | /* |
| 1905 | * OPEN_RECLAIM: |
| 1906 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1908 | 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] | 1909 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1910 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1911 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1912 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | int status; |
| 1914 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1915 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1916 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1917 | if (IS_ERR(opendata)) |
| 1918 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1919 | rcu_read_lock(); |
| 1920 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1921 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1922 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1923 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1924 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1925 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1926 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return status; |
| 1928 | } |
| 1929 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1930 | 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] | 1931 | { |
| 1932 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1933 | struct nfs4_exception exception = { }; |
| 1934 | int err; |
| 1935 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1936 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1937 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1938 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1939 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1940 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1941 | break; |
| 1942 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } while (exception.retry); |
| 1944 | return err; |
| 1945 | } |
| 1946 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1947 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1948 | { |
| 1949 | struct nfs_open_context *ctx; |
| 1950 | int ret; |
| 1951 | |
| 1952 | ctx = nfs4_state_find_open_context(state); |
| 1953 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1954 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1955 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1956 | put_nfs_open_context(ctx); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1960 | 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] | 1961 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1962 | switch (err) { |
| 1963 | default: |
| 1964 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1965 | "%d.\n", __func__, err); |
| 1966 | case 0: |
| 1967 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1968 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1969 | case -ESTALE: |
| 1970 | break; |
| 1971 | case -NFS4ERR_BADSESSION: |
| 1972 | case -NFS4ERR_BADSLOT: |
| 1973 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1974 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1975 | case -NFS4ERR_DEADSESSION: |
| 1976 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1977 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1978 | return -EAGAIN; |
| 1979 | case -NFS4ERR_STALE_CLIENTID: |
| 1980 | case -NFS4ERR_STALE_STATEID: |
| 1981 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1982 | /* Don't recall a delegation if it was lost */ |
| 1983 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1984 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1985 | case -NFS4ERR_MOVED: |
| 1986 | nfs4_schedule_migration_recovery(server); |
| 1987 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1988 | case -NFS4ERR_LEASE_MOVED: |
| 1989 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1990 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1991 | case -NFS4ERR_DELEG_REVOKED: |
| 1992 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1993 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1994 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1995 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1996 | nfs_inode_find_state_and_recover(state->inode, |
| 1997 | stateid); |
| 1998 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1999 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2000 | case -NFS4ERR_DELAY: |
| 2001 | case -NFS4ERR_GRACE: |
| 2002 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2003 | ssleep(1); |
| 2004 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2005 | case -ENOMEM: |
| 2006 | case -NFS4ERR_DENIED: |
| 2007 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 2008 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 2009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | return err; |
| 2011 | } |
| 2012 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2013 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2014 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2015 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2016 | { |
| 2017 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2018 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2019 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2020 | |
| 2021 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2022 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2023 | if (IS_ERR(opendata)) |
| 2024 | return PTR_ERR(opendata); |
| 2025 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2026 | write_seqlock(&state->seqlock); |
| 2027 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2028 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2029 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2030 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2031 | case FMODE_READ|FMODE_WRITE: |
| 2032 | case FMODE_WRITE: |
| 2033 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2034 | if (err) |
| 2035 | break; |
| 2036 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2037 | if (err) |
| 2038 | break; |
| 2039 | case FMODE_READ: |
| 2040 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2041 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2042 | nfs4_opendata_put(opendata); |
| 2043 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2044 | } |
| 2045 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2046 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2047 | { |
| 2048 | struct nfs4_opendata *data = calldata; |
| 2049 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2050 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2051 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2052 | } |
| 2053 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2054 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2055 | { |
| 2056 | struct nfs4_opendata *data = calldata; |
| 2057 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2058 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2059 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2060 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2061 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2062 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2063 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2064 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2065 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2066 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static void nfs4_open_confirm_release(void *calldata) |
| 2070 | { |
| 2071 | struct nfs4_opendata *data = calldata; |
| 2072 | struct nfs4_state *state = NULL; |
| 2073 | |
| 2074 | /* If this request hasn't been cancelled, do nothing */ |
| 2075 | if (data->cancelled == 0) |
| 2076 | goto out_free; |
| 2077 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2078 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2079 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2080 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2081 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2082 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2083 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2084 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2088 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2089 | .rpc_call_done = nfs4_open_confirm_done, |
| 2090 | .rpc_release = nfs4_open_confirm_release, |
| 2091 | }; |
| 2092 | |
| 2093 | /* |
| 2094 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2095 | */ |
| 2096 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2097 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2098 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2099 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2100 | struct rpc_message msg = { |
| 2101 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2102 | .rpc_argp = &data->c_arg, |
| 2103 | .rpc_resp = &data->c_res, |
| 2104 | .rpc_cred = data->owner->so_cred, |
| 2105 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2106 | struct rpc_task_setup task_setup_data = { |
| 2107 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2108 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2109 | .callback_ops = &nfs4_open_confirm_ops, |
| 2110 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2111 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2112 | .flags = RPC_TASK_ASYNC, |
| 2113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | int status; |
| 2115 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2116 | 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] | 2117 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2118 | data->rpc_done = 0; |
| 2119 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2120 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2121 | if (data->is_recover) |
| 2122 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2123 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2124 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2125 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2126 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2127 | if (status != 0) { |
| 2128 | data->cancelled = 1; |
| 2129 | smp_wmb(); |
| 2130 | } else |
| 2131 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2132 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | return status; |
| 2134 | } |
| 2135 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2136 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2138 | struct nfs4_opendata *data = calldata; |
| 2139 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2140 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2141 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2144 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2145 | /* |
| 2146 | * Check if we still need to send an OPEN call, or if we can use |
| 2147 | * a delegation instead. |
| 2148 | */ |
| 2149 | if (data->state != NULL) { |
| 2150 | struct nfs_delegation *delegation; |
| 2151 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2152 | 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] | 2153 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2154 | rcu_read_lock(); |
| 2155 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2156 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2157 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2158 | rcu_read_unlock(); |
| 2159 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2160 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2161 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2162 | switch (claim) { |
| 2163 | default: |
| 2164 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2165 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2166 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2167 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2168 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2169 | case NFS4_OPEN_CLAIM_FH: |
| 2170 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2171 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2172 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2173 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2174 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2175 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2176 | &data->o_res.seq_res, |
| 2177 | task) != 0) |
| 2178 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2179 | |
| 2180 | /* Set the create mode (note dependency on the session type) */ |
| 2181 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2182 | if (data->o_arg.open_flags & O_EXCL) { |
| 2183 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2184 | if (nfs4_has_persistent_session(clp)) |
| 2185 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2186 | else if (clp->cl_mvops->minor_version > 0) |
| 2187 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2188 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2189 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2190 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2191 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2192 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2193 | out_no_action: |
| 2194 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2195 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2196 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2197 | } |
| 2198 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2199 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2200 | { |
| 2201 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2203 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2204 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2205 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2206 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2207 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2208 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2209 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2210 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2211 | case S_IFREG: |
| 2212 | break; |
| 2213 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2214 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2215 | break; |
| 2216 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2217 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2218 | break; |
| 2219 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2220 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2221 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2222 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2223 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2224 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2225 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2226 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2227 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2228 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2229 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2230 | static void nfs4_open_release(void *calldata) |
| 2231 | { |
| 2232 | struct nfs4_opendata *data = calldata; |
| 2233 | struct nfs4_state *state = NULL; |
| 2234 | |
| 2235 | /* If this request hasn't been cancelled, do nothing */ |
| 2236 | if (data->cancelled == 0) |
| 2237 | goto out_free; |
| 2238 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2239 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2240 | goto out_free; |
| 2241 | /* In case we need an open_confirm, no cleanup! */ |
| 2242 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2243 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2244 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2245 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2246 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2247 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2248 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2252 | .rpc_call_prepare = nfs4_open_prepare, |
| 2253 | .rpc_call_done = nfs4_open_done, |
| 2254 | .rpc_release = nfs4_open_release, |
| 2255 | }; |
| 2256 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2257 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2258 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2259 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2260 | struct nfs_server *server = NFS_SERVER(dir); |
| 2261 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2262 | struct nfs_openres *o_res = &data->o_res; |
| 2263 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2264 | struct rpc_message msg = { |
| 2265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2266 | .rpc_argp = o_arg, |
| 2267 | .rpc_resp = o_res, |
| 2268 | .rpc_cred = data->owner->so_cred, |
| 2269 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2270 | struct rpc_task_setup task_setup_data = { |
| 2271 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2272 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2273 | .callback_ops = &nfs4_open_ops, |
| 2274 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2275 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2276 | .flags = RPC_TASK_ASYNC, |
| 2277 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2278 | int status; |
| 2279 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2280 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2281 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2282 | data->rpc_done = 0; |
| 2283 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2284 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2285 | data->is_recover = 0; |
| 2286 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2287 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2288 | data->is_recover = 1; |
| 2289 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2290 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2291 | if (IS_ERR(task)) |
| 2292 | return PTR_ERR(task); |
| 2293 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2294 | if (status != 0) { |
| 2295 | data->cancelled = 1; |
| 2296 | smp_wmb(); |
| 2297 | } else |
| 2298 | status = data->rpc_status; |
| 2299 | rpc_put_task(task); |
| 2300 | |
| 2301 | return status; |
| 2302 | } |
| 2303 | |
| 2304 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2305 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2306 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2307 | struct nfs_openres *o_res = &data->o_res; |
| 2308 | int status; |
| 2309 | |
| 2310 | status = nfs4_run_open_task(data, 1); |
| 2311 | if (status != 0 || !data->rpc_done) |
| 2312 | return status; |
| 2313 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2314 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2315 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2316 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2317 | status = _nfs4_proc_open_confirm(data); |
| 2318 | if (status != 0) |
| 2319 | return status; |
| 2320 | } |
| 2321 | |
| 2322 | return status; |
| 2323 | } |
| 2324 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2325 | /* |
| 2326 | * Additional permission checks in order to distinguish between an |
| 2327 | * open for read, and an open for execute. This works around the |
| 2328 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2329 | * the same. |
| 2330 | * Note that in the non-execute case, we want to turn off permission |
| 2331 | * checking if we just created a new file (POSIX open() semantics). |
| 2332 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2333 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2334 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2335 | struct nfs4_state *state, fmode_t fmode, |
| 2336 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2337 | { |
| 2338 | struct nfs_access_entry cache; |
| 2339 | u32 mask; |
| 2340 | |
| 2341 | /* access call failed or for some reason the server doesn't |
| 2342 | * support any access modes -- defer access call until later */ |
| 2343 | if (opendata->o_res.access_supported == 0) |
| 2344 | return 0; |
| 2345 | |
| 2346 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2347 | /* |
| 2348 | * Use openflags to check for exec, because fmode won't |
| 2349 | * always have FMODE_EXEC set when file open for exec. |
| 2350 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2351 | if (openflags & __FMODE_EXEC) { |
| 2352 | /* ONLY check for exec rights */ |
| 2353 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2354 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2355 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2356 | |
| 2357 | cache.cred = cred; |
| 2358 | cache.jiffies = jiffies; |
| 2359 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2360 | nfs_access_add_cache(state->inode, &cache); |
| 2361 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2362 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2363 | return 0; |
| 2364 | |
| 2365 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2366 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2367 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2368 | } |
| 2369 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2370 | /* |
| 2371 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2372 | */ |
| 2373 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2374 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2375 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2376 | struct nfs_server *server = NFS_SERVER(dir); |
| 2377 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2378 | struct nfs_openres *o_res = &data->o_res; |
| 2379 | int status; |
| 2380 | |
| 2381 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2382 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2383 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2384 | if (status != 0) { |
| 2385 | if (status == -NFS4ERR_BADNAME && |
| 2386 | !(o_arg->open_flags & O_CREAT)) |
| 2387 | return -ENOENT; |
| 2388 | return status; |
| 2389 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2390 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2391 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2392 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2393 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2394 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2395 | if (o_arg->open_flags & O_EXCL) |
| 2396 | data->file_created = 1; |
| 2397 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2398 | data->file_created = 1; |
| 2399 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2400 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2401 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2403 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2405 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
| 2407 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2408 | 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] | 2409 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2412 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2413 | { |
| 2414 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2415 | } |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | /* |
| 2418 | * OPEN_EXPIRED: |
| 2419 | * reclaim state on the server after a network partition. |
| 2420 | * Assumes caller holds the appropriate lock |
| 2421 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2422 | 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] | 2423 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2424 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2425 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2427 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2428 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2429 | if (IS_ERR(opendata)) |
| 2430 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2431 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2432 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2433 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2434 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2435 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2438 | 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] | 2439 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2440 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2441 | struct nfs4_exception exception = { }; |
| 2442 | int err; |
| 2443 | |
| 2444 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2445 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2446 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2447 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2448 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2449 | switch (err) { |
| 2450 | default: |
| 2451 | goto out; |
| 2452 | case -NFS4ERR_GRACE: |
| 2453 | case -NFS4ERR_DELAY: |
| 2454 | nfs4_handle_exception(server, err, &exception); |
| 2455 | err = 0; |
| 2456 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2457 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2458 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2459 | return err; |
| 2460 | } |
| 2461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2463 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2465 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2467 | ctx = nfs4_state_find_open_context(state); |
| 2468 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2469 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2470 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2471 | put_nfs_open_context(ctx); |
| 2472 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2475 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2476 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2477 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2478 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2479 | write_seqlock(&state->seqlock); |
| 2480 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2481 | write_sequnlock(&state->seqlock); |
| 2482 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2483 | } |
| 2484 | |
| 2485 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2486 | { |
| 2487 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2488 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2492 | { |
| 2493 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2494 | nfs40_clear_delegation_stateid(state); |
| 2495 | return nfs4_open_expired(sp, state); |
| 2496 | } |
| 2497 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2498 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2499 | nfs4_stateid *stateid, |
| 2500 | struct rpc_cred *cred) |
| 2501 | { |
| 2502 | return -NFS4ERR_BAD_STATEID; |
| 2503 | } |
| 2504 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2505 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2506 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2507 | nfs4_stateid *stateid, |
| 2508 | struct rpc_cred *cred) |
| 2509 | { |
| 2510 | int status; |
| 2511 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2512 | switch (stateid->type) { |
| 2513 | default: |
| 2514 | break; |
| 2515 | case NFS4_INVALID_STATEID_TYPE: |
| 2516 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2517 | return -NFS4ERR_BAD_STATEID; |
| 2518 | case NFS4_REVOKED_STATEID_TYPE: |
| 2519 | goto out_free; |
| 2520 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2521 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2522 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2523 | switch (status) { |
| 2524 | case -NFS4ERR_EXPIRED: |
| 2525 | case -NFS4ERR_ADMIN_REVOKED: |
| 2526 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2527 | break; |
| 2528 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2529 | return status; |
| 2530 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2531 | out_free: |
| 2532 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2533 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2534 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2537 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2538 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2539 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2540 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2541 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2542 | struct rpc_cred *cred; |
| 2543 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2544 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2545 | /* Get the delegation credential for use by test/free_stateid */ |
| 2546 | rcu_read_lock(); |
| 2547 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2548 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2549 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2550 | return; |
| 2551 | } |
| 2552 | |
| 2553 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2554 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2555 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2556 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2557 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2558 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2559 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2560 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2561 | rcu_read_unlock(); |
| 2562 | return; |
| 2563 | } |
| 2564 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2565 | cred = get_rpccred(delegation->cred); |
| 2566 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2567 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2568 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2569 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2570 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2571 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2572 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2576 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2577 | * |
| 2578 | * @state: NFSv4 state for an inode |
| 2579 | * |
| 2580 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2581 | * Otherwise a negative NFS4ERR value is returned. |
| 2582 | */ |
| 2583 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2584 | { |
| 2585 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2586 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2587 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2588 | |
| 2589 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2590 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2591 | |
| 2592 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2593 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2594 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2595 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2596 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2597 | atomic_inc(&lsp->ls_count); |
| 2598 | spin_unlock(&state->state_lock); |
| 2599 | |
| 2600 | nfs4_put_lock_state(prev); |
| 2601 | prev = lsp; |
| 2602 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2603 | status = nfs41_test_and_free_expired_stateid(server, |
| 2604 | &lsp->ls_stateid, |
| 2605 | cred); |
| 2606 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2607 | if (status == -NFS4ERR_EXPIRED || |
| 2608 | status == -NFS4ERR_BAD_STATEID) { |
| 2609 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2610 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2611 | if (!recover_lost_locks) |
| 2612 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2613 | } else if (status != NFS_OK) { |
| 2614 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2615 | nfs4_put_lock_state(prev); |
| 2616 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2617 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2618 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2619 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2620 | } |
| 2621 | spin_unlock(&state->state_lock); |
| 2622 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2623 | out: |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
| 2627 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2629 | * |
| 2630 | * @state: NFSv4 state for an inode |
| 2631 | * |
| 2632 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2633 | * Otherwise a negative NFS4ERR value is returned. |
| 2634 | */ |
| 2635 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2636 | { |
| 2637 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2638 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2639 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2640 | int status; |
| 2641 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2642 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2643 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2644 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2645 | return NFS_OK; |
| 2646 | return -NFS4ERR_OPENMODE; |
| 2647 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2648 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2649 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2650 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2651 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2652 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2653 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2654 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2655 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2656 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2657 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2658 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2659 | if (status != NFS_OK) |
| 2660 | return status; |
| 2661 | if (nfs_open_stateid_recover_openmode(state)) |
| 2662 | return -NFS4ERR_OPENMODE; |
| 2663 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2667 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2668 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2669 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2670 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2671 | status = nfs41_check_expired_locks(state); |
| 2672 | if (status != NFS_OK) |
| 2673 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2674 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2675 | if (status != NFS_OK) |
| 2676 | status = nfs4_open_expired(sp, state); |
| 2677 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2678 | } |
| 2679 | #endif |
| 2680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2682 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2683 | * fields corresponding to attributes that were used to store the verifier. |
| 2684 | * Make sure we clobber those fields in the later setattr call |
| 2685 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2686 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2687 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2688 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2689 | const u32 *attrset = opendata->o_res.attrset; |
| 2690 | |
| 2691 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2692 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2693 | sattr->ia_valid |= ATTR_ATIME; |
| 2694 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2695 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2696 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2697 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2698 | |
| 2699 | /* Except MODE, it seems harmless of setting twice. */ |
| 2700 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2701 | sattr->ia_valid &= ~ATTR_MODE; |
| 2702 | |
| 2703 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2704 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2705 | } |
| 2706 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2707 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2708 | fmode_t fmode, |
| 2709 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2710 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2711 | { |
| 2712 | struct nfs4_state_owner *sp = opendata->owner; |
| 2713 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2714 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2715 | struct nfs4_state *state; |
| 2716 | unsigned int seq; |
| 2717 | int ret; |
| 2718 | |
| 2719 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2720 | |
| 2721 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2722 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2723 | goto out; |
| 2724 | |
| 2725 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2726 | ret = PTR_ERR(state); |
| 2727 | if (IS_ERR(state)) |
| 2728 | goto out; |
| 2729 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2730 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2731 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2732 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2733 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2734 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2735 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2736 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2737 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2738 | alias = d_exact_alias(dentry, state->inode); |
| 2739 | if (!alias) |
| 2740 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2741 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2742 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2743 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2744 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2745 | } |
| 2746 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2747 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2748 | } |
| 2749 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2750 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2751 | if (ret != 0) |
| 2752 | goto out; |
| 2753 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2754 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2755 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2756 | nfs_inode_attach_open_context(ctx); |
| 2757 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2758 | nfs4_schedule_stateid_recovery(server, state); |
| 2759 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2760 | out: |
| 2761 | return ret; |
| 2762 | } |
| 2763 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2764 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2765 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2767 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2768 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2769 | int flags, |
| 2770 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2771 | struct nfs4_label *label, |
| 2772 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | { |
| 2774 | struct nfs4_state_owner *sp; |
| 2775 | struct nfs4_state *state = NULL; |
| 2776 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2777 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2778 | struct dentry *dentry = ctx->dentry; |
| 2779 | struct rpc_cred *cred = ctx->cred; |
| 2780 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2781 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2782 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2783 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2784 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
| 2786 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2788 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2789 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2791 | goto out_err; |
| 2792 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2793 | status = nfs4_recover_expired_lease(server); |
| 2794 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2795 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2796 | if (d_really_is_positive(dentry)) |
| 2797 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2798 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2799 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2800 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2801 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2802 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2803 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2804 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2806 | if (label) { |
| 2807 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2808 | if (IS_ERR(olabel)) { |
| 2809 | status = PTR_ERR(olabel); |
| 2810 | goto err_opendata_put; |
| 2811 | } |
| 2812 | } |
| 2813 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2814 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2815 | if (!opendata->f_attr.mdsthreshold) { |
| 2816 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2817 | if (!opendata->f_attr.mdsthreshold) |
| 2818 | goto err_free_label; |
| 2819 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2820 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2821 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2822 | if (d_really_is_positive(dentry)) |
| 2823 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2824 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2825 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2826 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2827 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2828 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2829 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2830 | 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] | 2831 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2832 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2833 | /* |
| 2834 | * send create attributes which was not set by open |
| 2835 | * with an extra setattr. |
| 2836 | */ |
| 2837 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2838 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2839 | status = nfs4_do_setattr(state->inode, cred, |
| 2840 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2841 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2842 | if (status == 0) { |
| 2843 | nfs_setattr_update_inode(state->inode, sattr, |
| 2844 | opendata->o_res.f_attr); |
| 2845 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2846 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2847 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2848 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2849 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2850 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2851 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2852 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2853 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2854 | opendata->f_attr.mdsthreshold = NULL; |
| 2855 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2856 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2857 | nfs4_label_free(olabel); |
| 2858 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2859 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2862 | err_free_label: |
| 2863 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2864 | err_opendata_put: |
| 2865 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2866 | err_put_state_owner: |
| 2867 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | return status; |
| 2870 | } |
| 2871 | |
| 2872 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2873 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2874 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2875 | int flags, |
| 2876 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2877 | struct nfs4_label *label, |
| 2878 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2880 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | struct nfs4_exception exception = { }; |
| 2882 | struct nfs4_state *res; |
| 2883 | int status; |
| 2884 | |
| 2885 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2886 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2887 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2888 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | if (status == 0) |
| 2890 | break; |
| 2891 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2892 | * book-keeping w.r.t. state-changing operations |
| 2893 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2894 | * It is actually a sign of a bug on the client or on the server. |
| 2895 | * |
| 2896 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2897 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | * have unhashed the old state_owner for us, and that we can |
| 2899 | * therefore safely retry using a new one. We should still warn |
| 2900 | * the user though... |
| 2901 | */ |
| 2902 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2903 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2904 | " returned a bad sequence-id error!\n", |
| 2905 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | exception.retry = 1; |
| 2907 | continue; |
| 2908 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2909 | /* |
| 2910 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2911 | * state before it received the OPEN_CONFIRM. |
| 2912 | * Recover by retrying the request as per the discussion |
| 2913 | * on Page 181 of RFC3530. |
| 2914 | */ |
| 2915 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2916 | exception.retry = 1; |
| 2917 | continue; |
| 2918 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2919 | if (status == -EAGAIN) { |
| 2920 | /* We must have found a delegation */ |
| 2921 | exception.retry = 1; |
| 2922 | continue; |
| 2923 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2924 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2925 | continue; |
| 2926 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | status, &exception)); |
| 2928 | } while (exception.retry); |
| 2929 | return res; |
| 2930 | } |
| 2931 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2932 | static int _nfs4_do_setattr(struct inode *inode, |
| 2933 | struct nfs_setattrargs *arg, |
| 2934 | struct nfs_setattrres *res, |
| 2935 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2936 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2937 | { |
| 2938 | struct nfs_server *server = NFS_SERVER(inode); |
| 2939 | struct rpc_message msg = { |
| 2940 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2941 | .rpc_argp = arg, |
| 2942 | .rpc_resp = res, |
| 2943 | .rpc_cred = cred, |
| 2944 | }; |
| 2945 | struct rpc_cred *delegation_cred = NULL; |
| 2946 | unsigned long timestamp = jiffies; |
| 2947 | fmode_t fmode; |
| 2948 | bool truncate; |
| 2949 | int status; |
| 2950 | |
| 2951 | nfs_fattr_init(res->fattr); |
| 2952 | |
| 2953 | /* Servers should only apply open mode checks for file size changes */ |
| 2954 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2955 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2956 | |
| 2957 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2958 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2959 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2960 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2961 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2962 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2963 | l_ctx = nfs_get_lock_context(ctx); |
| 2964 | if (IS_ERR(l_ctx)) |
| 2965 | return PTR_ERR(l_ctx); |
NeilBrown | 7a0566b | 2016-12-06 15:50:06 -0500 | [diff] [blame] | 2966 | status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
| 2967 | &arg->stateid, &delegation_cred); |
| 2968 | nfs_put_lock_context(l_ctx); |
| 2969 | if (status == -EIO) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2970 | return -EBADF; |
| 2971 | } else |
| 2972 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2973 | if (delegation_cred) |
| 2974 | msg.rpc_cred = delegation_cred; |
| 2975 | |
| 2976 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2977 | |
| 2978 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2979 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2980 | renew_lease(server, timestamp); |
| 2981 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2982 | return status; |
| 2983 | } |
| 2984 | |
| 2985 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2986 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2987 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2988 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2990 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2991 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2993 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | .iap = sattr, |
| 2995 | .server = server, |
| 2996 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2997 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | }; |
| 2999 | struct nfs_setattrres res = { |
| 3000 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3001 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | .server = server, |
| 3003 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 3004 | struct nfs4_exception exception = { |
| 3005 | .state = state, |
| 3006 | .inode = inode, |
| 3007 | .stateid = &arg.stateid, |
| 3008 | }; |
| 3009 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3011 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 3012 | if (ilabel) |
| 3013 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3016 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3017 | switch (err) { |
| 3018 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3019 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3020 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3021 | "applying open mode checks to " |
| 3022 | "a SETATTR that is not " |
| 3023 | "changing file size.\n", |
| 3024 | server->nfs_client->cl_hostname); |
| 3025 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3026 | if (state && !(state->state & FMODE_WRITE)) { |
| 3027 | err = -EBADF; |
| 3028 | if (sattr->ia_valid & ATTR_OPEN) |
| 3029 | err = -EACCES; |
| 3030 | goto out; |
| 3031 | } |
| 3032 | } |
| 3033 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3035 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | return err; |
| 3037 | } |
| 3038 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3039 | static bool |
| 3040 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3041 | { |
| 3042 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3043 | return false; |
| 3044 | |
| 3045 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3046 | } |
| 3047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | struct nfs4_closedata { |
| 3049 | struct inode *inode; |
| 3050 | struct nfs4_state *state; |
| 3051 | struct nfs_closeargs arg; |
| 3052 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3053 | struct { |
| 3054 | struct nfs4_layoutreturn_args arg; |
| 3055 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3056 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3057 | u32 roc_barrier; |
| 3058 | bool roc; |
| 3059 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3060 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3061 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | }; |
| 3063 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3064 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3065 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3066 | struct nfs4_closedata *calldata = data; |
| 3067 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3068 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3069 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3070 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3071 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3072 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3073 | nfs4_put_open_state(calldata->state); |
| 3074 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3075 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3076 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3077 | kfree(calldata); |
| 3078 | } |
| 3079 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3080 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3082 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3085 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3087 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3088 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3089 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3090 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3091 | |
| 3092 | /* Handle Layoutreturn errors */ |
| 3093 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3094 | switch (calldata->res.lr_ret) { |
| 3095 | default: |
| 3096 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3097 | break; |
| 3098 | case 0: |
| 3099 | calldata->arg.lr_args = NULL; |
| 3100 | calldata->res.lr_res = NULL; |
| 3101 | break; |
| 3102 | case -NFS4ERR_ADMIN_REVOKED: |
| 3103 | case -NFS4ERR_DELEG_REVOKED: |
| 3104 | case -NFS4ERR_EXPIRED: |
| 3105 | case -NFS4ERR_BAD_STATEID: |
| 3106 | case -NFS4ERR_OLD_STATEID: |
| 3107 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3108 | case -NFS4ERR_WRONG_CRED: |
| 3109 | calldata->arg.lr_args = NULL; |
| 3110 | calldata->res.lr_res = NULL; |
| 3111 | calldata->res.lr_ret = 0; |
| 3112 | rpc_restart_call_prepare(task); |
| 3113 | return; |
| 3114 | } |
| 3115 | } |
| 3116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | /* hmm. we are done with the inode, and in the process of freeing |
| 3118 | * the state_owner. we keep this around to process errors |
| 3119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | switch (task->tk_status) { |
| 3121 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3122 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3123 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3124 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3125 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3127 | case -NFS4ERR_EXPIRED: |
| 3128 | nfs4_free_revoked_stateid(server, |
| 3129 | &calldata->arg.stateid, |
| 3130 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3131 | case -NFS4ERR_OLD_STATEID: |
| 3132 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3133 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3134 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3135 | rpc_restart_call_prepare(task); |
| 3136 | goto out_release; |
| 3137 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3138 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3139 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3141 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3142 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3143 | goto out_release; |
| 3144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3146 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3147 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3148 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3149 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3150 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3151 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3154 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3156 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3157 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3158 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3159 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3160 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3161 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3162 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3163 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3164 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3165 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3166 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3167 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3168 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3169 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3170 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3171 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3172 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3173 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3174 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3175 | if (state->n_rdonly == 0) |
| 3176 | call_close |= is_rdonly; |
| 3177 | else if (is_rdonly) |
| 3178 | calldata->arg.fmode |= FMODE_READ; |
| 3179 | if (state->n_wronly == 0) |
| 3180 | call_close |= is_wronly; |
| 3181 | else if (is_wronly) |
| 3182 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3183 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3184 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3185 | } else if (is_rdwr) |
| 3186 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3187 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3188 | if (!nfs4_valid_open_stateid(state) || |
| 3189 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3190 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3191 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3192 | |
| 3193 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3194 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3195 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3196 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3197 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3198 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3199 | nfs_release_seqid(calldata->arg.seqid); |
| 3200 | goto out_wait; |
| 3201 | } |
| 3202 | |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3203 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3204 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3205 | |
| 3206 | /* Close-to-open cache consistency revalidation */ |
| 3207 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3208 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3209 | else |
| 3210 | calldata->arg.bitmask = NULL; |
| 3211 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3212 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3213 | calldata->arg.share_access = |
| 3214 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3215 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3216 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3217 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3218 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3219 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3220 | &calldata->arg.seq_args, |
| 3221 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3222 | task) != 0) |
| 3223 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3224 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3225 | return; |
| 3226 | out_no_action: |
| 3227 | task->tk_action = NULL; |
| 3228 | out_wait: |
| 3229 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3232 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3233 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3234 | .rpc_call_done = nfs4_close_done, |
| 3235 | .rpc_release = nfs4_free_closedata, |
| 3236 | }; |
| 3237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | /* |
| 3239 | * It is possible for data to be read/written from a mem-mapped file |
| 3240 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3241 | * This means that we can't safely call nfsv4 close on a file until |
| 3242 | * the inode is cleared. This in turn means that we are not good |
| 3243 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3244 | * share state even when we are done with one of the three share |
| 3245 | * stateid's in the inode. |
| 3246 | * |
| 3247 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3248 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3249 | 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] | 3250 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3251 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3252 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3254 | struct nfs4_state_owner *sp = state->owner; |
| 3255 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3256 | struct rpc_message msg = { |
| 3257 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3258 | .rpc_cred = state->owner->so_cred, |
| 3259 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3260 | struct rpc_task_setup task_setup_data = { |
| 3261 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3262 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3263 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3264 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3265 | .flags = RPC_TASK_ASYNC, |
| 3266 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3267 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3269 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3270 | &task_setup_data.rpc_client, &msg); |
| 3271 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3272 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3274 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3275 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3276 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3278 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3280 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3281 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3282 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3283 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3284 | calldata->arg.fmode = 0; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 3285 | calldata->lr.arg.ld_private = &calldata->lr.ld_private; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3286 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3287 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3288 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3289 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3290 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3291 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3292 | if (calldata->lr.roc) { |
| 3293 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3294 | calldata->res.lr_res = &calldata->lr.res; |
| 3295 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3296 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3297 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3298 | msg.rpc_argp = &calldata->arg; |
| 3299 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3300 | task_setup_data.callback_data = calldata; |
| 3301 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3302 | if (IS_ERR(task)) |
| 3303 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3304 | status = 0; |
| 3305 | if (wait) |
| 3306 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3307 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3308 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3309 | out_free_calldata: |
| 3310 | kfree(calldata); |
| 3311 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3312 | nfs4_put_open_state(state); |
| 3313 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3314 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3317 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3318 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3319 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3322 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3323 | |
| 3324 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3326 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3327 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3328 | |
| 3329 | nfs4_label_release_security(label); |
| 3330 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3331 | if (IS_ERR(state)) |
| 3332 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3333 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3336 | 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] | 3337 | { |
| 3338 | if (ctx->state == NULL) |
| 3339 | return; |
| 3340 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3341 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3342 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3343 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3346 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3347 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 3348 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3351 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3352 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3353 | struct nfs4_server_caps_arg args = { |
| 3354 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3355 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3356 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | struct nfs4_server_caps_res res = {}; |
| 3358 | struct rpc_message msg = { |
| 3359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3360 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | .rpc_resp = &res, |
| 3362 | }; |
| 3363 | int status; |
| 3364 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3365 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3366 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3367 | FATTR4_WORD0_LINK_SUPPORT | |
| 3368 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3369 | FATTR4_WORD0_ACLSUPPORT; |
| 3370 | if (minorversion) |
| 3371 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3372 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3373 | 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] | 3374 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3375 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3376 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3377 | case 0: |
| 3378 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3379 | res.attr_bitmask[2] = 0; |
| 3380 | break; |
| 3381 | case 1: |
| 3382 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3383 | break; |
| 3384 | case 2: |
| 3385 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3388 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3389 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3390 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3391 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3392 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3393 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3394 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3395 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | server->caps |= NFS_CAP_ACLS; |
| 3397 | if (res.has_links != 0) |
| 3398 | server->caps |= NFS_CAP_HARDLINKS; |
| 3399 | if (res.has_symlinks != 0) |
| 3400 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3401 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3402 | server->caps |= NFS_CAP_FILEID; |
| 3403 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3404 | server->caps |= NFS_CAP_MODE; |
| 3405 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3406 | server->caps |= NFS_CAP_NLINK; |
| 3407 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3408 | server->caps |= NFS_CAP_OWNER; |
| 3409 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3410 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3411 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3412 | server->caps |= NFS_CAP_ATIME; |
| 3413 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3414 | server->caps |= NFS_CAP_CTIME; |
| 3415 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3416 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3417 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3418 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3419 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3420 | #endif |
| 3421 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3422 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3423 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3424 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3425 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3426 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3427 | 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] | 3428 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3429 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3430 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3432 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | return status; |
| 3436 | } |
| 3437 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3438 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | { |
| 3440 | struct nfs4_exception exception = { }; |
| 3441 | int err; |
| 3442 | do { |
| 3443 | err = nfs4_handle_exception(server, |
| 3444 | _nfs4_server_capabilities(server, fhandle), |
| 3445 | &exception); |
| 3446 | } while (exception.retry); |
| 3447 | return err; |
| 3448 | } |
| 3449 | |
| 3450 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3451 | struct nfs_fsinfo *info) |
| 3452 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3453 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3455 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | }; |
| 3457 | struct nfs4_lookup_res res = { |
| 3458 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3459 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | .fh = fhandle, |
| 3461 | }; |
| 3462 | struct rpc_message msg = { |
| 3463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3464 | .rpc_argp = &args, |
| 3465 | .rpc_resp = &res, |
| 3466 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3467 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3468 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3469 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3470 | /* |
| 3471 | * Process the label in the upcoming getfattr |
| 3472 | */ |
| 3473 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3474 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3475 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3476 | 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] | 3477 | } |
| 3478 | |
| 3479 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3480 | struct nfs_fsinfo *info) |
| 3481 | { |
| 3482 | struct nfs4_exception exception = { }; |
| 3483 | int err; |
| 3484 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3485 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3486 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3487 | switch (err) { |
| 3488 | case 0: |
| 3489 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3490 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3491 | default: |
| 3492 | err = nfs4_handle_exception(server, err, &exception); |
| 3493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3495 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | return err; |
| 3497 | } |
| 3498 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3499 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3500 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3501 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3502 | struct rpc_auth_create_args auth_args = { |
| 3503 | .pseudoflavor = flavor, |
| 3504 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3505 | struct rpc_auth *auth; |
| 3506 | int ret; |
| 3507 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3508 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3509 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3510 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3511 | goto out; |
| 3512 | } |
| 3513 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3514 | out: |
| 3515 | return ret; |
| 3516 | } |
| 3517 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3518 | /* |
| 3519 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3520 | * |
| 3521 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3522 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3523 | * |
| 3524 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3525 | * negative errno value. |
| 3526 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3527 | 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] | 3528 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3530 | /* Per 3530bis 15.33.5 */ |
| 3531 | static const rpc_authflavor_t flav_array[] = { |
| 3532 | RPC_AUTH_GSS_KRB5P, |
| 3533 | RPC_AUTH_GSS_KRB5I, |
| 3534 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3535 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3536 | RPC_AUTH_NULL, |
| 3537 | }; |
| 3538 | int status = -EPERM; |
| 3539 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3541 | if (server->auth_info.flavor_len > 0) { |
| 3542 | /* try each flavor specified by user */ |
| 3543 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3544 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3545 | server->auth_info.flavors[i]); |
| 3546 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3547 | continue; |
| 3548 | break; |
| 3549 | } |
| 3550 | } else { |
| 3551 | /* no flavors specified by user, try default list */ |
| 3552 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3553 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3554 | flav_array[i]); |
| 3555 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3556 | continue; |
| 3557 | break; |
| 3558 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3559 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3560 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3561 | /* |
| 3562 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3563 | * to access the mount. It could also mean that we tried to mount |
| 3564 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3565 | * existing mount programs don't handle -EACCES very well so it should |
| 3566 | * be mapped to -EPERM instead. |
| 3567 | */ |
| 3568 | if (status == -EACCES) |
| 3569 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3570 | return status; |
| 3571 | } |
| 3572 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3573 | /** |
| 3574 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3575 | * @server: initialized nfs_server handle |
| 3576 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3577 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3578 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3579 | * |
| 3580 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3581 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3582 | 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] | 3583 | struct nfs_fsinfo *info, |
| 3584 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3585 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3586 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3587 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3588 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3589 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3590 | |
| 3591 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3592 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3593 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | if (status == 0) |
| 3596 | status = nfs4_server_capabilities(server, fhandle); |
| 3597 | if (status == 0) |
| 3598 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3599 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3600 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3603 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3604 | struct nfs_fsinfo *info) |
| 3605 | { |
| 3606 | int error; |
| 3607 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3609 | |
| 3610 | error = nfs4_server_capabilities(server, mntfh); |
| 3611 | if (error < 0) { |
| 3612 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3613 | return error; |
| 3614 | } |
| 3615 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3616 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3617 | if (IS_ERR(label)) |
| 3618 | return PTR_ERR(label); |
| 3619 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3620 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3621 | if (error < 0) { |
| 3622 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3623 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3627 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3628 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3629 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3630 | err_free_label: |
| 3631 | nfs4_label_free(label); |
| 3632 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3633 | return error; |
| 3634 | } |
| 3635 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3636 | /* |
| 3637 | * Get locations and (maybe) other attributes of a referral. |
| 3638 | * Note that we'll actually follow the referral later when |
| 3639 | * we detect fsid mismatch in inode revalidation |
| 3640 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3641 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3642 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3643 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3644 | { |
| 3645 | int status = -ENOMEM; |
| 3646 | struct page *page = NULL; |
| 3647 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3648 | |
| 3649 | page = alloc_page(GFP_KERNEL); |
| 3650 | if (page == NULL) |
| 3651 | goto out; |
| 3652 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3653 | if (locations == NULL) |
| 3654 | goto out; |
| 3655 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3656 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3657 | if (status != 0) |
| 3658 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3659 | |
| 3660 | /* |
| 3661 | * If the fsid didn't change, this is a migration event, not a |
| 3662 | * referral. Cause us to drop into the exception handler, which |
| 3663 | * will kick off migration recovery. |
| 3664 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3665 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3666 | dprintk("%s: server did not return a different fsid for" |
| 3667 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3668 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3669 | goto out; |
| 3670 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3671 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3672 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3673 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3674 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3675 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3676 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3677 | out: |
| 3678 | if (page) |
| 3679 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3680 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3681 | return status; |
| 3682 | } |
| 3683 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3684 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3685 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | { |
| 3687 | struct nfs4_getattr_arg args = { |
| 3688 | .fh = fhandle, |
| 3689 | .bitmask = server->attr_bitmask, |
| 3690 | }; |
| 3691 | struct nfs4_getattr_res res = { |
| 3692 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3693 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | .server = server, |
| 3695 | }; |
| 3696 | struct rpc_message msg = { |
| 3697 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3698 | .rpc_argp = &args, |
| 3699 | .rpc_resp = &res, |
| 3700 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3701 | |
| 3702 | args.bitmask = nfs4_bitmask(server, label); |
| 3703 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3704 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3705 | 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] | 3706 | } |
| 3707 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3708 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3709 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | { |
| 3711 | struct nfs4_exception exception = { }; |
| 3712 | int err; |
| 3713 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3714 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3715 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3716 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | &exception); |
| 3718 | } while (exception.retry); |
| 3719 | return err; |
| 3720 | } |
| 3721 | |
| 3722 | /* |
| 3723 | * The file is not closed if it is opened due to the a request to change |
| 3724 | * the size of the file. The open call will not be needed once the |
| 3725 | * VFS layer lookup-intents are implemented. |
| 3726 | * |
| 3727 | * Close is called when the inode is destroyed. |
| 3728 | * If we haven't opened the file for O_WRONLY, we |
| 3729 | * need to in the size_change case to obtain a stateid. |
| 3730 | * |
| 3731 | * Got race? |
| 3732 | * Because OPEN is always done by name in nfsv4, it is |
| 3733 | * possible that we opened a different file by the same |
| 3734 | * name. We can recognize this race condition, but we |
| 3735 | * can't do anything about it besides returning an error. |
| 3736 | * |
| 3737 | * This will be fixed with VFS changes (lookup-intent). |
| 3738 | */ |
| 3739 | static int |
| 3740 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3741 | struct iattr *sattr) |
| 3742 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3743 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3744 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3745 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3746 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | int status; |
| 3748 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3749 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3750 | sattr->ia_valid & ATTR_SIZE && |
| 3751 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3752 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3753 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3754 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3756 | /* Deal with open(O_TRUNC) */ |
| 3757 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3758 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3759 | |
| 3760 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3761 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3762 | return 0; |
| 3763 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3764 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3765 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3766 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3767 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3768 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3769 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3770 | } |
| 3771 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3772 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3773 | if (IS_ERR(label)) |
| 3774 | return PTR_ERR(label); |
| 3775 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3776 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3777 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3778 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3779 | nfs_setsecurity(inode, fattr, label); |
| 3780 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3781 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | return status; |
| 3783 | } |
| 3784 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3785 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3786 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3787 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3788 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3789 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3790 | int status; |
| 3791 | struct nfs4_lookup_arg args = { |
| 3792 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3793 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3794 | .name = name, |
| 3795 | }; |
| 3796 | struct nfs4_lookup_res res = { |
| 3797 | .server = server, |
| 3798 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3799 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3800 | .fh = fhandle, |
| 3801 | }; |
| 3802 | struct rpc_message msg = { |
| 3803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3804 | .rpc_argp = &args, |
| 3805 | .rpc_resp = &res, |
| 3806 | }; |
| 3807 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3808 | args.bitmask = nfs4_bitmask(server, label); |
| 3809 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3810 | nfs_fattr_init(fattr); |
| 3811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3813 | 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] | 3814 | dprintk("NFS reply lookup: %d\n", status); |
| 3815 | return status; |
| 3816 | } |
| 3817 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3818 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3819 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3820 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3821 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3822 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3823 | fattr->nlink = 2; |
| 3824 | } |
| 3825 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3826 | 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] | 3827 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3828 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3829 | { |
| 3830 | struct nfs4_exception exception = { }; |
| 3831 | struct rpc_clnt *client = *clnt; |
| 3832 | int err; |
| 3833 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3834 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3835 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3836 | switch (err) { |
| 3837 | case -NFS4ERR_BADNAME: |
| 3838 | err = -ENOENT; |
| 3839 | goto out; |
| 3840 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3841 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3842 | if (err == -NFS4ERR_MOVED) |
| 3843 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3844 | goto out; |
| 3845 | case -NFS4ERR_WRONGSEC: |
| 3846 | err = -EPERM; |
| 3847 | if (client != *clnt) |
| 3848 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3849 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3850 | if (IS_ERR(client)) |
| 3851 | return PTR_ERR(client); |
| 3852 | |
| 3853 | exception.retry = 1; |
| 3854 | break; |
| 3855 | default: |
| 3856 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3857 | } |
| 3858 | } while (exception.retry); |
| 3859 | |
| 3860 | out: |
| 3861 | if (err == 0) |
| 3862 | *clnt = client; |
| 3863 | else if (client != *clnt) |
| 3864 | rpc_shutdown_client(client); |
| 3865 | |
| 3866 | return err; |
| 3867 | } |
| 3868 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3869 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3870 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3871 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3873 | int status; |
| 3874 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3875 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3876 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3877 | if (client != NFS_CLIENT(dir)) { |
| 3878 | rpc_shutdown_client(client); |
| 3879 | nfs_fixup_secinfo_attributes(fattr); |
| 3880 | } |
| 3881 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3884 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3885 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3886 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3887 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3888 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3889 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3890 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3891 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3892 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3893 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3894 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3895 | } |
| 3896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3898 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3899 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | struct nfs4_accessargs args = { |
| 3901 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3902 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3904 | struct nfs4_accessres res = { |
| 3905 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3906 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | struct rpc_message msg = { |
| 3908 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3909 | .rpc_argp = &args, |
| 3910 | .rpc_resp = &res, |
| 3911 | .rpc_cred = entry->cred, |
| 3912 | }; |
| 3913 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3914 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | |
| 3916 | /* |
| 3917 | * Determine which access bits we want to ask for... |
| 3918 | */ |
| 3919 | if (mode & MAY_READ) |
| 3920 | args.access |= NFS4_ACCESS_READ; |
| 3921 | if (S_ISDIR(inode->i_mode)) { |
| 3922 | if (mode & MAY_WRITE) |
| 3923 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3924 | if (mode & MAY_EXEC) |
| 3925 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3926 | } else { |
| 3927 | if (mode & MAY_WRITE) |
| 3928 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3929 | if (mode & MAY_EXEC) |
| 3930 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3931 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3932 | |
| 3933 | res.fattr = nfs_alloc_fattr(); |
| 3934 | if (res.fattr == NULL) |
| 3935 | return -ENOMEM; |
| 3936 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3937 | 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] | 3938 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3939 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3940 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3942 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | return status; |
| 3944 | } |
| 3945 | |
| 3946 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3947 | { |
| 3948 | struct nfs4_exception exception = { }; |
| 3949 | int err; |
| 3950 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3951 | err = _nfs4_proc_access(inode, entry); |
| 3952 | trace_nfs4_access(inode, err); |
| 3953 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | &exception); |
| 3955 | } while (exception.retry); |
| 3956 | return err; |
| 3957 | } |
| 3958 | |
| 3959 | /* |
| 3960 | * TODO: For the time being, we don't try to get any attributes |
| 3961 | * along with any of the zero-copy operations READ, READDIR, |
| 3962 | * READLINK, WRITE. |
| 3963 | * |
| 3964 | * In the case of the first three, we want to put the GETATTR |
| 3965 | * after the read-type operation -- this is because it is hard |
| 3966 | * to predict the length of a GETATTR response in v4, and thus |
| 3967 | * align the READ data correctly. This means that the GETATTR |
| 3968 | * may end up partially falling into the page cache, and we should |
| 3969 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3970 | * To do this efficiently, we need to know the total length |
| 3971 | * of data received, which doesn't seem to be available outside |
| 3972 | * of the RPC layer. |
| 3973 | * |
| 3974 | * In the case of WRITE, we also want to put the GETATTR after |
| 3975 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3976 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | * |
| 3978 | * Both of these changes to the XDR layer would in fact be quite |
| 3979 | * minor, but I decided to leave them for a subsequent patch. |
| 3980 | */ |
| 3981 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3982 | unsigned int pgbase, unsigned int pglen) |
| 3983 | { |
| 3984 | struct nfs4_readlink args = { |
| 3985 | .fh = NFS_FH(inode), |
| 3986 | .pgbase = pgbase, |
| 3987 | .pglen = pglen, |
| 3988 | .pages = &page, |
| 3989 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3990 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | struct rpc_message msg = { |
| 3992 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3993 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3994 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | }; |
| 3996 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3997 | 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] | 3998 | } |
| 3999 | |
| 4000 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 4001 | unsigned int pgbase, unsigned int pglen) |
| 4002 | { |
| 4003 | struct nfs4_exception exception = { }; |
| 4004 | int err; |
| 4005 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4006 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 4007 | trace_nfs4_readlink(inode, err); |
| 4008 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | &exception); |
| 4010 | } while (exception.retry); |
| 4011 | return err; |
| 4012 | } |
| 4013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4015 | * 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] | 4016 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | static int |
| 4018 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4019 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4021 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4022 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4023 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | int status = 0; |
| 4026 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4027 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4028 | if (IS_ERR(ctx)) |
| 4029 | return PTR_ERR(ctx); |
| 4030 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4031 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4032 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4033 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4034 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4035 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | if (IS_ERR(state)) { |
| 4037 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4038 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4041 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4042 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | return status; |
| 4044 | } |
| 4045 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4046 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4048 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4049 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4051 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4053 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4054 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4055 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4058 | .rpc_argp = &args, |
| 4059 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4061 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4062 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4063 | 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] | 4064 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4065 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | return status; |
| 4067 | } |
| 4068 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4069 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | { |
| 4071 | struct nfs4_exception exception = { }; |
| 4072 | int err; |
| 4073 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4074 | err = _nfs4_proc_remove(dir, name); |
| 4075 | trace_nfs4_remove(dir, name, err); |
| 4076 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | &exception); |
| 4078 | } while (exception.retry); |
| 4079 | return err; |
| 4080 | } |
| 4081 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4082 | 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] | 4083 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4084 | struct nfs_server *server = NFS_SERVER(dir); |
| 4085 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4086 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4088 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4090 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4091 | |
| 4092 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4095 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4096 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4097 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4098 | &data->args.seq_args, |
| 4099 | &data->res.seq_res, |
| 4100 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4103 | 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] | 4104 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4105 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4106 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4107 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4108 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4109 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4110 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4111 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4112 | return 0; |
| 4113 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4114 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4117 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4118 | { |
| 4119 | struct nfs_server *server = NFS_SERVER(dir); |
| 4120 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4121 | struct nfs_renameres *res = msg->rpc_resp; |
| 4122 | |
| 4123 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4124 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4125 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4126 | } |
| 4127 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4128 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4129 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4130 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4131 | &data->args.seq_args, |
| 4132 | &data->res.seq_res, |
| 4133 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4137 | struct inode *new_dir) |
| 4138 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4139 | struct nfs_renamedata *data = task->tk_calldata; |
| 4140 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4141 | |
| 4142 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4143 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4144 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4145 | return 0; |
| 4146 | |
| 4147 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4148 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4149 | return 1; |
| 4150 | } |
| 4151 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4152 | 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] | 4153 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4154 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | struct nfs4_link_arg arg = { |
| 4156 | .fh = NFS_FH(inode), |
| 4157 | .dir_fh = NFS_FH(dir), |
| 4158 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4159 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4161 | struct nfs4_link_res res = { |
| 4162 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4163 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4164 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | struct rpc_message msg = { |
| 4166 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4167 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4168 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4170 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4172 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4173 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4174 | goto out; |
| 4175 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4176 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4177 | if (IS_ERR(res.label)) { |
| 4178 | status = PTR_ERR(res.label); |
| 4179 | goto out; |
| 4180 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4181 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4182 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4183 | 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] | 4184 | if (!status) { |
| 4185 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4186 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4187 | if (!status) |
| 4188 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4189 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4190 | |
| 4191 | |
| 4192 | nfs4_label_free(res.label); |
| 4193 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4194 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4195 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | return status; |
| 4197 | } |
| 4198 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4199 | 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] | 4200 | { |
| 4201 | struct nfs4_exception exception = { }; |
| 4202 | int err; |
| 4203 | do { |
| 4204 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4205 | _nfs4_proc_link(inode, dir, name), |
| 4206 | &exception); |
| 4207 | } while (exception.retry); |
| 4208 | return err; |
| 4209 | } |
| 4210 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | struct nfs4_createdata { |
| 4212 | struct rpc_message msg; |
| 4213 | struct nfs4_create_arg arg; |
| 4214 | struct nfs4_create_res res; |
| 4215 | struct nfs_fh fh; |
| 4216 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4217 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4218 | }; |
| 4219 | |
| 4220 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4221 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4222 | { |
| 4223 | struct nfs4_createdata *data; |
| 4224 | |
| 4225 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4226 | if (data != NULL) { |
| 4227 | struct nfs_server *server = NFS_SERVER(dir); |
| 4228 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4229 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4230 | if (IS_ERR(data->label)) |
| 4231 | goto out_free; |
| 4232 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4233 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4234 | data->msg.rpc_argp = &data->arg; |
| 4235 | data->msg.rpc_resp = &data->res; |
| 4236 | data->arg.dir_fh = NFS_FH(dir); |
| 4237 | data->arg.server = server; |
| 4238 | data->arg.name = name; |
| 4239 | data->arg.attrs = sattr; |
| 4240 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4241 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4242 | data->arg.umask = current_umask(); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4243 | data->res.server = server; |
| 4244 | data->res.fh = &data->fh; |
| 4245 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4246 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4247 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4248 | } |
| 4249 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4250 | out_free: |
| 4251 | kfree(data); |
| 4252 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4256 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4257 | 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] | 4258 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4259 | if (status == 0) { |
| 4260 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4261 | 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] | 4262 | } |
| 4263 | return status; |
| 4264 | } |
| 4265 | |
| 4266 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4267 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4268 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4269 | kfree(data); |
| 4270 | } |
| 4271 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4272 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4273 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4274 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4276 | struct nfs4_createdata *data; |
| 4277 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4279 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4280 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4281 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4282 | status = -ENOMEM; |
| 4283 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4284 | if (data == NULL) |
| 4285 | goto out; |
| 4286 | |
| 4287 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4288 | data->arg.u.symlink.pages = &page; |
| 4289 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4290 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4292 | status = nfs4_do_create(dir, dentry, data); |
| 4293 | |
| 4294 | nfs4_free_createdata(data); |
| 4295 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | return status; |
| 4297 | } |
| 4298 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4299 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4300 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | { |
| 4302 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4303 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4305 | |
| 4306 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4309 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4310 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4311 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | &exception); |
| 4313 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4314 | |
| 4315 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | return err; |
| 4317 | } |
| 4318 | |
| 4319 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4320 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4322 | struct nfs4_createdata *data; |
| 4323 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4325 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4326 | if (data == NULL) |
| 4327 | goto out; |
| 4328 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4329 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4330 | status = nfs4_do_create(dir, dentry, data); |
| 4331 | |
| 4332 | nfs4_free_createdata(data); |
| 4333 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | return status; |
| 4335 | } |
| 4336 | |
| 4337 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4338 | struct iattr *sattr) |
| 4339 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4340 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4342 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4344 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4345 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4346 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4347 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4348 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4350 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4351 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4352 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | &exception); |
| 4354 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4355 | nfs4_label_release_security(label); |
| 4356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | return err; |
| 4358 | } |
| 4359 | |
| 4360 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4361 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4363 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | struct nfs4_readdir_arg args = { |
| 4365 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4366 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | .pgbase = 0, |
| 4368 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4369 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4370 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | }; |
| 4372 | struct nfs4_readdir_res res; |
| 4373 | struct rpc_message msg = { |
| 4374 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4375 | .rpc_argp = &args, |
| 4376 | .rpc_resp = &res, |
| 4377 | .rpc_cred = cred, |
| 4378 | }; |
| 4379 | int status; |
| 4380 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4381 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4382 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4383 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4384 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4386 | 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] | 4387 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4388 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4389 | status += args.pgbase; |
| 4390 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4391 | |
| 4392 | nfs_invalidate_atime(dir); |
| 4393 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4394 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | return status; |
| 4396 | } |
| 4397 | |
| 4398 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4399 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | { |
| 4401 | struct nfs4_exception exception = { }; |
| 4402 | int err; |
| 4403 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4404 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4405 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4406 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4407 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | &exception); |
| 4409 | } while (exception.retry); |
| 4410 | return err; |
| 4411 | } |
| 4412 | |
| 4413 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4414 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4416 | struct nfs4_createdata *data; |
| 4417 | int mode = sattr->ia_mode; |
| 4418 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4420 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4421 | if (data == NULL) |
| 4422 | goto out; |
| 4423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4425 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4427 | data->arg.ftype = NF4BLK; |
| 4428 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4429 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | } |
| 4431 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4432 | data->arg.ftype = NF4CHR; |
| 4433 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4434 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4435 | } else if (!S_ISSOCK(mode)) { |
| 4436 | status = -EINVAL; |
| 4437 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4439 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4440 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4441 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4442 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4443 | nfs4_free_createdata(data); |
| 4444 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | return status; |
| 4446 | } |
| 4447 | |
| 4448 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4449 | struct iattr *sattr, dev_t rdev) |
| 4450 | { |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4451 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4453 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4455 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4456 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4457 | |
Andreas Gruenbacher | dff25dd | 2016-12-02 22:53:30 -0500 | [diff] [blame] | 4458 | if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) |
| 4459 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4461 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4462 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4463 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | &exception); |
| 4465 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4466 | |
| 4467 | nfs4_label_release_security(label); |
| 4468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | return err; |
| 4470 | } |
| 4471 | |
| 4472 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4473 | struct nfs_fsstat *fsstat) |
| 4474 | { |
| 4475 | struct nfs4_statfs_arg args = { |
| 4476 | .fh = fhandle, |
| 4477 | .bitmask = server->attr_bitmask, |
| 4478 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4479 | struct nfs4_statfs_res res = { |
| 4480 | .fsstat = fsstat, |
| 4481 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | struct rpc_message msg = { |
| 4483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4484 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4485 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | }; |
| 4487 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4488 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4489 | 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] | 4490 | } |
| 4491 | |
| 4492 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4493 | { |
| 4494 | struct nfs4_exception exception = { }; |
| 4495 | int err; |
| 4496 | do { |
| 4497 | err = nfs4_handle_exception(server, |
| 4498 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4499 | &exception); |
| 4500 | } while (exception.retry); |
| 4501 | return err; |
| 4502 | } |
| 4503 | |
| 4504 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4505 | struct nfs_fsinfo *fsinfo) |
| 4506 | { |
| 4507 | struct nfs4_fsinfo_arg args = { |
| 4508 | .fh = fhandle, |
| 4509 | .bitmask = server->attr_bitmask, |
| 4510 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4511 | struct nfs4_fsinfo_res res = { |
| 4512 | .fsinfo = fsinfo, |
| 4513 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | struct rpc_message msg = { |
| 4515 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4516 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4517 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | }; |
| 4519 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4520 | 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] | 4521 | } |
| 4522 | |
| 4523 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4524 | { |
| 4525 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4526 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | int err; |
| 4528 | |
| 4529 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4530 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4531 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4532 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4533 | nfs4_set_lease_period(server->nfs_client, |
| 4534 | fsinfo->lease_time * HZ, |
| 4535 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4536 | break; |
| 4537 | } |
| 4538 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | } while (exception.retry); |
| 4540 | return err; |
| 4541 | } |
| 4542 | |
| 4543 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4544 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4545 | int error; |
| 4546 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4547 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4548 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4549 | if (error == 0) { |
| 4550 | /* block layout checks this! */ |
| 4551 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4552 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4553 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4554 | |
| 4555 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4559 | struct nfs_pathconf *pathconf) |
| 4560 | { |
| 4561 | struct nfs4_pathconf_arg args = { |
| 4562 | .fh = fhandle, |
| 4563 | .bitmask = server->attr_bitmask, |
| 4564 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4565 | struct nfs4_pathconf_res res = { |
| 4566 | .pathconf = pathconf, |
| 4567 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | struct rpc_message msg = { |
| 4569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4570 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4571 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | }; |
| 4573 | |
| 4574 | /* None of the pathconf attributes are mandatory to implement */ |
| 4575 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4576 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4577 | return 0; |
| 4578 | } |
| 4579 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4580 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4581 | 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] | 4582 | } |
| 4583 | |
| 4584 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4585 | struct nfs_pathconf *pathconf) |
| 4586 | { |
| 4587 | struct nfs4_exception exception = { }; |
| 4588 | int err; |
| 4589 | |
| 4590 | do { |
| 4591 | err = nfs4_handle_exception(server, |
| 4592 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4593 | &exception); |
| 4594 | } while (exception.retry); |
| 4595 | return err; |
| 4596 | } |
| 4597 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4598 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4599 | const struct nfs_open_context *ctx, |
| 4600 | const struct nfs_lock_context *l_ctx, |
| 4601 | fmode_t fmode) |
| 4602 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4603 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4604 | } |
| 4605 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4606 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4607 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4608 | const struct nfs_open_context *ctx, |
| 4609 | const struct nfs_lock_context *l_ctx, |
| 4610 | fmode_t fmode) |
| 4611 | { |
| 4612 | nfs4_stateid current_stateid; |
| 4613 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4614 | /* If the current stateid represents a lost lock, then exit */ |
| 4615 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4616 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4617 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4618 | } |
| 4619 | |
| 4620 | static bool nfs4_error_stateid_expired(int err) |
| 4621 | { |
| 4622 | switch (err) { |
| 4623 | case -NFS4ERR_DELEG_REVOKED: |
| 4624 | case -NFS4ERR_ADMIN_REVOKED: |
| 4625 | case -NFS4ERR_BAD_STATEID: |
| 4626 | case -NFS4ERR_STALE_STATEID: |
| 4627 | case -NFS4ERR_OLD_STATEID: |
| 4628 | case -NFS4ERR_OPENMODE: |
| 4629 | case -NFS4ERR_EXPIRED: |
| 4630 | return true; |
| 4631 | } |
| 4632 | return false; |
| 4633 | } |
| 4634 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4635 | 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] | 4636 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4637 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4639 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4640 | if (task->tk_status < 0) { |
| 4641 | struct nfs4_exception exception = { |
| 4642 | .inode = hdr->inode, |
| 4643 | .state = hdr->args.context->state, |
| 4644 | .stateid = &hdr->args.stateid, |
| 4645 | }; |
| 4646 | task->tk_status = nfs4_async_handle_exception(task, |
| 4647 | server, task->tk_status, &exception); |
| 4648 | if (exception.retry) { |
| 4649 | rpc_restart_call_prepare(task); |
| 4650 | return -EAGAIN; |
| 4651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4655 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4656 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4659 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4660 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4661 | { |
| 4662 | |
| 4663 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4664 | nfs4_stateid_is_current(&args->stateid, |
| 4665 | args->context, |
| 4666 | args->lock_context, |
| 4667 | FMODE_READ)) |
| 4668 | return false; |
| 4669 | rpc_restart_call_prepare(task); |
| 4670 | return true; |
| 4671 | } |
| 4672 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4673 | 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] | 4674 | { |
| 4675 | |
| 4676 | dprintk("--> %s\n", __func__); |
| 4677 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4678 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4679 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4680 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4681 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4682 | if (task->tk_status > 0) |
| 4683 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4684 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4685 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4688 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4689 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4691 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4692 | if (!hdr->pgio_done_cb) |
| 4693 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4694 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4695 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4698 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4699 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4700 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4701 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4702 | &hdr->args.seq_args, |
| 4703 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4704 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4705 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4706 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4707 | hdr->args.lock_context, |
| 4708 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4709 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4710 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4711 | return -EIO; |
| 4712 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4715 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4716 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4718 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4719 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4720 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4721 | if (task->tk_status < 0) { |
| 4722 | struct nfs4_exception exception = { |
| 4723 | .inode = hdr->inode, |
| 4724 | .state = hdr->args.context->state, |
| 4725 | .stateid = &hdr->args.stateid, |
| 4726 | }; |
| 4727 | task->tk_status = nfs4_async_handle_exception(task, |
| 4728 | NFS_SERVER(inode), task->tk_status, |
| 4729 | &exception); |
| 4730 | if (exception.retry) { |
| 4731 | rpc_restart_call_prepare(task); |
| 4732 | return -EAGAIN; |
| 4733 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4735 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4736 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4737 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4738 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4739 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4742 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4743 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4744 | { |
| 4745 | |
| 4746 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4747 | nfs4_stateid_is_current(&args->stateid, |
| 4748 | args->context, |
| 4749 | args->lock_context, |
| 4750 | FMODE_WRITE)) |
| 4751 | return false; |
| 4752 | rpc_restart_call_prepare(task); |
| 4753 | return true; |
| 4754 | } |
| 4755 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4756 | 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] | 4757 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4758 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4759 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4760 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4761 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4762 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4763 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4764 | } |
| 4765 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4766 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4767 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4768 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4769 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4770 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4771 | return false; |
| 4772 | /* Otherwise, request attributes if and only if we don't hold |
| 4773 | * a delegation |
| 4774 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4775 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4776 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4777 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4778 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4779 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4781 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4782 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4783 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4784 | hdr->args.bitmask = NULL; |
| 4785 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4786 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4787 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4788 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4789 | if (!hdr->pgio_done_cb) |
| 4790 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4791 | hdr->res.server = server; |
| 4792 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4794 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4795 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4798 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4799 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4800 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4801 | &data->args.seq_args, |
| 4802 | &data->res.seq_res, |
| 4803 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | } |
| 4805 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4806 | 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] | 4807 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4809 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4810 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4811 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4812 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4813 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4814 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4816 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4819 | 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] | 4820 | { |
| 4821 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4822 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4823 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4824 | } |
| 4825 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4826 | 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] | 4827 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4828 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4829 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4830 | if (data->commit_done_cb == NULL) |
| 4831 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4832 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4833 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4834 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4837 | struct nfs4_renewdata { |
| 4838 | struct nfs_client *client; |
| 4839 | unsigned long timestamp; |
| 4840 | }; |
| 4841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | /* |
| 4843 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4844 | * standalone procedure for queueing an asynchronous RENEW. |
| 4845 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4846 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4847 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4848 | struct nfs4_renewdata *data = calldata; |
| 4849 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4850 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4851 | if (atomic_read(&clp->cl_count) > 1) |
| 4852 | nfs4_schedule_state_renewal(clp); |
| 4853 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4854 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4855 | } |
| 4856 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4857 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4859 | struct nfs4_renewdata *data = calldata; |
| 4860 | struct nfs_client *clp = data->client; |
| 4861 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4863 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4864 | switch (task->tk_status) { |
| 4865 | case 0: |
| 4866 | break; |
| 4867 | case -NFS4ERR_LEASE_MOVED: |
| 4868 | nfs4_schedule_lease_moved_recovery(clp); |
| 4869 | break; |
| 4870 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4871 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4872 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4873 | return; |
| 4874 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4875 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4876 | return; |
| 4877 | } |
| 4878 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4880 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | } |
| 4882 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4883 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4884 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4885 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4886 | }; |
| 4887 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4888 | 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] | 4889 | { |
| 4890 | struct rpc_message msg = { |
| 4891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4892 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4893 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4895 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4897 | if (renew_flags == 0) |
| 4898 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4899 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4900 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4901 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4902 | if (data == NULL) |
| 4903 | return -ENOMEM; |
| 4904 | data->client = clp; |
| 4905 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4906 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4907 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4910 | 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] | 4911 | { |
| 4912 | struct rpc_message msg = { |
| 4913 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4914 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4915 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | }; |
| 4917 | unsigned long now = jiffies; |
| 4918 | int status; |
| 4919 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4920 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | if (status < 0) |
| 4922 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4923 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | return 0; |
| 4925 | } |
| 4926 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4927 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4928 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4929 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4932 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4933 | * 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] | 4934 | * the stack. |
| 4935 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4936 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4937 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4938 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4939 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4940 | { |
| 4941 | struct page *newpage, **spages; |
| 4942 | int rc = 0; |
| 4943 | size_t len; |
| 4944 | spages = pages; |
| 4945 | |
| 4946 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4947 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4948 | newpage = alloc_page(GFP_KERNEL); |
| 4949 | |
| 4950 | if (newpage == NULL) |
| 4951 | goto unwind; |
| 4952 | memcpy(page_address(newpage), buf, len); |
| 4953 | buf += len; |
| 4954 | buflen -= len; |
| 4955 | *pages++ = newpage; |
| 4956 | rc++; |
| 4957 | } while (buflen != 0); |
| 4958 | |
| 4959 | return rc; |
| 4960 | |
| 4961 | unwind: |
| 4962 | for(; rc > 0; rc--) |
| 4963 | __free_page(spages[rc-1]); |
| 4964 | return -ENOMEM; |
| 4965 | } |
| 4966 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4967 | struct nfs4_cached_acl { |
| 4968 | int cached; |
| 4969 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4970 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4971 | }; |
| 4972 | |
| 4973 | 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] | 4974 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4975 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4976 | |
| 4977 | spin_lock(&inode->i_lock); |
| 4978 | kfree(nfsi->nfs4_acl); |
| 4979 | nfsi->nfs4_acl = acl; |
| 4980 | spin_unlock(&inode->i_lock); |
| 4981 | } |
| 4982 | |
| 4983 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4984 | { |
| 4985 | nfs4_set_cached_acl(inode, NULL); |
| 4986 | } |
| 4987 | |
| 4988 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4989 | { |
| 4990 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4991 | struct nfs4_cached_acl *acl; |
| 4992 | int ret = -ENOENT; |
| 4993 | |
| 4994 | spin_lock(&inode->i_lock); |
| 4995 | acl = nfsi->nfs4_acl; |
| 4996 | if (acl == NULL) |
| 4997 | goto out; |
| 4998 | if (buf == NULL) /* user is just asking for length */ |
| 4999 | goto out_len; |
| 5000 | if (acl->cached == 0) |
| 5001 | goto out; |
| 5002 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 5003 | if (acl->len > buflen) |
| 5004 | goto out; |
| 5005 | memcpy(buf, acl->data, acl->len); |
| 5006 | out_len: |
| 5007 | ret = acl->len; |
| 5008 | out: |
| 5009 | spin_unlock(&inode->i_lock); |
| 5010 | return ret; |
| 5011 | } |
| 5012 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5013 | 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] | 5014 | { |
| 5015 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5016 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5017 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5018 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 5019 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5020 | if (acl == NULL) |
| 5021 | goto out; |
| 5022 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5023 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5024 | } else { |
| 5025 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5026 | if (acl == NULL) |
| 5027 | goto out; |
| 5028 | acl->cached = 0; |
| 5029 | } |
| 5030 | acl->len = acl_len; |
| 5031 | out: |
| 5032 | nfs4_set_cached_acl(inode, acl); |
| 5033 | } |
| 5034 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5035 | /* |
| 5036 | * The getxattr API returns the required buffer length when called with a |
| 5037 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5038 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5039 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5040 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5041 | * the cache. If not so, we throw away the page, and cache the required |
| 5042 | * length. The next getxattr call will then produce another round trip to |
| 5043 | * the server, this time with the input buf of the required size. |
| 5044 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5045 | 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] | 5046 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5047 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5048 | struct nfs_getaclargs args = { |
| 5049 | .fh = NFS_FH(inode), |
| 5050 | .acl_pages = pages, |
| 5051 | .acl_len = buflen, |
| 5052 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5053 | struct nfs_getaclres res = { |
| 5054 | .acl_len = buflen, |
| 5055 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5056 | struct rpc_message msg = { |
| 5057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5058 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5059 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5060 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5061 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5062 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5063 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5064 | /* As long as we're doing a round trip to the server anyway, |
| 5065 | * let's be prepared for a page of acl data. */ |
| 5066 | if (npages == 0) |
| 5067 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5068 | if (npages > ARRAY_SIZE(pages)) |
| 5069 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5070 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5071 | for (i = 0; i < npages; i++) { |
| 5072 | pages[i] = alloc_page(GFP_KERNEL); |
| 5073 | if (!pages[i]) |
| 5074 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5075 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5076 | |
| 5077 | /* for decoding across pages */ |
| 5078 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5079 | if (!res.acl_scratch) |
| 5080 | goto out_free; |
| 5081 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5082 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5083 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5084 | 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] | 5085 | __func__, buf, buflen, npages, args.acl_len); |
| 5086 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5087 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5088 | if (ret) |
| 5089 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5090 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5091 | /* Handle the case where the passed-in buffer is too short */ |
| 5092 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5093 | /* Did the user only issue a request for the acl length? */ |
| 5094 | if (buf == NULL) |
| 5095 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5096 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5097 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5098 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5099 | 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] | 5100 | if (buf) { |
| 5101 | if (res.acl_len > buflen) { |
| 5102 | ret = -ERANGE; |
| 5103 | goto out_free; |
| 5104 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5105 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5106 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5107 | out_ok: |
| 5108 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5109 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5110 | for (i = 0; i < npages; i++) |
| 5111 | if (pages[i]) |
| 5112 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5113 | if (res.acl_scratch) |
| 5114 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5115 | return ret; |
| 5116 | } |
| 5117 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5118 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5119 | { |
| 5120 | struct nfs4_exception exception = { }; |
| 5121 | ssize_t ret; |
| 5122 | do { |
| 5123 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5124 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5125 | if (ret >= 0) |
| 5126 | break; |
| 5127 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5128 | } while (exception.retry); |
| 5129 | return ret; |
| 5130 | } |
| 5131 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5132 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5133 | { |
| 5134 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5135 | int ret; |
| 5136 | |
| 5137 | if (!nfs4_server_supports_acls(server)) |
| 5138 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5139 | ret = nfs_revalidate_inode(server, inode); |
| 5140 | if (ret < 0) |
| 5141 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5142 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5143 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5144 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5145 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5146 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5147 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5148 | return ret; |
| 5149 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5150 | } |
| 5151 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5152 | 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] | 5153 | { |
| 5154 | struct nfs_server *server = NFS_SERVER(inode); |
| 5155 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5156 | struct nfs_setaclargs arg = { |
| 5157 | .fh = NFS_FH(inode), |
| 5158 | .acl_pages = pages, |
| 5159 | .acl_len = buflen, |
| 5160 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5161 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5162 | struct rpc_message msg = { |
| 5163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5164 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5165 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5166 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5167 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5168 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5169 | |
| 5170 | if (!nfs4_server_supports_acls(server)) |
| 5171 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5172 | if (npages > ARRAY_SIZE(pages)) |
| 5173 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5174 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5175 | if (i < 0) |
| 5176 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5177 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5178 | 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] | 5179 | |
| 5180 | /* |
| 5181 | * Free each page after tx, so the only ref left is |
| 5182 | * held by the network stack |
| 5183 | */ |
| 5184 | for (; i > 0; i--) |
| 5185 | put_page(pages[i-1]); |
| 5186 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5187 | /* |
| 5188 | * Acl update can result in inode attribute update. |
| 5189 | * so mark the attribute cache invalid. |
| 5190 | */ |
| 5191 | spin_lock(&inode->i_lock); |
| 5192 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5193 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5194 | nfs_access_zap_cache(inode); |
| 5195 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5196 | return ret; |
| 5197 | } |
| 5198 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5199 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5200 | { |
| 5201 | struct nfs4_exception exception = { }; |
| 5202 | int err; |
| 5203 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5204 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5205 | trace_nfs4_set_acl(inode, err); |
| 5206 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5207 | &exception); |
| 5208 | } while (exception.retry); |
| 5209 | return err; |
| 5210 | } |
| 5211 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5212 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5213 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5214 | size_t buflen) |
| 5215 | { |
| 5216 | struct nfs_server *server = NFS_SERVER(inode); |
| 5217 | struct nfs_fattr fattr; |
| 5218 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5219 | |
| 5220 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5221 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5222 | .fh = NFS_FH(inode), |
| 5223 | .bitmask = bitmask, |
| 5224 | }; |
| 5225 | struct nfs4_getattr_res res = { |
| 5226 | .fattr = &fattr, |
| 5227 | .label = &label, |
| 5228 | .server = server, |
| 5229 | }; |
| 5230 | struct rpc_message msg = { |
| 5231 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5232 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5233 | .rpc_resp = &res, |
| 5234 | }; |
| 5235 | int ret; |
| 5236 | |
| 5237 | nfs_fattr_init(&fattr); |
| 5238 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5239 | 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] | 5240 | if (ret) |
| 5241 | return ret; |
| 5242 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5243 | return -ENOENT; |
| 5244 | if (buflen < label.len) |
| 5245 | return -ERANGE; |
| 5246 | return 0; |
| 5247 | } |
| 5248 | |
| 5249 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5250 | size_t buflen) |
| 5251 | { |
| 5252 | struct nfs4_exception exception = { }; |
| 5253 | int err; |
| 5254 | |
| 5255 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5256 | return -EOPNOTSUPP; |
| 5257 | |
| 5258 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5259 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5260 | trace_nfs4_get_security_label(inode, err); |
| 5261 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5262 | &exception); |
| 5263 | } while (exception.retry); |
| 5264 | return err; |
| 5265 | } |
| 5266 | |
| 5267 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5268 | struct nfs4_label *ilabel, |
| 5269 | struct nfs_fattr *fattr, |
| 5270 | struct nfs4_label *olabel) |
| 5271 | { |
| 5272 | |
| 5273 | struct iattr sattr = {0}; |
| 5274 | struct nfs_server *server = NFS_SERVER(inode); |
| 5275 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5276 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5277 | .fh = NFS_FH(inode), |
| 5278 | .iap = &sattr, |
| 5279 | .server = server, |
| 5280 | .bitmask = bitmask, |
| 5281 | .label = ilabel, |
| 5282 | }; |
| 5283 | struct nfs_setattrres res = { |
| 5284 | .fattr = fattr, |
| 5285 | .label = olabel, |
| 5286 | .server = server, |
| 5287 | }; |
| 5288 | struct rpc_message msg = { |
| 5289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5290 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5291 | .rpc_resp = &res, |
| 5292 | }; |
| 5293 | int status; |
| 5294 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5295 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5296 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5297 | 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] | 5298 | if (status) |
| 5299 | dprintk("%s failed: %d\n", __func__, status); |
| 5300 | |
| 5301 | return status; |
| 5302 | } |
| 5303 | |
| 5304 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5305 | struct nfs4_label *ilabel, |
| 5306 | struct nfs_fattr *fattr, |
| 5307 | struct nfs4_label *olabel) |
| 5308 | { |
| 5309 | struct nfs4_exception exception = { }; |
| 5310 | int err; |
| 5311 | |
| 5312 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5313 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5314 | fattr, olabel); |
| 5315 | trace_nfs4_set_security_label(inode, err); |
| 5316 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5317 | &exception); |
| 5318 | } while (exception.retry); |
| 5319 | return err; |
| 5320 | } |
| 5321 | |
| 5322 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5323 | 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] | 5324 | { |
| 5325 | struct nfs4_label ilabel, *olabel = NULL; |
| 5326 | struct nfs_fattr fattr; |
| 5327 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5328 | int status; |
| 5329 | |
| 5330 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5331 | return -EOPNOTSUPP; |
| 5332 | |
| 5333 | nfs_fattr_init(&fattr); |
| 5334 | |
| 5335 | ilabel.pi = 0; |
| 5336 | ilabel.lfs = 0; |
| 5337 | ilabel.label = (char *)buf; |
| 5338 | ilabel.len = buflen; |
| 5339 | |
| 5340 | cred = rpc_lookup_cred(); |
| 5341 | if (IS_ERR(cred)) |
| 5342 | return PTR_ERR(cred); |
| 5343 | |
| 5344 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5345 | if (IS_ERR(olabel)) { |
| 5346 | status = -PTR_ERR(olabel); |
| 5347 | goto out; |
| 5348 | } |
| 5349 | |
| 5350 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5351 | if (status == 0) |
| 5352 | nfs_setsecurity(inode, &fattr, olabel); |
| 5353 | |
| 5354 | nfs4_label_free(olabel); |
| 5355 | out: |
| 5356 | put_rpccred(cred); |
| 5357 | return status; |
| 5358 | } |
| 5359 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5360 | |
| 5361 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5362 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5363 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5364 | { |
| 5365 | __be32 verf[2]; |
| 5366 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5367 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5368 | /* An impossible timestamp guarantees this value |
| 5369 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5370 | verf[0] = cpu_to_be32(U32_MAX); |
| 5371 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5372 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5373 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5374 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5375 | |
| 5376 | verf[0] = cpu_to_be32(ns >> 32); |
| 5377 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5378 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5379 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5380 | } |
| 5381 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5382 | static int |
| 5383 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5384 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5385 | size_t len; |
| 5386 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5387 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5388 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5389 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5390 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5391 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5392 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5393 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5394 | 1 + |
| 5395 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5396 | 1; |
| 5397 | rcu_read_unlock(); |
| 5398 | |
| 5399 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5400 | return -EINVAL; |
| 5401 | |
| 5402 | /* |
| 5403 | * Since this string is allocated at mount time, and held until the |
| 5404 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5405 | * about a memory-reclaim deadlock. |
| 5406 | */ |
| 5407 | str = kmalloc(len, GFP_KERNEL); |
| 5408 | if (!str) |
| 5409 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5410 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5411 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5412 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5413 | clp->cl_ipaddr, |
| 5414 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5415 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5416 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5417 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5418 | clp->cl_owner_id = str; |
| 5419 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5420 | } |
| 5421 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5422 | static int |
| 5423 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5424 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5425 | size_t len; |
| 5426 | char *str; |
| 5427 | |
| 5428 | len = 10 + 10 + 1 + 10 + 1 + |
| 5429 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5430 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5431 | |
| 5432 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5433 | return -EINVAL; |
| 5434 | |
| 5435 | /* |
| 5436 | * Since this string is allocated at mount time, and held until the |
| 5437 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5438 | * about a memory-reclaim deadlock. |
| 5439 | */ |
| 5440 | str = kmalloc(len, GFP_KERNEL); |
| 5441 | if (!str) |
| 5442 | return -ENOMEM; |
| 5443 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5444 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5445 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5446 | nfs4_client_id_uniquifier, |
| 5447 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5448 | clp->cl_owner_id = str; |
| 5449 | return 0; |
| 5450 | } |
| 5451 | |
| 5452 | static int |
| 5453 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5454 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5455 | size_t len; |
| 5456 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5457 | |
| 5458 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5459 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5460 | |
| 5461 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5462 | return nfs4_init_uniquifier_client_string(clp); |
| 5463 | |
| 5464 | len = 10 + 10 + 1 + 10 + 1 + |
| 5465 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5466 | |
| 5467 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5468 | return -EINVAL; |
| 5469 | |
| 5470 | /* |
| 5471 | * Since this string is allocated at mount time, and held until the |
| 5472 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5473 | * about a memory-reclaim deadlock. |
| 5474 | */ |
| 5475 | str = kmalloc(len, GFP_KERNEL); |
| 5476 | if (!str) |
| 5477 | return -ENOMEM; |
| 5478 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5479 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5480 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5481 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5482 | clp->cl_owner_id = str; |
| 5483 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5484 | } |
| 5485 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5486 | /* |
| 5487 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5488 | * services. Advertise one based on the address family of the |
| 5489 | * clientaddr. |
| 5490 | */ |
| 5491 | static unsigned int |
| 5492 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5493 | { |
| 5494 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5495 | return scnprintf(buf, len, "tcp6"); |
| 5496 | else |
| 5497 | return scnprintf(buf, len, "tcp"); |
| 5498 | } |
| 5499 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5500 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5501 | { |
| 5502 | struct nfs4_setclientid *sc = calldata; |
| 5503 | |
| 5504 | if (task->tk_status == 0) |
| 5505 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5506 | } |
| 5507 | |
| 5508 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5509 | .rpc_call_done = nfs4_setclientid_done, |
| 5510 | }; |
| 5511 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5512 | /** |
| 5513 | * nfs4_proc_setclientid - Negotiate client ID |
| 5514 | * @clp: state data structure |
| 5515 | * @program: RPC program for NFSv4 callback service |
| 5516 | * @port: IP port number for NFS4 callback service |
| 5517 | * @cred: RPC credential to use for this call |
| 5518 | * @res: where to place the result |
| 5519 | * |
| 5520 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5521 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5522 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5523 | unsigned short port, struct rpc_cred *cred, |
| 5524 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | { |
| 5526 | nfs4_verifier sc_verifier; |
| 5527 | struct nfs4_setclientid setclientid = { |
| 5528 | .sc_verifier = &sc_verifier, |
| 5529 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5530 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | }; |
| 5532 | struct rpc_message msg = { |
| 5533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5534 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5535 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5536 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5538 | struct rpc_task *task; |
| 5539 | struct rpc_task_setup task_setup_data = { |
| 5540 | .rpc_client = clp->cl_rpcclient, |
| 5541 | .rpc_message = &msg, |
| 5542 | .callback_ops = &nfs4_setclientid_ops, |
| 5543 | .callback_data = &setclientid, |
| 5544 | .flags = RPC_TASK_TIMEOUT, |
| 5545 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5546 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5548 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5549 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5550 | |
| 5551 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5552 | status = nfs4_init_uniform_client_string(clp); |
| 5553 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5554 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5555 | |
| 5556 | if (status) |
| 5557 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5558 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5559 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5560 | setclientid.sc_netid_len = |
| 5561 | nfs4_init_callback_netid(clp, |
| 5562 | setclientid.sc_netid, |
| 5563 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5564 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5565 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5567 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5568 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5569 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5570 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5571 | task = rpc_run_task(&task_setup_data); |
| 5572 | if (IS_ERR(task)) { |
| 5573 | status = PTR_ERR(task); |
| 5574 | goto out; |
| 5575 | } |
| 5576 | status = task->tk_status; |
| 5577 | if (setclientid.sc_cred) { |
| 5578 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5579 | put_rpccred(setclientid.sc_cred); |
| 5580 | } |
| 5581 | rpc_put_task(task); |
| 5582 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5583 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5584 | dprintk("NFS reply setclientid: %d\n", status); |
| 5585 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | } |
| 5587 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5588 | /** |
| 5589 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5590 | * @clp: state data structure |
| 5591 | * @res: result of a previous SETCLIENTID |
| 5592 | * @cred: RPC credential to use for this call |
| 5593 | * |
| 5594 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5595 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5596 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5597 | struct nfs4_setclientid_res *arg, |
| 5598 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5599 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5600 | struct rpc_message msg = { |
| 5601 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5602 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5603 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | int status; |
| 5606 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5607 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5608 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5609 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5610 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5611 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5612 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5613 | return status; |
| 5614 | } |
| 5615 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5616 | struct nfs4_delegreturndata { |
| 5617 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5618 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5619 | struct nfs_fh fh; |
| 5620 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5621 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5622 | struct { |
| 5623 | struct nfs4_layoutreturn_args arg; |
| 5624 | struct nfs4_layoutreturn_res res; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5625 | struct nfs4_xdr_opaque_data ld_private; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5626 | u32 roc_barrier; |
| 5627 | bool roc; |
| 5628 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5629 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5630 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5631 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5632 | }; |
| 5633 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5634 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5635 | { |
| 5636 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5637 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5638 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5639 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5640 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5641 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5642 | |
| 5643 | /* Handle Layoutreturn errors */ |
| 5644 | if (data->args.lr_args && task->tk_status != 0) { |
| 5645 | switch(data->res.lr_ret) { |
| 5646 | default: |
| 5647 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5648 | break; |
| 5649 | case 0: |
| 5650 | data->args.lr_args = NULL; |
| 5651 | data->res.lr_res = NULL; |
| 5652 | break; |
| 5653 | case -NFS4ERR_ADMIN_REVOKED: |
| 5654 | case -NFS4ERR_DELEG_REVOKED: |
| 5655 | case -NFS4ERR_EXPIRED: |
| 5656 | case -NFS4ERR_BAD_STATEID: |
| 5657 | case -NFS4ERR_OLD_STATEID: |
| 5658 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5659 | case -NFS4ERR_WRONG_CRED: |
| 5660 | data->args.lr_args = NULL; |
| 5661 | data->res.lr_res = NULL; |
| 5662 | data->res.lr_ret = 0; |
| 5663 | rpc_restart_call_prepare(task); |
| 5664 | return; |
| 5665 | } |
| 5666 | } |
| 5667 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5668 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5669 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5670 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5671 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5672 | case -NFS4ERR_ADMIN_REVOKED: |
| 5673 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5674 | case -NFS4ERR_EXPIRED: |
| 5675 | nfs4_free_revoked_stateid(data->res.server, |
| 5676 | data->args.stateid, |
| 5677 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5678 | case -NFS4ERR_BAD_STATEID: |
| 5679 | case -NFS4ERR_OLD_STATEID: |
| 5680 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5681 | task->tk_status = 0; |
| 5682 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5683 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5684 | if (nfs4_async_handle_error(task, data->res.server, |
| 5685 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5686 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5687 | return; |
| 5688 | } |
| 5689 | } |
| 5690 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | static void nfs4_delegreturn_release(void *calldata) |
| 5694 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5695 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5696 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5697 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5698 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5699 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5700 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5701 | data->res.lr_ret); |
Trond Myklebust | 0bc2c9b | 2016-12-16 19:48:09 -0500 | [diff] [blame^] | 5702 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5703 | nfs_iput_and_deactive(inode); |
| 5704 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5705 | kfree(calldata); |
| 5706 | } |
| 5707 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5708 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5709 | { |
| 5710 | struct nfs4_delegreturndata *d_data; |
| 5711 | |
| 5712 | d_data = (struct nfs4_delegreturndata *)data; |
| 5713 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5714 | 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] | 5715 | return; |
| 5716 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5717 | nfs4_setup_sequence(d_data->res.server, |
| 5718 | &d_data->args.seq_args, |
| 5719 | &d_data->res.seq_res, |
| 5720 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5721 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5722 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5723 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5724 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5725 | .rpc_call_done = nfs4_delegreturn_done, |
| 5726 | .rpc_release = nfs4_delegreturn_release, |
| 5727 | }; |
| 5728 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5729 | 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] | 5730 | { |
| 5731 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5732 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5733 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5734 | struct rpc_message msg = { |
| 5735 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5736 | .rpc_cred = cred, |
| 5737 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5738 | struct rpc_task_setup task_setup_data = { |
| 5739 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5740 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5741 | .callback_ops = &nfs4_delegreturn_ops, |
| 5742 | .flags = RPC_TASK_ASYNC, |
| 5743 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5744 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5745 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5746 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5747 | if (data == NULL) |
| 5748 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5749 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5750 | |
| 5751 | nfs4_state_protect(server->nfs_client, |
| 5752 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5753 | &task_setup_data.rpc_client, &msg); |
| 5754 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5755 | data->args.fhandle = &data->fh; |
| 5756 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5757 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5758 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5759 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5760 | data->res.fattr = &data->fattr; |
| 5761 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5762 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 5763 | data->lr.arg.ld_private = &data->lr.ld_private; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5764 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5765 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5766 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5767 | 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] | 5768 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5769 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5770 | if (data->lr.roc) { |
| 5771 | data->args.lr_args = &data->lr.arg; |
| 5772 | data->res.lr_res = &data->lr.res; |
| 5773 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5774 | } else if (data->lr.roc) { |
| 5775 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5776 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5777 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5778 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5779 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5780 | msg.rpc_argp = &data->args; |
| 5781 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5782 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5783 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5784 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5785 | if (!issync) |
| 5786 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5787 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5788 | if (status != 0) |
| 5789 | goto out; |
| 5790 | status = data->rpc_status; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5791 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5792 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5793 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5796 | 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] | 5797 | { |
| 5798 | struct nfs_server *server = NFS_SERVER(inode); |
| 5799 | struct nfs4_exception exception = { }; |
| 5800 | int err; |
| 5801 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5802 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5803 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5804 | switch (err) { |
| 5805 | case -NFS4ERR_STALE_STATEID: |
| 5806 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5807 | case 0: |
| 5808 | return 0; |
| 5809 | } |
| 5810 | err = nfs4_handle_exception(server, err, &exception); |
| 5811 | } while (exception.retry); |
| 5812 | return err; |
| 5813 | } |
| 5814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5816 | { |
| 5817 | struct inode *inode = state->inode; |
| 5818 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5819 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5820 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5822 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5824 | struct nfs_lockt_res res = { |
| 5825 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | }; |
| 5827 | struct rpc_message msg = { |
| 5828 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5829 | .rpc_argp = &arg, |
| 5830 | .rpc_resp = &res, |
| 5831 | .rpc_cred = state->owner->so_cred, |
| 5832 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | struct nfs4_lock_state *lsp; |
| 5834 | int status; |
| 5835 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5836 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5837 | status = nfs4_set_lock_state(state, request); |
| 5838 | if (status != 0) |
| 5839 | goto out; |
| 5840 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5841 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5842 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5843 | 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] | 5844 | switch (status) { |
| 5845 | case 0: |
| 5846 | request->fl_type = F_UNLCK; |
| 5847 | break; |
| 5848 | case -NFS4ERR_DENIED: |
| 5849 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5851 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5852 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5853 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | return status; |
| 5855 | } |
| 5856 | |
| 5857 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5858 | { |
| 5859 | struct nfs4_exception exception = { }; |
| 5860 | int err; |
| 5861 | |
| 5862 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5863 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5864 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5865 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | &exception); |
| 5867 | } while (exception.retry); |
| 5868 | return err; |
| 5869 | } |
| 5870 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5871 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5872 | struct nfs_locku_args arg; |
| 5873 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5874 | struct nfs4_lock_state *lsp; |
| 5875 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5876 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5877 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5878 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5879 | }; |
| 5880 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5881 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5882 | struct nfs_open_context *ctx, |
| 5883 | struct nfs4_lock_state *lsp, |
| 5884 | struct nfs_seqid *seqid) |
| 5885 | { |
| 5886 | struct nfs4_unlockdata *p; |
| 5887 | struct inode *inode = lsp->ls_state->inode; |
| 5888 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5889 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5890 | if (p == NULL) |
| 5891 | return NULL; |
| 5892 | p->arg.fh = NFS_FH(inode); |
| 5893 | p->arg.fl = &p->fl; |
| 5894 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5895 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5896 | p->lsp = lsp; |
| 5897 | atomic_inc(&lsp->ls_count); |
| 5898 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5899 | p->ctx = get_nfs_open_context(ctx); |
| 5900 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5901 | p->server = NFS_SERVER(inode); |
| 5902 | return p; |
| 5903 | } |
| 5904 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5905 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5906 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5907 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5908 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5909 | nfs4_put_lock_state(calldata->lsp); |
| 5910 | put_nfs_open_context(calldata->ctx); |
| 5911 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5912 | } |
| 5913 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5914 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5915 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5916 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5917 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5918 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5919 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5920 | switch (task->tk_status) { |
| 5921 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5922 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5923 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5924 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5925 | &calldata->res.stateid)) |
| 5926 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5927 | case -NFS4ERR_ADMIN_REVOKED: |
| 5928 | case -NFS4ERR_EXPIRED: |
| 5929 | nfs4_free_revoked_stateid(calldata->server, |
| 5930 | &calldata->arg.stateid, |
| 5931 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5932 | case -NFS4ERR_BAD_STATEID: |
| 5933 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5934 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5935 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5936 | &calldata->lsp->ls_stateid)) |
| 5937 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5938 | break; |
| 5939 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5940 | if (nfs4_async_handle_error(task, calldata->server, |
| 5941 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5942 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5943 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5944 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5945 | } |
| 5946 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5947 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5948 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5949 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5951 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5952 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5953 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5954 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5955 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5956 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5957 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5958 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5959 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5960 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5961 | &calldata->res.seq_res, |
| 5962 | task) != 0) |
| 5963 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5964 | return; |
| 5965 | out_no_action: |
| 5966 | task->tk_action = NULL; |
| 5967 | out_wait: |
| 5968 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5971 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5972 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5973 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5974 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5975 | }; |
| 5976 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5977 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5978 | struct nfs_open_context *ctx, |
| 5979 | struct nfs4_lock_state *lsp, |
| 5980 | struct nfs_seqid *seqid) |
| 5981 | { |
| 5982 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5983 | struct rpc_message msg = { |
| 5984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5985 | .rpc_cred = ctx->cred, |
| 5986 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5987 | struct rpc_task_setup task_setup_data = { |
| 5988 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5989 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5990 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5991 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5992 | .flags = RPC_TASK_ASYNC, |
| 5993 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5994 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5995 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5996 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5997 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5998 | /* Ensure this is an unlock - when canceling a lock, the |
| 5999 | * canceled lock is passed in, and it won't be an unlock. |
| 6000 | */ |
| 6001 | fl->fl_type = F_UNLCK; |
| 6002 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6003 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 6004 | if (data == NULL) { |
| 6005 | nfs_free_seqid(seqid); |
| 6006 | return ERR_PTR(-ENOMEM); |
| 6007 | } |
| 6008 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6009 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6010 | msg.rpc_argp = &data->arg; |
| 6011 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6012 | task_setup_data.callback_data = data; |
| 6013 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6014 | } |
| 6015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6017 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6018 | struct inode *inode = state->inode; |
| 6019 | struct nfs4_state_owner *sp = state->owner; |
| 6020 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6021 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6022 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6023 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6024 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6025 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6026 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6028 | status = nfs4_set_lock_state(state, request); |
| 6029 | /* Unlock _before_ we do the RPC call */ |
| 6030 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6031 | /* Exclude nfs_delegation_claim_locks() */ |
| 6032 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6033 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6034 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6035 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 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 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6039 | } |
| 6040 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6041 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6042 | if (status != 0) |
| 6043 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6044 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6045 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6046 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6047 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6048 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6049 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6050 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6051 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6052 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6053 | 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] | 6054 | status = PTR_ERR(task); |
| 6055 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6056 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6057 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6058 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6059 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6060 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6061 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6062 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6065 | struct nfs4_lockdata { |
| 6066 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6067 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6068 | struct nfs4_lock_state *lsp; |
| 6069 | struct nfs_open_context *ctx; |
| 6070 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6071 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6072 | int rpc_status; |
| 6073 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6074 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6075 | }; |
| 6076 | |
| 6077 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6078 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6079 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6080 | { |
| 6081 | struct nfs4_lockdata *p; |
| 6082 | struct inode *inode = lsp->ls_state->inode; |
| 6083 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6084 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6085 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6086 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6087 | if (p == NULL) |
| 6088 | return NULL; |
| 6089 | |
| 6090 | p->arg.fh = NFS_FH(inode); |
| 6091 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6092 | 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] | 6093 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6094 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6095 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6096 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6097 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6098 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6099 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6100 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6101 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6102 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6103 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6104 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6105 | atomic_inc(&lsp->ls_count); |
| 6106 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6107 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6108 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6109 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6110 | out_free_seqid: |
| 6111 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6112 | out_free: |
| 6113 | kfree(p); |
| 6114 | return NULL; |
| 6115 | } |
| 6116 | |
| 6117 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6118 | { |
| 6119 | struct nfs4_lockdata *data = calldata; |
| 6120 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6122 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6123 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6124 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6125 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6126 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6127 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6128 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6129 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6130 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6131 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6132 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6133 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6134 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6135 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6136 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6137 | &data->lsp->ls_stateid); |
| 6138 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6139 | if (!nfs4_valid_open_stateid(state)) { |
| 6140 | data->rpc_status = -EBADF; |
| 6141 | task->tk_action = NULL; |
| 6142 | goto out_release_open_seqid; |
| 6143 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6144 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6145 | if (nfs4_setup_sequence(data->server, |
| 6146 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6147 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6148 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6149 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6150 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6151 | nfs_release_seqid(data->arg.open_seqid); |
| 6152 | out_release_lock_seqid: |
| 6153 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6154 | out_wait: |
| 6155 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6156 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6157 | } |
| 6158 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6159 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6160 | { |
| 6161 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6162 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6163 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6164 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6165 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6166 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6167 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6168 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6169 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6170 | switch (task->tk_status) { |
| 6171 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6172 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6173 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6174 | if (data->arg.new_lock) { |
| 6175 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6176 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6177 | rpc_restart_call_prepare(task); |
| 6178 | break; |
| 6179 | } |
| 6180 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6181 | if (data->arg.new_lock_owner != 0) { |
| 6182 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6183 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6184 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6185 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6186 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6187 | break; |
| 6188 | case -NFS4ERR_BAD_STATEID: |
| 6189 | case -NFS4ERR_OLD_STATEID: |
| 6190 | case -NFS4ERR_STALE_STATEID: |
| 6191 | case -NFS4ERR_EXPIRED: |
| 6192 | if (data->arg.new_lock_owner != 0) { |
| 6193 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6194 | &lsp->ls_state->open_stateid)) |
| 6195 | rpc_restart_call_prepare(task); |
| 6196 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6197 | &lsp->ls_stateid)) |
| 6198 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6199 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6200 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | static void nfs4_lock_release(void *calldata) |
| 6204 | { |
| 6205 | struct nfs4_lockdata *data = calldata; |
| 6206 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6207 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6208 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6209 | if (data->cancelled != 0) { |
| 6210 | struct rpc_task *task; |
| 6211 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6212 | data->arg.lock_seqid); |
| 6213 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6214 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6215 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6216 | } else |
| 6217 | nfs_free_seqid(data->arg.lock_seqid); |
| 6218 | nfs4_put_lock_state(data->lsp); |
| 6219 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6220 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6221 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6222 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6226 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6227 | .rpc_call_done = nfs4_lock_done, |
| 6228 | .rpc_release = nfs4_lock_release, |
| 6229 | }; |
| 6230 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6231 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6232 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6233 | switch (error) { |
| 6234 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6235 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6236 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6237 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6238 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6239 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6240 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6241 | break; |
| 6242 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6243 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6244 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6245 | }; |
| 6246 | } |
| 6247 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6248 | 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] | 6249 | { |
| 6250 | struct nfs4_lockdata *data; |
| 6251 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6252 | struct rpc_message msg = { |
| 6253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6254 | .rpc_cred = state->owner->so_cred, |
| 6255 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6256 | struct rpc_task_setup task_setup_data = { |
| 6257 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6258 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6259 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6260 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6261 | .flags = RPC_TASK_ASYNC, |
| 6262 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6263 | int ret; |
| 6264 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6265 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6266 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6267 | fl->fl_u.nfs4_fl.owner, |
| 6268 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6269 | if (data == NULL) |
| 6270 | return -ENOMEM; |
| 6271 | if (IS_SETLKW(cmd)) |
| 6272 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6273 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6274 | msg.rpc_argp = &data->arg; |
| 6275 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6276 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6277 | if (recovery_type > NFS_LOCK_NEW) { |
| 6278 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6279 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6280 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6281 | } else |
| 6282 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6283 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6284 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6285 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6286 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6287 | if (ret == 0) { |
| 6288 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6289 | if (ret) |
| 6290 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6291 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6292 | } else |
| 6293 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6294 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6295 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6296 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6297 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6301 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6302 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6303 | struct nfs4_exception exception = { |
| 6304 | .inode = state->inode, |
| 6305 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6306 | int err; |
| 6307 | |
| 6308 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6309 | /* Cache the lock if possible... */ |
| 6310 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6311 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6312 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6313 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6314 | break; |
| 6315 | nfs4_handle_exception(server, err, &exception); |
| 6316 | } while (exception.retry); |
| 6317 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6321 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6322 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6323 | struct nfs4_exception exception = { |
| 6324 | .inode = state->inode, |
| 6325 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6326 | int err; |
| 6327 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6328 | err = nfs4_set_lock_state(state, request); |
| 6329 | if (err != 0) |
| 6330 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6331 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6332 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6333 | return 0; |
| 6334 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6335 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6336 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6337 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6338 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6339 | switch (err) { |
| 6340 | default: |
| 6341 | goto out; |
| 6342 | case -NFS4ERR_GRACE: |
| 6343 | case -NFS4ERR_DELAY: |
| 6344 | nfs4_handle_exception(server, err, &exception); |
| 6345 | err = 0; |
| 6346 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6347 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6348 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6349 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | } |
| 6351 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6352 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6353 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6354 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6355 | struct nfs4_lock_state *lsp; |
| 6356 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6357 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6358 | status = nfs4_set_lock_state(state, request); |
| 6359 | if (status != 0) |
| 6360 | return status; |
| 6361 | lsp = request->fl_u.nfs4_fl.owner; |
| 6362 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6363 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6364 | return 0; |
| 6365 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6366 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6367 | } |
| 6368 | #endif |
| 6369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6370 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6371 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6372 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6373 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6374 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6375 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6377 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6378 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6379 | if (status < 0) |
| 6380 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6381 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6382 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6383 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6384 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6385 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6386 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6387 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -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); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6390 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6391 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6392 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6393 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6394 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6395 | out: |
| 6396 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | return status; |
| 6398 | } |
| 6399 | |
| 6400 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6401 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6402 | struct nfs4_exception exception = { |
| 6403 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6404 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6405 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6406 | int err; |
| 6407 | |
| 6408 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6409 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6410 | if (err == -NFS4ERR_DENIED) |
| 6411 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6413 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6414 | } while (exception.retry); |
| 6415 | return err; |
| 6416 | } |
| 6417 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6418 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6419 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6420 | |
| 6421 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6422 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6423 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6424 | { |
| 6425 | int status = -ERESTARTSYS; |
| 6426 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6427 | |
| 6428 | while(!signalled()) { |
| 6429 | status = nfs4_proc_setlk(state, cmd, request); |
| 6430 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6431 | break; |
| 6432 | freezable_schedule_timeout_interruptible(timeout); |
| 6433 | timeout *= 2; |
| 6434 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6435 | status = -ERESTARTSYS; |
| 6436 | } |
| 6437 | return status; |
| 6438 | } |
| 6439 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6440 | #ifdef CONFIG_NFS_V4_1 |
| 6441 | struct nfs4_lock_waiter { |
| 6442 | struct task_struct *task; |
| 6443 | struct inode *inode; |
| 6444 | struct nfs_lowner *owner; |
| 6445 | bool notified; |
| 6446 | }; |
| 6447 | |
| 6448 | static int |
| 6449 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6450 | { |
| 6451 | int ret; |
| 6452 | struct cb_notify_lock_args *cbnl = key; |
| 6453 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6454 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6455 | *wowner = waiter->owner; |
| 6456 | |
| 6457 | /* Only wake if the callback was for the same owner */ |
| 6458 | if (lowner->clientid != wowner->clientid || |
| 6459 | lowner->id != wowner->id || |
| 6460 | lowner->s_dev != wowner->s_dev) |
| 6461 | return 0; |
| 6462 | |
| 6463 | /* Make sure it's for the right inode */ |
| 6464 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6465 | return 0; |
| 6466 | |
| 6467 | waiter->notified = true; |
| 6468 | |
| 6469 | /* override "private" so we can use default_wake_function */ |
| 6470 | wait->private = waiter->task; |
| 6471 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6472 | wait->private = waiter; |
| 6473 | return ret; |
| 6474 | } |
| 6475 | |
| 6476 | static int |
| 6477 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6478 | { |
| 6479 | int status = -ERESTARTSYS; |
| 6480 | unsigned long flags; |
| 6481 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6482 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6483 | struct nfs_client *clp = server->nfs_client; |
| 6484 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6485 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6486 | .id = lsp->ls_seqid.owner_id, |
| 6487 | .s_dev = server->s_dev }; |
| 6488 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6489 | .inode = state->inode, |
| 6490 | .owner = &owner, |
| 6491 | .notified = false }; |
| 6492 | wait_queue_t wait; |
| 6493 | |
| 6494 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6495 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6496 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6497 | |
| 6498 | init_wait(&wait); |
| 6499 | wait.private = &waiter; |
| 6500 | wait.func = nfs4_wake_lock_waiter; |
| 6501 | add_wait_queue(q, &wait); |
| 6502 | |
| 6503 | while(!signalled()) { |
| 6504 | status = nfs4_proc_setlk(state, cmd, request); |
| 6505 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6506 | break; |
| 6507 | |
| 6508 | status = -ERESTARTSYS; |
| 6509 | spin_lock_irqsave(&q->lock, flags); |
| 6510 | if (waiter.notified) { |
| 6511 | spin_unlock_irqrestore(&q->lock, flags); |
| 6512 | continue; |
| 6513 | } |
| 6514 | set_current_state(TASK_INTERRUPTIBLE); |
| 6515 | spin_unlock_irqrestore(&q->lock, flags); |
| 6516 | |
| 6517 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6518 | } |
| 6519 | |
| 6520 | finish_wait(q, &wait); |
| 6521 | return status; |
| 6522 | } |
| 6523 | #else /* !CONFIG_NFS_V4_1 */ |
| 6524 | static inline int |
| 6525 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6526 | { |
| 6527 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6528 | } |
| 6529 | #endif |
| 6530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6531 | static int |
| 6532 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6533 | { |
| 6534 | struct nfs_open_context *ctx; |
| 6535 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | int status; |
| 6537 | |
| 6538 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6539 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6540 | state = ctx->state; |
| 6541 | |
| 6542 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6543 | return -EINVAL; |
| 6544 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6545 | if (IS_GETLK(cmd)) { |
| 6546 | if (state != NULL) |
| 6547 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6548 | return 0; |
| 6549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6550 | |
| 6551 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6552 | return -EINVAL; |
| 6553 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6554 | if (request->fl_type == F_UNLCK) { |
| 6555 | if (state != NULL) |
| 6556 | return nfs4_proc_unlck(state, cmd, request); |
| 6557 | return 0; |
| 6558 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6559 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6560 | if (state == NULL) |
| 6561 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6562 | |
| 6563 | if ((request->fl_flags & FL_POSIX) && |
| 6564 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6565 | return -ENOLCK; |
| 6566 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6567 | /* |
| 6568 | * Don't rely on the VFS having checked the file open mode, |
| 6569 | * since it won't do this for flock() locks. |
| 6570 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6571 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6572 | case F_RDLCK: |
| 6573 | if (!(filp->f_mode & FMODE_READ)) |
| 6574 | return -EBADF; |
| 6575 | break; |
| 6576 | case F_WRLCK: |
| 6577 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6578 | return -EBADF; |
| 6579 | } |
| 6580 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6581 | status = nfs4_set_lock_state(state, request); |
| 6582 | if (status != 0) |
| 6583 | return status; |
| 6584 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6585 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6586 | } |
| 6587 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6588 | 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] | 6589 | { |
| 6590 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6591 | int err; |
| 6592 | |
| 6593 | err = nfs4_set_lock_state(state, fl); |
| 6594 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6595 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6596 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6597 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6598 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6599 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6600 | struct nfs_release_lockowner_data { |
| 6601 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6602 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6603 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6604 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6605 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6606 | }; |
| 6607 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6608 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6609 | { |
| 6610 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6611 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6612 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6613 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6614 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6615 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6619 | { |
| 6620 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6621 | struct nfs_server *server = data->server; |
| 6622 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6623 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6624 | |
| 6625 | switch (task->tk_status) { |
| 6626 | case 0: |
| 6627 | renew_lease(server, data->timestamp); |
| 6628 | break; |
| 6629 | case -NFS4ERR_STALE_CLIENTID: |
| 6630 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6631 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6632 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6633 | case -NFS4ERR_LEASE_MOVED: |
| 6634 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6635 | if (nfs4_async_handle_error(task, server, |
| 6636 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6637 | rpc_restart_call_prepare(task); |
| 6638 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6639 | } |
| 6640 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6641 | static void nfs4_release_lockowner_release(void *calldata) |
| 6642 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6643 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6644 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6645 | kfree(calldata); |
| 6646 | } |
| 6647 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6648 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6649 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6650 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6651 | .rpc_release = nfs4_release_lockowner_release, |
| 6652 | }; |
| 6653 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6654 | static void |
| 6655 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6656 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6657 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6658 | struct rpc_message msg = { |
| 6659 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6660 | }; |
| 6661 | |
| 6662 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6663 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6664 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6665 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6666 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6667 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6668 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6669 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6670 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6671 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6672 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6673 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6674 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6675 | msg.rpc_resp = &data->res; |
| 6676 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6677 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6678 | } |
| 6679 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6680 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6681 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6682 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6683 | struct dentry *unused, struct inode *inode, |
| 6684 | const char *key, const void *buf, |
| 6685 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6686 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6687 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6688 | } |
| 6689 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6690 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6691 | struct dentry *unused, struct inode *inode, |
| 6692 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6693 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6694 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6697 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6698 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6699 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6702 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6703 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6704 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6705 | struct dentry *unused, struct inode *inode, |
| 6706 | const char *key, const void *buf, |
| 6707 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6708 | { |
| 6709 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6710 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6711 | |
| 6712 | return -EOPNOTSUPP; |
| 6713 | } |
| 6714 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6715 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6716 | struct dentry *unused, struct inode *inode, |
| 6717 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6718 | { |
| 6719 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6720 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6721 | return -EOPNOTSUPP; |
| 6722 | } |
| 6723 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6724 | static ssize_t |
| 6725 | 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] | 6726 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6727 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6728 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6729 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6730 | len = security_inode_listsecurity(inode, list, list_len); |
| 6731 | if (list_len && len > list_len) |
| 6732 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6733 | } |
| 6734 | return len; |
| 6735 | } |
| 6736 | |
| 6737 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6738 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6739 | .get = nfs4_xattr_get_nfs4_label, |
| 6740 | .set = nfs4_xattr_set_nfs4_label, |
| 6741 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6742 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6743 | #else |
| 6744 | |
| 6745 | static ssize_t |
| 6746 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6747 | { |
| 6748 | return 0; |
| 6749 | } |
| 6750 | |
| 6751 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6752 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6753 | /* |
| 6754 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6755 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6756 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6757 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6758 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6759 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6760 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6761 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6762 | return; |
| 6763 | |
| 6764 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6765 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6766 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6767 | fattr->nlink = 2; |
| 6768 | } |
| 6769 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6770 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6771 | const struct qstr *name, |
| 6772 | struct nfs4_fs_locations *fs_locations, |
| 6773 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6774 | { |
| 6775 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6776 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6777 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6778 | }; |
| 6779 | struct nfs4_fs_locations_arg args = { |
| 6780 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6781 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6782 | .page = page, |
| 6783 | .bitmask = bitmask, |
| 6784 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6785 | struct nfs4_fs_locations_res res = { |
| 6786 | .fs_locations = fs_locations, |
| 6787 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6788 | struct rpc_message msg = { |
| 6789 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6790 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6791 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6792 | }; |
| 6793 | int status; |
| 6794 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6795 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6796 | |
| 6797 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6798 | * is not supported */ |
| 6799 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6800 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6801 | else |
| 6802 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6803 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6804 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6805 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6806 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6807 | 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] | 6808 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6809 | return status; |
| 6810 | } |
| 6811 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6812 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6813 | const struct qstr *name, |
| 6814 | struct nfs4_fs_locations *fs_locations, |
| 6815 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6816 | { |
| 6817 | struct nfs4_exception exception = { }; |
| 6818 | int err; |
| 6819 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6820 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6821 | fs_locations, page); |
| 6822 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6823 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6824 | &exception); |
| 6825 | } while (exception.retry); |
| 6826 | return err; |
| 6827 | } |
| 6828 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6829 | /* |
| 6830 | * This operation also signals the server that this client is |
| 6831 | * performing migration recovery. The server can stop returning |
| 6832 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6833 | * appended to this compound to identify the client ID which is |
| 6834 | * performing recovery. |
| 6835 | */ |
| 6836 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6837 | struct nfs4_fs_locations *locations, |
| 6838 | struct page *page, struct rpc_cred *cred) |
| 6839 | { |
| 6840 | struct nfs_server *server = NFS_SERVER(inode); |
| 6841 | struct rpc_clnt *clnt = server->client; |
| 6842 | u32 bitmask[2] = { |
| 6843 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6844 | }; |
| 6845 | struct nfs4_fs_locations_arg args = { |
| 6846 | .clientid = server->nfs_client->cl_clientid, |
| 6847 | .fh = NFS_FH(inode), |
| 6848 | .page = page, |
| 6849 | .bitmask = bitmask, |
| 6850 | .migration = 1, /* skip LOOKUP */ |
| 6851 | .renew = 1, /* append RENEW */ |
| 6852 | }; |
| 6853 | struct nfs4_fs_locations_res res = { |
| 6854 | .fs_locations = locations, |
| 6855 | .migration = 1, |
| 6856 | .renew = 1, |
| 6857 | }; |
| 6858 | struct rpc_message msg = { |
| 6859 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6860 | .rpc_argp = &args, |
| 6861 | .rpc_resp = &res, |
| 6862 | .rpc_cred = cred, |
| 6863 | }; |
| 6864 | unsigned long now = jiffies; |
| 6865 | int status; |
| 6866 | |
| 6867 | nfs_fattr_init(&locations->fattr); |
| 6868 | locations->server = server; |
| 6869 | locations->nlocations = 0; |
| 6870 | |
| 6871 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6872 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6873 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6874 | &args.seq_args, &res.seq_res); |
| 6875 | if (status) |
| 6876 | return status; |
| 6877 | |
| 6878 | renew_lease(server, now); |
| 6879 | return 0; |
| 6880 | } |
| 6881 | |
| 6882 | #ifdef CONFIG_NFS_V4_1 |
| 6883 | |
| 6884 | /* |
| 6885 | * This operation also signals the server that this client is |
| 6886 | * performing migration recovery. The server can stop asserting |
| 6887 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6888 | * performing this operation is identified in the SEQUENCE |
| 6889 | * operation in this compound. |
| 6890 | * |
| 6891 | * When the client supports GETATTR(fs_locations_info), it can |
| 6892 | * be plumbed in here. |
| 6893 | */ |
| 6894 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6895 | struct nfs4_fs_locations *locations, |
| 6896 | struct page *page, struct rpc_cred *cred) |
| 6897 | { |
| 6898 | struct nfs_server *server = NFS_SERVER(inode); |
| 6899 | struct rpc_clnt *clnt = server->client; |
| 6900 | u32 bitmask[2] = { |
| 6901 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6902 | }; |
| 6903 | struct nfs4_fs_locations_arg args = { |
| 6904 | .fh = NFS_FH(inode), |
| 6905 | .page = page, |
| 6906 | .bitmask = bitmask, |
| 6907 | .migration = 1, /* skip LOOKUP */ |
| 6908 | }; |
| 6909 | struct nfs4_fs_locations_res res = { |
| 6910 | .fs_locations = locations, |
| 6911 | .migration = 1, |
| 6912 | }; |
| 6913 | struct rpc_message msg = { |
| 6914 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6915 | .rpc_argp = &args, |
| 6916 | .rpc_resp = &res, |
| 6917 | .rpc_cred = cred, |
| 6918 | }; |
| 6919 | int status; |
| 6920 | |
| 6921 | nfs_fattr_init(&locations->fattr); |
| 6922 | locations->server = server; |
| 6923 | locations->nlocations = 0; |
| 6924 | |
| 6925 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6926 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6927 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6928 | &args.seq_args, &res.seq_res); |
| 6929 | if (status == NFS4_OK && |
| 6930 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6931 | status = -NFS4ERR_LEASE_MOVED; |
| 6932 | return status; |
| 6933 | } |
| 6934 | |
| 6935 | #endif /* CONFIG_NFS_V4_1 */ |
| 6936 | |
| 6937 | /** |
| 6938 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6939 | * @inode: inode on FSID that is migrating |
| 6940 | * @locations: result of query |
| 6941 | * @page: buffer |
| 6942 | * @cred: credential to use for this operation |
| 6943 | * |
| 6944 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6945 | * operation failed, or a negative errno if a local error occurred. |
| 6946 | * |
| 6947 | * On success, "locations" is filled in, but if the server has |
| 6948 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6949 | * asserted. |
| 6950 | * |
| 6951 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6952 | * from this client that require migration recovery. |
| 6953 | */ |
| 6954 | int nfs4_proc_get_locations(struct inode *inode, |
| 6955 | struct nfs4_fs_locations *locations, |
| 6956 | struct page *page, struct rpc_cred *cred) |
| 6957 | { |
| 6958 | struct nfs_server *server = NFS_SERVER(inode); |
| 6959 | struct nfs_client *clp = server->nfs_client; |
| 6960 | const struct nfs4_mig_recovery_ops *ops = |
| 6961 | clp->cl_mvops->mig_recovery_ops; |
| 6962 | struct nfs4_exception exception = { }; |
| 6963 | int status; |
| 6964 | |
| 6965 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6966 | (unsigned long long)server->fsid.major, |
| 6967 | (unsigned long long)server->fsid.minor, |
| 6968 | clp->cl_hostname); |
| 6969 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6970 | |
| 6971 | do { |
| 6972 | status = ops->get_locations(inode, locations, page, cred); |
| 6973 | if (status != -NFS4ERR_DELAY) |
| 6974 | break; |
| 6975 | nfs4_handle_exception(server, status, &exception); |
| 6976 | } while (exception.retry); |
| 6977 | return status; |
| 6978 | } |
| 6979 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6980 | /* |
| 6981 | * This operation also signals the server that this client is |
| 6982 | * performing "lease moved" recovery. The server can stop |
| 6983 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6984 | * is appended to this compound to identify the client ID which is |
| 6985 | * performing recovery. |
| 6986 | */ |
| 6987 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6988 | { |
| 6989 | struct nfs_server *server = NFS_SERVER(inode); |
| 6990 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6991 | struct rpc_clnt *clnt = server->client; |
| 6992 | struct nfs4_fsid_present_arg args = { |
| 6993 | .fh = NFS_FH(inode), |
| 6994 | .clientid = clp->cl_clientid, |
| 6995 | .renew = 1, /* append RENEW */ |
| 6996 | }; |
| 6997 | struct nfs4_fsid_present_res res = { |
| 6998 | .renew = 1, |
| 6999 | }; |
| 7000 | struct rpc_message msg = { |
| 7001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7002 | .rpc_argp = &args, |
| 7003 | .rpc_resp = &res, |
| 7004 | .rpc_cred = cred, |
| 7005 | }; |
| 7006 | unsigned long now = jiffies; |
| 7007 | int status; |
| 7008 | |
| 7009 | res.fh = nfs_alloc_fhandle(); |
| 7010 | if (res.fh == NULL) |
| 7011 | return -ENOMEM; |
| 7012 | |
| 7013 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7014 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7015 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7016 | &args.seq_args, &res.seq_res); |
| 7017 | nfs_free_fhandle(res.fh); |
| 7018 | if (status) |
| 7019 | return status; |
| 7020 | |
| 7021 | do_renew_lease(clp, now); |
| 7022 | return 0; |
| 7023 | } |
| 7024 | |
| 7025 | #ifdef CONFIG_NFS_V4_1 |
| 7026 | |
| 7027 | /* |
| 7028 | * This operation also signals the server that this client is |
| 7029 | * performing "lease moved" recovery. The server can stop asserting |
| 7030 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7031 | * this operation is identified in the SEQUENCE operation in this |
| 7032 | * compound. |
| 7033 | */ |
| 7034 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7035 | { |
| 7036 | struct nfs_server *server = NFS_SERVER(inode); |
| 7037 | struct rpc_clnt *clnt = server->client; |
| 7038 | struct nfs4_fsid_present_arg args = { |
| 7039 | .fh = NFS_FH(inode), |
| 7040 | }; |
| 7041 | struct nfs4_fsid_present_res res = { |
| 7042 | }; |
| 7043 | struct rpc_message msg = { |
| 7044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7045 | .rpc_argp = &args, |
| 7046 | .rpc_resp = &res, |
| 7047 | .rpc_cred = cred, |
| 7048 | }; |
| 7049 | int status; |
| 7050 | |
| 7051 | res.fh = nfs_alloc_fhandle(); |
| 7052 | if (res.fh == NULL) |
| 7053 | return -ENOMEM; |
| 7054 | |
| 7055 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7056 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7057 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7058 | &args.seq_args, &res.seq_res); |
| 7059 | nfs_free_fhandle(res.fh); |
| 7060 | if (status == NFS4_OK && |
| 7061 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7062 | status = -NFS4ERR_LEASE_MOVED; |
| 7063 | return status; |
| 7064 | } |
| 7065 | |
| 7066 | #endif /* CONFIG_NFS_V4_1 */ |
| 7067 | |
| 7068 | /** |
| 7069 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7070 | * @inode: inode on FSID to check |
| 7071 | * @cred: credential to use for this operation |
| 7072 | * |
| 7073 | * Server indicates whether the FSID is present, moved, or not |
| 7074 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7075 | * condition for this client ID. |
| 7076 | * |
| 7077 | * Returns NFS4_OK if the FSID is present on this server, |
| 7078 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7079 | * NFS4ERR code if some error occurred on the server, or a |
| 7080 | * negative errno if a local failure occurred. |
| 7081 | */ |
| 7082 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7083 | { |
| 7084 | struct nfs_server *server = NFS_SERVER(inode); |
| 7085 | struct nfs_client *clp = server->nfs_client; |
| 7086 | const struct nfs4_mig_recovery_ops *ops = |
| 7087 | clp->cl_mvops->mig_recovery_ops; |
| 7088 | struct nfs4_exception exception = { }; |
| 7089 | int status; |
| 7090 | |
| 7091 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7092 | (unsigned long long)server->fsid.major, |
| 7093 | (unsigned long long)server->fsid.minor, |
| 7094 | clp->cl_hostname); |
| 7095 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7096 | |
| 7097 | do { |
| 7098 | status = ops->fsid_present(inode, cred); |
| 7099 | if (status != -NFS4ERR_DELAY) |
| 7100 | break; |
| 7101 | nfs4_handle_exception(server, status, &exception); |
| 7102 | } while (exception.retry); |
| 7103 | return status; |
| 7104 | } |
| 7105 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7106 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7107 | * If 'use_integrity' is true and the state managment nfs_client |
| 7108 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7109 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7110 | * Considerations sections. Otherwise, just use the user cred with the |
| 7111 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7112 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7113 | 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] | 7114 | { |
| 7115 | int status; |
| 7116 | struct nfs4_secinfo_arg args = { |
| 7117 | .dir_fh = NFS_FH(dir), |
| 7118 | .name = name, |
| 7119 | }; |
| 7120 | struct nfs4_secinfo_res res = { |
| 7121 | .flavors = flavors, |
| 7122 | }; |
| 7123 | struct rpc_message msg = { |
| 7124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7125 | .rpc_argp = &args, |
| 7126 | .rpc_resp = &res, |
| 7127 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7128 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7129 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7130 | |
| 7131 | if (use_integrity) { |
| 7132 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7133 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7134 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7135 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7136 | |
| 7137 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7138 | |
| 7139 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7140 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7141 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7142 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7143 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7144 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7145 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7146 | if (cred) |
| 7147 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7148 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7149 | return status; |
| 7150 | } |
| 7151 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7152 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7153 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7154 | { |
| 7155 | struct nfs4_exception exception = { }; |
| 7156 | int err; |
| 7157 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7158 | err = -NFS4ERR_WRONGSEC; |
| 7159 | |
| 7160 | /* try to use integrity protection with machine cred */ |
| 7161 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7162 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7163 | |
| 7164 | /* |
| 7165 | * if unable to use integrity protection, or SECINFO with |
| 7166 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7167 | * disallowed by spec, but exists in deployed servers) use |
| 7168 | * the current filesystem's rpc_client and the user cred. |
| 7169 | */ |
| 7170 | if (err == -NFS4ERR_WRONGSEC) |
| 7171 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7172 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7173 | trace_nfs4_secinfo(dir, name, err); |
| 7174 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7175 | &exception); |
| 7176 | } while (exception.retry); |
| 7177 | return err; |
| 7178 | } |
| 7179 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7180 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7181 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7182 | * Check the exchange flags returned by the server for invalid flags, having |
| 7183 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7184 | * DS flags set. |
| 7185 | */ |
| 7186 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7187 | { |
| 7188 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7189 | goto out_inval; |
| 7190 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7191 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7192 | goto out_inval; |
| 7193 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7194 | goto out_inval; |
| 7195 | return NFS_OK; |
| 7196 | out_inval: |
| 7197 | return -NFS4ERR_INVAL; |
| 7198 | } |
| 7199 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7200 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7201 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7202 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7203 | { |
| 7204 | if (a->server_scope_sz == b->server_scope_sz && |
| 7205 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7206 | return true; |
| 7207 | |
| 7208 | return false; |
| 7209 | } |
| 7210 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7211 | static void |
| 7212 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7213 | { |
| 7214 | } |
| 7215 | |
| 7216 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7217 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7218 | }; |
| 7219 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7220 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7221 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7222 | * |
| 7223 | * The 4.1 client currently uses the same TCP connection for the |
| 7224 | * fore and backchannel. |
| 7225 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7226 | static |
| 7227 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7228 | struct rpc_xprt *xprt, |
| 7229 | struct nfs_client *clp, |
| 7230 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7231 | { |
| 7232 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7233 | struct nfs41_bind_conn_to_session_args args = { |
| 7234 | .client = clp, |
| 7235 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7236 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7237 | struct nfs41_bind_conn_to_session_res res; |
| 7238 | struct rpc_message msg = { |
| 7239 | .rpc_proc = |
| 7240 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7241 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7242 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7243 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7244 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7245 | struct rpc_task_setup task_setup_data = { |
| 7246 | .rpc_client = clnt, |
| 7247 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7248 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7249 | .rpc_message = &msg, |
| 7250 | .flags = RPC_TASK_TIMEOUT, |
| 7251 | }; |
| 7252 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7253 | |
| 7254 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7255 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7256 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7257 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7258 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7259 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7260 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7261 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7262 | args.dir = NFS4_CDFC4_FORE; |
| 7263 | |
| 7264 | task = rpc_run_task(&task_setup_data); |
| 7265 | if (!IS_ERR(task)) { |
| 7266 | status = task->tk_status; |
| 7267 | rpc_put_task(task); |
| 7268 | } else |
| 7269 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7270 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7271 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7272 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7273 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7274 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7275 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7276 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7277 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7278 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7279 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7280 | __func__); |
| 7281 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7282 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7283 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7284 | 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] | 7285 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7286 | __func__); |
| 7287 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7288 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7289 | } |
| 7290 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7291 | out: |
| 7292 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7293 | return status; |
| 7294 | } |
| 7295 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7296 | struct rpc_bind_conn_calldata { |
| 7297 | struct nfs_client *clp; |
| 7298 | struct rpc_cred *cred; |
| 7299 | }; |
| 7300 | |
| 7301 | static int |
| 7302 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7303 | struct rpc_xprt *xprt, |
| 7304 | void *calldata) |
| 7305 | { |
| 7306 | struct rpc_bind_conn_calldata *p = calldata; |
| 7307 | |
| 7308 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7309 | } |
| 7310 | |
| 7311 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7312 | { |
| 7313 | struct rpc_bind_conn_calldata data = { |
| 7314 | .clp = clp, |
| 7315 | .cred = cred, |
| 7316 | }; |
| 7317 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7318 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7319 | } |
| 7320 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7321 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7322 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7323 | * 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] | 7324 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7325 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7326 | .how = SP4_MACH_CRED, |
| 7327 | .enforce.u.words = { |
| 7328 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7329 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7330 | 1 << (OP_CREATE_SESSION - 32) | |
| 7331 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7332 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7333 | }, |
| 7334 | .allow.u.words = { |
| 7335 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7336 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7337 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7338 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7339 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7340 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7341 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7342 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7343 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7344 | 1 << (OP_FREE_STATEID - 32) | |
| 7345 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7346 | } |
| 7347 | }; |
| 7348 | |
| 7349 | /* |
| 7350 | * Select the state protection mode for client `clp' given the server results |
| 7351 | * from exchange_id in `sp'. |
| 7352 | * |
| 7353 | * Returns 0 on success, negative errno otherwise. |
| 7354 | */ |
| 7355 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7356 | struct nfs41_state_protection *sp) |
| 7357 | { |
| 7358 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7359 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7360 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7361 | 1 << (OP_CREATE_SESSION - 32) | |
| 7362 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7363 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7364 | }; |
| 7365 | unsigned int i; |
| 7366 | |
| 7367 | if (sp->how == SP4_MACH_CRED) { |
| 7368 | /* Print state protect result */ |
| 7369 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7370 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7371 | if (test_bit(i, sp->enforce.u.longs)) |
| 7372 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7373 | if (test_bit(i, sp->allow.u.longs)) |
| 7374 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7375 | } |
| 7376 | |
| 7377 | /* make sure nothing is on enforce list that isn't supported */ |
| 7378 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7379 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7380 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7381 | return -EINVAL; |
| 7382 | } |
| 7383 | } |
| 7384 | |
| 7385 | /* |
| 7386 | * Minimal mode - state operations are allowed to use machine |
| 7387 | * credential. Note this already happens by default, so the |
| 7388 | * client doesn't have to do anything more than the negotiation. |
| 7389 | * |
| 7390 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7391 | * we're already using the machine cred for exchange_id |
| 7392 | * and will never use a different cred. |
| 7393 | */ |
| 7394 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7395 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7396 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7397 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7398 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7399 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7400 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7401 | } else { |
| 7402 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7403 | return -EINVAL; |
| 7404 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7405 | |
| 7406 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7407 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7408 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7409 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7410 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7411 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7412 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7413 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7414 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7415 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7416 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7417 | &clp->cl_sp4_flags); |
| 7418 | } |
| 7419 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7420 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7421 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7422 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7423 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7424 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7425 | |
| 7426 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7427 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7428 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7429 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7430 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7431 | |
| 7432 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7433 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7434 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7435 | } |
| 7436 | |
| 7437 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7438 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7439 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7440 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7441 | } |
| 7442 | |
| 7443 | return 0; |
| 7444 | } |
| 7445 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7446 | struct nfs41_exchange_id_data { |
| 7447 | struct nfs41_exchange_id_res res; |
| 7448 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7449 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7450 | int rpc_status; |
| 7451 | }; |
| 7452 | |
| 7453 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7454 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7455 | struct nfs41_exchange_id_data *cdata = |
| 7456 | (struct nfs41_exchange_id_data *)data; |
| 7457 | struct nfs_client *clp = cdata->args.client; |
| 7458 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7459 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7460 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7461 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7462 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7463 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7464 | |
| 7465 | if (cdata->xprt && status == 0) { |
| 7466 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7467 | cdata->xprt); |
| 7468 | goto out; |
| 7469 | } |
| 7470 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7471 | if (status == 0) |
| 7472 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7473 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7474 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7475 | clp->cl_clientid = cdata->res.clientid; |
| 7476 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7477 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7478 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7479 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7480 | &clp->cl_session->session_state); |
| 7481 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7482 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7483 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7484 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7485 | clp->cl_serverowner = cdata->res.server_owner; |
| 7486 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7487 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7488 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7489 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7490 | clp->cl_implid = cdata->res.impl_id; |
| 7491 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7492 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7493 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7494 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7495 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7496 | dprintk("%s: server_scope mismatch detected\n", |
| 7497 | __func__); |
| 7498 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7499 | kfree(clp->cl_serverscope); |
| 7500 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7501 | } |
| 7502 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7503 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7504 | clp->cl_serverscope = cdata->res.server_scope; |
| 7505 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7506 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7507 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7508 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7509 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7510 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7511 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7512 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7513 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7514 | } |
| 7515 | |
| 7516 | static void nfs4_exchange_id_release(void *data) |
| 7517 | { |
| 7518 | struct nfs41_exchange_id_data *cdata = |
| 7519 | (struct nfs41_exchange_id_data *)data; |
| 7520 | |
| 7521 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7522 | if (cdata->xprt) { |
| 7523 | xprt_put(cdata->xprt); |
| 7524 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7525 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7526 | kfree(cdata->res.impl_id); |
| 7527 | kfree(cdata->res.server_scope); |
| 7528 | kfree(cdata->res.server_owner); |
| 7529 | kfree(cdata); |
| 7530 | } |
| 7531 | |
| 7532 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7533 | .rpc_call_done = nfs4_exchange_id_done, |
| 7534 | .rpc_release = nfs4_exchange_id_release, |
| 7535 | }; |
| 7536 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7537 | /* |
| 7538 | * _nfs4_proc_exchange_id() |
| 7539 | * |
| 7540 | * Wrapper for EXCHANGE_ID operation. |
| 7541 | */ |
| 7542 | 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] | 7543 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7544 | { |
| 7545 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7546 | struct rpc_message msg = { |
| 7547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7548 | .rpc_cred = cred, |
| 7549 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7550 | struct rpc_task_setup task_setup_data = { |
| 7551 | .rpc_client = clp->cl_rpcclient, |
| 7552 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7553 | .rpc_message = &msg, |
| 7554 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7555 | }; |
| 7556 | struct nfs41_exchange_id_data *calldata; |
| 7557 | struct rpc_task *task; |
| 7558 | int status = -EIO; |
| 7559 | |
| 7560 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7561 | goto out; |
| 7562 | |
| 7563 | status = -ENOMEM; |
| 7564 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7565 | if (!calldata) |
| 7566 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7567 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7568 | if (!xprt) |
| 7569 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7570 | |
| 7571 | status = nfs4_init_uniform_client_string(clp); |
| 7572 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7573 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7574 | |
| 7575 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7576 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7577 | clp->cl_owner_id); |
| 7578 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7579 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7580 | GFP_NOFS); |
| 7581 | status = -ENOMEM; |
| 7582 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7583 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7584 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7585 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7586 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7587 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7588 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7589 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7590 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7591 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7592 | goto out_server_scope; |
| 7593 | |
| 7594 | switch (sp4_how) { |
| 7595 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7596 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7597 | break; |
| 7598 | |
| 7599 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7600 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7601 | break; |
| 7602 | |
| 7603 | default: |
| 7604 | /* unsupported! */ |
| 7605 | WARN_ON_ONCE(1); |
| 7606 | status = -EINVAL; |
| 7607 | goto out_impl_id; |
| 7608 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7609 | if (xprt) { |
| 7610 | calldata->xprt = xprt; |
| 7611 | task_setup_data.rpc_xprt = xprt; |
| 7612 | task_setup_data.flags = |
| 7613 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7614 | calldata->args.verifier = &clp->cl_confirm; |
| 7615 | } else { |
| 7616 | calldata->args.verifier = &verifier; |
| 7617 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7618 | calldata->args.client = clp; |
| 7619 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7620 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7621 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7622 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7623 | #else |
| 7624 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7625 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7626 | #endif |
| 7627 | msg.rpc_argp = &calldata->args; |
| 7628 | msg.rpc_resp = &calldata->res; |
| 7629 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7630 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7631 | task = rpc_run_task(&task_setup_data); |
| 7632 | if (IS_ERR(task)) { |
| 7633 | status = PTR_ERR(task); |
| 7634 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7635 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7636 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7637 | if (!xprt) { |
| 7638 | status = rpc_wait_for_completion_task(task); |
| 7639 | if (!status) |
| 7640 | status = calldata->rpc_status; |
| 7641 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7642 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7643 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7644 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7645 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7646 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7647 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7648 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7649 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7650 | clp->cl_implid->date.seconds, |
| 7651 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7652 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7653 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7654 | |
| 7655 | out_impl_id: |
| 7656 | kfree(calldata->res.impl_id); |
| 7657 | out_server_scope: |
| 7658 | kfree(calldata->res.server_scope); |
| 7659 | out_server_owner: |
| 7660 | kfree(calldata->res.server_owner); |
| 7661 | out_calldata: |
| 7662 | kfree(calldata); |
| 7663 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7664 | } |
| 7665 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7666 | /* |
| 7667 | * nfs4_proc_exchange_id() |
| 7668 | * |
| 7669 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7670 | * |
| 7671 | * Since the clientid has expired, all compounds using sessions |
| 7672 | * associated with the stale clientid will be returning |
| 7673 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7674 | * be in some phase of session reset. |
| 7675 | * |
| 7676 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7677 | */ |
| 7678 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7679 | { |
| 7680 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7681 | int status; |
| 7682 | |
| 7683 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7684 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7685 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7686 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7687 | if (!status) |
| 7688 | return 0; |
| 7689 | } |
| 7690 | |
| 7691 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7692 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7693 | } |
| 7694 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7695 | /** |
| 7696 | * nfs4_test_session_trunk |
| 7697 | * |
| 7698 | * This is an add_xprt_test() test function called from |
| 7699 | * rpc_clnt_setup_test_and_add_xprt. |
| 7700 | * |
| 7701 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7702 | * and is dereferrenced in nfs4_exchange_id_release |
| 7703 | * |
| 7704 | * Upon success, add the new transport to the rpc_clnt |
| 7705 | * |
| 7706 | * @clnt: struct rpc_clnt to get new transport |
| 7707 | * @xprt: the rpc_xprt to test |
| 7708 | * @data: call data for _nfs4_proc_exchange_id. |
| 7709 | */ |
| 7710 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7711 | void *data) |
| 7712 | { |
| 7713 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7714 | u32 sp4_how; |
| 7715 | |
| 7716 | dprintk("--> %s try %s\n", __func__, |
| 7717 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7718 | |
| 7719 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7720 | |
| 7721 | /* Test connection for session trunking. Async exchange_id call */ |
| 7722 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7723 | } |
| 7724 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7725 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7726 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7727 | struct rpc_cred *cred) |
| 7728 | { |
| 7729 | struct rpc_message msg = { |
| 7730 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7731 | .rpc_argp = clp, |
| 7732 | .rpc_cred = cred, |
| 7733 | }; |
| 7734 | int status; |
| 7735 | |
| 7736 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7737 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7738 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7739 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7740 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7741 | return status; |
| 7742 | } |
| 7743 | |
| 7744 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7745 | struct rpc_cred *cred) |
| 7746 | { |
| 7747 | unsigned int loop; |
| 7748 | int ret; |
| 7749 | |
| 7750 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7751 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7752 | switch (ret) { |
| 7753 | case -NFS4ERR_DELAY: |
| 7754 | case -NFS4ERR_CLIENTID_BUSY: |
| 7755 | ssleep(1); |
| 7756 | break; |
| 7757 | default: |
| 7758 | return ret; |
| 7759 | } |
| 7760 | } |
| 7761 | return 0; |
| 7762 | } |
| 7763 | |
| 7764 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7765 | { |
| 7766 | struct rpc_cred *cred; |
| 7767 | int ret = 0; |
| 7768 | |
| 7769 | if (clp->cl_mvops->minor_version < 1) |
| 7770 | goto out; |
| 7771 | if (clp->cl_exchange_flags == 0) |
| 7772 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7773 | if (clp->cl_preserve_clid) |
| 7774 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7775 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7776 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7777 | if (cred) |
| 7778 | put_rpccred(cred); |
| 7779 | switch (ret) { |
| 7780 | case 0: |
| 7781 | case -NFS4ERR_STALE_CLIENTID: |
| 7782 | clp->cl_exchange_flags = 0; |
| 7783 | } |
| 7784 | out: |
| 7785 | return ret; |
| 7786 | } |
| 7787 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7788 | struct nfs4_get_lease_time_data { |
| 7789 | struct nfs4_get_lease_time_args *args; |
| 7790 | struct nfs4_get_lease_time_res *res; |
| 7791 | struct nfs_client *clp; |
| 7792 | }; |
| 7793 | |
| 7794 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7795 | void *calldata) |
| 7796 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7797 | struct nfs4_get_lease_time_data *data = |
| 7798 | (struct nfs4_get_lease_time_data *)calldata; |
| 7799 | |
| 7800 | dprintk("--> %s\n", __func__); |
| 7801 | /* just setup sequence, do not trigger session recovery |
| 7802 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7803 | nfs41_setup_sequence(data->clp->cl_session, |
| 7804 | &data->args->la_seq_args, |
| 7805 | &data->res->lr_seq_res, |
| 7806 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7807 | dprintk("<-- %s\n", __func__); |
| 7808 | } |
| 7809 | |
| 7810 | /* |
| 7811 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7812 | * from sequence operation or clientid errors. |
| 7813 | */ |
| 7814 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7815 | { |
| 7816 | struct nfs4_get_lease_time_data *data = |
| 7817 | (struct nfs4_get_lease_time_data *)calldata; |
| 7818 | |
| 7819 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7820 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7821 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7822 | switch (task->tk_status) { |
| 7823 | case -NFS4ERR_DELAY: |
| 7824 | case -NFS4ERR_GRACE: |
| 7825 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7826 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7827 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7828 | /* fall through */ |
| 7829 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7830 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7831 | return; |
| 7832 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7833 | dprintk("<-- %s\n", __func__); |
| 7834 | } |
| 7835 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7836 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7837 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7838 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7839 | }; |
| 7840 | |
| 7841 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7842 | { |
| 7843 | struct rpc_task *task; |
| 7844 | struct nfs4_get_lease_time_args args; |
| 7845 | struct nfs4_get_lease_time_res res = { |
| 7846 | .lr_fsinfo = fsinfo, |
| 7847 | }; |
| 7848 | struct nfs4_get_lease_time_data data = { |
| 7849 | .args = &args, |
| 7850 | .res = &res, |
| 7851 | .clp = clp, |
| 7852 | }; |
| 7853 | struct rpc_message msg = { |
| 7854 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7855 | .rpc_argp = &args, |
| 7856 | .rpc_resp = &res, |
| 7857 | }; |
| 7858 | struct rpc_task_setup task_setup = { |
| 7859 | .rpc_client = clp->cl_rpcclient, |
| 7860 | .rpc_message = &msg, |
| 7861 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7862 | .callback_data = &data, |
| 7863 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7864 | }; |
| 7865 | int status; |
| 7866 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7867 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7868 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7869 | dprintk("--> %s\n", __func__); |
| 7870 | task = rpc_run_task(&task_setup); |
| 7871 | |
| 7872 | if (IS_ERR(task)) |
| 7873 | status = PTR_ERR(task); |
| 7874 | else { |
| 7875 | status = task->tk_status; |
| 7876 | rpc_put_task(task); |
| 7877 | } |
| 7878 | dprintk("<-- %s return %d\n", __func__, status); |
| 7879 | |
| 7880 | return status; |
| 7881 | } |
| 7882 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7883 | /* |
| 7884 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7885 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7886 | * use them. |
| 7887 | * |
| 7888 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7889 | * always set csa_cachethis to FALSE because the current implementation |
| 7890 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7891 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7892 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7893 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7894 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7895 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7896 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7897 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7898 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7899 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7900 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7901 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7902 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7903 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7904 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7905 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7906 | |
| 7907 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7908 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7909 | __func__, |
| 7910 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7911 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7912 | |
| 7913 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7914 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7915 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7916 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7917 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7918 | 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] | 7919 | |
| 7920 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7921 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7922 | __func__, |
| 7923 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7924 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7925 | args->bc_attrs.max_reqs); |
| 7926 | } |
| 7927 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7928 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7929 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7930 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7931 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7932 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7933 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7934 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7935 | return -EINVAL; |
| 7936 | /* |
| 7937 | * Our requested max_ops is the minimum we need; we're not |
| 7938 | * prepared to break up compounds into smaller pieces than that. |
| 7939 | * So, no point even trying to continue if the server won't |
| 7940 | * cooperate: |
| 7941 | */ |
| 7942 | if (rcvd->max_ops < sent->max_ops) |
| 7943 | return -EINVAL; |
| 7944 | if (rcvd->max_reqs == 0) |
| 7945 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7946 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7947 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7948 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7949 | } |
| 7950 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7951 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7952 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7953 | { |
| 7954 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7955 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7956 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7957 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7958 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7959 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7960 | return -EINVAL; |
| 7961 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7962 | return -EINVAL; |
| 7963 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7964 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7965 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7966 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7967 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7968 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7969 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7970 | return 0; |
| 7971 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7972 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7973 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7974 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7975 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7976 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7977 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7978 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7979 | if (ret) |
| 7980 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7981 | return nfs4_verify_back_channel_attrs(args, res); |
| 7982 | } |
| 7983 | |
| 7984 | static void nfs4_update_session(struct nfs4_session *session, |
| 7985 | struct nfs41_create_session_res *res) |
| 7986 | { |
| 7987 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7988 | /* Mark client id and session as being confirmed */ |
| 7989 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7990 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7991 | session->flags = res->flags; |
| 7992 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7993 | if (res->flags & SESSION4_BACK_CHAN) |
| 7994 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7995 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7996 | } |
| 7997 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7998 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7999 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8000 | { |
| 8001 | struct nfs4_session *session = clp->cl_session; |
| 8002 | struct nfs41_create_session_args args = { |
| 8003 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8004 | .clientid = clp->cl_clientid, |
| 8005 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8006 | .cb_program = NFS4_CALLBACK, |
| 8007 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8008 | struct nfs41_create_session_res res; |
| 8009 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8010 | struct rpc_message msg = { |
| 8011 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 8012 | .rpc_argp = &args, |
| 8013 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8014 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8015 | }; |
| 8016 | int status; |
| 8017 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 8018 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 8019 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8020 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8021 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8022 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8023 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8024 | switch (status) { |
| 8025 | case -NFS4ERR_STALE_CLIENTID: |
| 8026 | case -NFS4ERR_DELAY: |
| 8027 | case -ETIMEDOUT: |
| 8028 | case -EACCES: |
| 8029 | case -EAGAIN: |
| 8030 | goto out; |
| 8031 | }; |
| 8032 | |
| 8033 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8034 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8035 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8036 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8037 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8038 | if (status) |
| 8039 | goto out; |
| 8040 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8041 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8042 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8043 | return status; |
| 8044 | } |
| 8045 | |
| 8046 | /* |
| 8047 | * Issues a CREATE_SESSION operation to the server. |
| 8048 | * It is the responsibility of the caller to verify the session is |
| 8049 | * expired before calling this routine. |
| 8050 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8051 | 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] | 8052 | { |
| 8053 | int status; |
| 8054 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8055 | struct nfs4_session *session = clp->cl_session; |
| 8056 | |
| 8057 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8058 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8059 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8060 | if (status) |
| 8061 | goto out; |
| 8062 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8063 | /* Init or reset the session slot tables */ |
| 8064 | status = nfs4_setup_session_slot_tables(session); |
| 8065 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8066 | if (status) |
| 8067 | goto out; |
| 8068 | |
| 8069 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8070 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8071 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8072 | out: |
| 8073 | dprintk("<-- %s\n", __func__); |
| 8074 | return status; |
| 8075 | } |
| 8076 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8077 | /* |
| 8078 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8079 | * The caller must serialize access to this routine. |
| 8080 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8081 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8082 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8083 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8084 | struct rpc_message msg = { |
| 8085 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8086 | .rpc_argp = session, |
| 8087 | .rpc_cred = cred, |
| 8088 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8089 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8090 | |
| 8091 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8092 | |
| 8093 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8094 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8095 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8096 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8097 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8098 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8099 | |
| 8100 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8101 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8102 | "Session has been destroyed regardless...\n", status); |
| 8103 | |
| 8104 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8105 | return status; |
| 8106 | } |
| 8107 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8108 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8109 | * Renew the cl_session lease. |
| 8110 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8111 | struct nfs4_sequence_data { |
| 8112 | struct nfs_client *clp; |
| 8113 | struct nfs4_sequence_args args; |
| 8114 | struct nfs4_sequence_res res; |
| 8115 | }; |
| 8116 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8117 | static void nfs41_sequence_release(void *data) |
| 8118 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8119 | struct nfs4_sequence_data *calldata = data; |
| 8120 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8121 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8122 | if (atomic_read(&clp->cl_count) > 1) |
| 8123 | nfs4_schedule_state_renewal(clp); |
| 8124 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8125 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8126 | } |
| 8127 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8128 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8129 | { |
| 8130 | switch(task->tk_status) { |
| 8131 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8132 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8133 | return -EAGAIN; |
| 8134 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8135 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8136 | } |
| 8137 | return 0; |
| 8138 | } |
| 8139 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8140 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8141 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8142 | struct nfs4_sequence_data *calldata = data; |
| 8143 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8144 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8145 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8146 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8147 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8148 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8149 | if (task->tk_status < 0) { |
| 8150 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8151 | if (atomic_read(&clp->cl_count) == 1) |
| 8152 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8153 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8154 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8155 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8156 | return; |
| 8157 | } |
| 8158 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8159 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8160 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8161 | dprintk("<-- %s\n", __func__); |
| 8162 | } |
| 8163 | |
| 8164 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8165 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8166 | struct nfs4_sequence_data *calldata = data; |
| 8167 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8168 | struct nfs4_sequence_args *args; |
| 8169 | struct nfs4_sequence_res *res; |
| 8170 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8171 | args = task->tk_msg.rpc_argp; |
| 8172 | res = task->tk_msg.rpc_resp; |
| 8173 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8174 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8175 | } |
| 8176 | |
| 8177 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8178 | .rpc_call_done = nfs41_sequence_call_done, |
| 8179 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8180 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8181 | }; |
| 8182 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8183 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8184 | struct rpc_cred *cred, |
| 8185 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8186 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8187 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8188 | struct rpc_message msg = { |
| 8189 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8190 | .rpc_cred = cred, |
| 8191 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8192 | struct rpc_task_setup task_setup_data = { |
| 8193 | .rpc_client = clp->cl_rpcclient, |
| 8194 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8195 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8196 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8197 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8198 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8199 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8200 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8201 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8202 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8203 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8204 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8205 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8206 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8207 | if (is_privileged) |
| 8208 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8209 | msg.rpc_argp = &calldata->args; |
| 8210 | msg.rpc_resp = &calldata->res; |
| 8211 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8212 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8213 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8214 | return rpc_run_task(&task_setup_data); |
| 8215 | } |
| 8216 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8217 | 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] | 8218 | { |
| 8219 | struct rpc_task *task; |
| 8220 | int ret = 0; |
| 8221 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8222 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8223 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8224 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8225 | if (IS_ERR(task)) |
| 8226 | ret = PTR_ERR(task); |
| 8227 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8228 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8229 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8230 | return ret; |
| 8231 | } |
| 8232 | |
| 8233 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8234 | { |
| 8235 | struct rpc_task *task; |
| 8236 | int ret; |
| 8237 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8238 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8239 | if (IS_ERR(task)) { |
| 8240 | ret = PTR_ERR(task); |
| 8241 | goto out; |
| 8242 | } |
| 8243 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8244 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8245 | ret = task->tk_status; |
| 8246 | rpc_put_task(task); |
| 8247 | out: |
| 8248 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8249 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8250 | } |
| 8251 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8252 | struct nfs4_reclaim_complete_data { |
| 8253 | struct nfs_client *clp; |
| 8254 | struct nfs41_reclaim_complete_args arg; |
| 8255 | struct nfs41_reclaim_complete_res res; |
| 8256 | }; |
| 8257 | |
| 8258 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8259 | { |
| 8260 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8261 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8262 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8263 | &calldata->arg.seq_args, |
| 8264 | &calldata->res.seq_res, |
| 8265 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8266 | } |
| 8267 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8268 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8269 | { |
| 8270 | switch(task->tk_status) { |
| 8271 | case 0: |
| 8272 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8273 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8274 | break; |
| 8275 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8276 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8277 | /* fall through */ |
| 8278 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8279 | return -EAGAIN; |
| 8280 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8281 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8282 | } |
| 8283 | return 0; |
| 8284 | } |
| 8285 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8286 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8287 | { |
| 8288 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8289 | struct nfs_client *clp = calldata->clp; |
| 8290 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8291 | |
| 8292 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8293 | if (!nfs41_sequence_done(task, res)) |
| 8294 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8295 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8296 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8297 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8298 | rpc_restart_call_prepare(task); |
| 8299 | return; |
| 8300 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8301 | dprintk("<-- %s\n", __func__); |
| 8302 | } |
| 8303 | |
| 8304 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8305 | { |
| 8306 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8307 | |
| 8308 | kfree(calldata); |
| 8309 | } |
| 8310 | |
| 8311 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8312 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8313 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8314 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8315 | }; |
| 8316 | |
| 8317 | /* |
| 8318 | * Issue a global reclaim complete. |
| 8319 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8320 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8321 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8322 | { |
| 8323 | struct nfs4_reclaim_complete_data *calldata; |
| 8324 | struct rpc_task *task; |
| 8325 | struct rpc_message msg = { |
| 8326 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8327 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8328 | }; |
| 8329 | struct rpc_task_setup task_setup_data = { |
| 8330 | .rpc_client = clp->cl_rpcclient, |
| 8331 | .rpc_message = &msg, |
| 8332 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8333 | .flags = RPC_TASK_ASYNC, |
| 8334 | }; |
| 8335 | int status = -ENOMEM; |
| 8336 | |
| 8337 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8338 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8339 | if (calldata == NULL) |
| 8340 | goto out; |
| 8341 | calldata->clp = clp; |
| 8342 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8343 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8344 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8345 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8346 | msg.rpc_argp = &calldata->arg; |
| 8347 | msg.rpc_resp = &calldata->res; |
| 8348 | task_setup_data.callback_data = calldata; |
| 8349 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8350 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8351 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8352 | goto out; |
| 8353 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8354 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8355 | if (status == 0) |
| 8356 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8357 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8358 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8359 | out: |
| 8360 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8361 | return status; |
| 8362 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8363 | |
| 8364 | static void |
| 8365 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8366 | { |
| 8367 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8368 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8369 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8370 | |
| 8371 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8372 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8373 | &lgp->res.seq_res, task); |
| 8374 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8375 | } |
| 8376 | |
| 8377 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8378 | { |
| 8379 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8380 | |
| 8381 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8382 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8383 | dprintk("<-- %s\n", __func__); |
| 8384 | } |
| 8385 | |
| 8386 | static int |
| 8387 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8388 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8389 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8390 | struct inode *inode = lgp->args.inode; |
| 8391 | struct nfs_server *server = NFS_SERVER(inode); |
| 8392 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8393 | int nfs4err = task->tk_status; |
| 8394 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8395 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8396 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8397 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8398 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8399 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8400 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8401 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8402 | |
| 8403 | /* |
| 8404 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8405 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8406 | * retry go inband. |
| 8407 | */ |
| 8408 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8409 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8410 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8411 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8412 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8413 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8414 | */ |
| 8415 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8416 | status = -EOVERFLOW; |
| 8417 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8418 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8419 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8420 | * (or clients) writing to the same RAID stripe except when |
| 8421 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8422 | * |
| 8423 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8424 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8425 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8426 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8427 | if (lgp->args.minlength == 0) { |
| 8428 | status = -EOVERFLOW; |
| 8429 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8430 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8431 | status = -EBUSY; |
| 8432 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8433 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8434 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8435 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8436 | case -NFS4ERR_DELEG_REVOKED: |
| 8437 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8438 | case -NFS4ERR_EXPIRED: |
| 8439 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8440 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8441 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8442 | lo = NFS_I(inode)->layout; |
| 8443 | /* If the open stateid was bad, then recover it. */ |
| 8444 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8445 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8446 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8447 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8448 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8449 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8450 | break; |
| 8451 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8452 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8453 | /* |
| 8454 | * Mark the bad layout state as invalid, then retry |
| 8455 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8456 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8457 | spin_unlock(&inode->i_lock); |
| 8458 | pnfs_free_lseg_list(&head); |
| 8459 | status = -EAGAIN; |
| 8460 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8461 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8462 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8463 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8464 | if (!status) { |
| 8465 | if (exception->retry) |
| 8466 | status = -EAGAIN; |
| 8467 | else |
| 8468 | status = err; |
| 8469 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8470 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8471 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8472 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8473 | } |
| 8474 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8475 | static size_t max_response_pages(struct nfs_server *server) |
| 8476 | { |
| 8477 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8478 | return nfs_page_array_len(0, max_resp_sz); |
| 8479 | } |
| 8480 | |
| 8481 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8482 | { |
| 8483 | int i; |
| 8484 | |
| 8485 | if (!pages) |
| 8486 | return; |
| 8487 | |
| 8488 | for (i = 0; i < size; i++) { |
| 8489 | if (!pages[i]) |
| 8490 | break; |
| 8491 | __free_page(pages[i]); |
| 8492 | } |
| 8493 | kfree(pages); |
| 8494 | } |
| 8495 | |
| 8496 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8497 | { |
| 8498 | struct page **pages; |
| 8499 | int i; |
| 8500 | |
| 8501 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8502 | if (!pages) { |
| 8503 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8504 | return NULL; |
| 8505 | } |
| 8506 | |
| 8507 | for (i = 0; i < size; i++) { |
| 8508 | pages[i] = alloc_page(gfp_flags); |
| 8509 | if (!pages[i]) { |
| 8510 | dprintk("%s: failed to allocate page\n", __func__); |
| 8511 | nfs4_free_pages(pages, size); |
| 8512 | return NULL; |
| 8513 | } |
| 8514 | } |
| 8515 | |
| 8516 | return pages; |
| 8517 | } |
| 8518 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8519 | static void nfs4_layoutget_release(void *calldata) |
| 8520 | { |
| 8521 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8522 | struct inode *inode = lgp->args.inode; |
| 8523 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8524 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8525 | |
| 8526 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8527 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8528 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8529 | put_nfs_open_context(lgp->args.ctx); |
| 8530 | kfree(calldata); |
| 8531 | dprintk("<-- %s\n", __func__); |
| 8532 | } |
| 8533 | |
| 8534 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8535 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8536 | .rpc_call_done = nfs4_layoutget_done, |
| 8537 | .rpc_release = nfs4_layoutget_release, |
| 8538 | }; |
| 8539 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8540 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8541 | 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] | 8542 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8543 | struct inode *inode = lgp->args.inode; |
| 8544 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8545 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8546 | struct rpc_task *task; |
| 8547 | struct rpc_message msg = { |
| 8548 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8549 | .rpc_argp = &lgp->args, |
| 8550 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8551 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8552 | }; |
| 8553 | struct rpc_task_setup task_setup_data = { |
| 8554 | .rpc_client = server->client, |
| 8555 | .rpc_message = &msg, |
| 8556 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8557 | .callback_data = lgp, |
| 8558 | .flags = RPC_TASK_ASYNC, |
| 8559 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8560 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8561 | struct nfs4_exception exception = { |
| 8562 | .inode = inode, |
| 8563 | .timeout = *timeout, |
| 8564 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8565 | int status = 0; |
| 8566 | |
| 8567 | dprintk("--> %s\n", __func__); |
| 8568 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8569 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8570 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8571 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8572 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8573 | if (!lgp->args.layout.pages) { |
| 8574 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8575 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8576 | } |
| 8577 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8578 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8579 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8580 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8581 | 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] | 8582 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8583 | task = rpc_run_task(&task_setup_data); |
| 8584 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8585 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8586 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8587 | if (status == 0) { |
| 8588 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8589 | *timeout = exception.timeout; |
| 8590 | } |
| 8591 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8592 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8593 | &lgp->args.range, |
| 8594 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8595 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8596 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8597 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8598 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8599 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8600 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8601 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8602 | rpc_put_task(task); |
| 8603 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8604 | if (status) |
| 8605 | return ERR_PTR(status); |
| 8606 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8607 | } |
| 8608 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8609 | static void |
| 8610 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8611 | { |
| 8612 | struct nfs4_layoutreturn *lrp = calldata; |
| 8613 | |
| 8614 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8615 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8616 | &lrp->args.seq_args, |
| 8617 | &lrp->res.seq_res, |
| 8618 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8619 | } |
| 8620 | |
| 8621 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8622 | { |
| 8623 | struct nfs4_layoutreturn *lrp = calldata; |
| 8624 | struct nfs_server *server; |
| 8625 | |
| 8626 | dprintk("--> %s\n", __func__); |
| 8627 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8628 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8629 | return; |
| 8630 | |
| 8631 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8632 | switch (task->tk_status) { |
| 8633 | default: |
| 8634 | task->tk_status = 0; |
| 8635 | case 0: |
| 8636 | break; |
| 8637 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8638 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8639 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8640 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8641 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8642 | return; |
| 8643 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8644 | dprintk("<-- %s\n", __func__); |
| 8645 | } |
| 8646 | |
| 8647 | static void nfs4_layoutreturn_release(void *calldata) |
| 8648 | { |
| 8649 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8650 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8651 | |
| 8652 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8653 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8654 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8655 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 4d796d7 | 2016-09-23 11:38:08 -0400 | [diff] [blame] | 8656 | if (lrp->ld_private.ops && lrp->ld_private.ops->free) |
| 8657 | lrp->ld_private.ops->free(&lrp->ld_private); |
Trond Myklebust | 2f065dd | 2016-12-07 12:29:26 -0500 | [diff] [blame] | 8658 | pnfs_put_layout_hdr(lrp->args.layout); |
| 8659 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8660 | kfree(calldata); |
| 8661 | dprintk("<-- %s\n", __func__); |
| 8662 | } |
| 8663 | |
| 8664 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8665 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8666 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8667 | .rpc_release = nfs4_layoutreturn_release, |
| 8668 | }; |
| 8669 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8670 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8671 | { |
| 8672 | struct rpc_task *task; |
| 8673 | struct rpc_message msg = { |
| 8674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8675 | .rpc_argp = &lrp->args, |
| 8676 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8677 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8678 | }; |
| 8679 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8680 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8681 | .rpc_message = &msg, |
| 8682 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8683 | .callback_data = lrp, |
| 8684 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8685 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8686 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8687 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8688 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8689 | &task_setup_data.rpc_client, &msg); |
| 8690 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8691 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8692 | if (!sync) { |
| 8693 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8694 | if (!lrp->inode) { |
| 8695 | nfs4_layoutreturn_release(lrp); |
| 8696 | return -EAGAIN; |
| 8697 | } |
| 8698 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8699 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8700 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8701 | task = rpc_run_task(&task_setup_data); |
| 8702 | if (IS_ERR(task)) |
| 8703 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8704 | if (sync) |
| 8705 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8706 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8707 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8708 | rpc_put_task(task); |
| 8709 | return status; |
| 8710 | } |
| 8711 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8712 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8713 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8714 | struct pnfs_device *pdev, |
| 8715 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8716 | { |
| 8717 | struct nfs4_getdeviceinfo_args args = { |
| 8718 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8719 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8720 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8721 | }; |
| 8722 | struct nfs4_getdeviceinfo_res res = { |
| 8723 | .pdev = pdev, |
| 8724 | }; |
| 8725 | struct rpc_message msg = { |
| 8726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8727 | .rpc_argp = &args, |
| 8728 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8729 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8730 | }; |
| 8731 | int status; |
| 8732 | |
| 8733 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8734 | 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] | 8735 | if (res.notification & ~args.notify_types) |
| 8736 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8737 | if (res.notification != args.notify_types) |
| 8738 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8739 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8740 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8741 | |
| 8742 | return status; |
| 8743 | } |
| 8744 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8745 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8746 | struct pnfs_device *pdev, |
| 8747 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8748 | { |
| 8749 | struct nfs4_exception exception = { }; |
| 8750 | int err; |
| 8751 | |
| 8752 | do { |
| 8753 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8754 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8755 | &exception); |
| 8756 | } while (exception.retry); |
| 8757 | return err; |
| 8758 | } |
| 8759 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8760 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8761 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8762 | { |
| 8763 | struct nfs4_layoutcommit_data *data = calldata; |
| 8764 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8765 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8766 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8767 | nfs41_setup_sequence(session, |
| 8768 | &data->args.seq_args, |
| 8769 | &data->res.seq_res, |
| 8770 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8771 | } |
| 8772 | |
| 8773 | static void |
| 8774 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8775 | { |
| 8776 | struct nfs4_layoutcommit_data *data = calldata; |
| 8777 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8778 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8779 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8780 | return; |
| 8781 | |
| 8782 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8783 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8784 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8785 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8786 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8787 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8788 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8789 | break; |
| 8790 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8791 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8792 | rpc_restart_call_prepare(task); |
| 8793 | return; |
| 8794 | } |
| 8795 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8796 | } |
| 8797 | |
| 8798 | static void nfs4_layoutcommit_release(void *calldata) |
| 8799 | { |
| 8800 | struct nfs4_layoutcommit_data *data = calldata; |
| 8801 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8802 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8803 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8804 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8805 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8806 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8807 | kfree(data); |
| 8808 | } |
| 8809 | |
| 8810 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8811 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8812 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8813 | .rpc_release = nfs4_layoutcommit_release, |
| 8814 | }; |
| 8815 | |
| 8816 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8817 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8818 | { |
| 8819 | struct rpc_message msg = { |
| 8820 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8821 | .rpc_argp = &data->args, |
| 8822 | .rpc_resp = &data->res, |
| 8823 | .rpc_cred = data->cred, |
| 8824 | }; |
| 8825 | struct rpc_task_setup task_setup_data = { |
| 8826 | .task = &data->task, |
| 8827 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8828 | .rpc_message = &msg, |
| 8829 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8830 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8831 | }; |
| 8832 | struct rpc_task *task; |
| 8833 | int status = 0; |
| 8834 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8835 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8836 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8837 | data->args.lastbytewritten, |
| 8838 | data->args.inode->i_ino); |
| 8839 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8840 | if (!sync) { |
| 8841 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8842 | if (data->inode == NULL) { |
| 8843 | nfs4_layoutcommit_release(data); |
| 8844 | return -EAGAIN; |
| 8845 | } |
| 8846 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8847 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8848 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8849 | task = rpc_run_task(&task_setup_data); |
| 8850 | if (IS_ERR(task)) |
| 8851 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8852 | if (sync) |
| 8853 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8854 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8855 | dprintk("%s: status %d\n", __func__, status); |
| 8856 | rpc_put_task(task); |
| 8857 | return status; |
| 8858 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8859 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8860 | /** |
| 8861 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8862 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8863 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8864 | static int |
| 8865 | _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] | 8866 | struct nfs_fsinfo *info, |
| 8867 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8868 | { |
| 8869 | struct nfs41_secinfo_no_name_args args = { |
| 8870 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8871 | }; |
| 8872 | struct nfs4_secinfo_res res = { |
| 8873 | .flavors = flavors, |
| 8874 | }; |
| 8875 | struct rpc_message msg = { |
| 8876 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8877 | .rpc_argp = &args, |
| 8878 | .rpc_resp = &res, |
| 8879 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8880 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8881 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8882 | int status; |
| 8883 | |
| 8884 | if (use_integrity) { |
| 8885 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8886 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8887 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8888 | } |
| 8889 | |
| 8890 | dprintk("--> %s\n", __func__); |
| 8891 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8892 | &res.seq_res, 0); |
| 8893 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8894 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8895 | if (cred) |
| 8896 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8897 | |
| 8898 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8899 | } |
| 8900 | |
| 8901 | static int |
| 8902 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8903 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8904 | { |
| 8905 | struct nfs4_exception exception = { }; |
| 8906 | int err; |
| 8907 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8908 | /* first try using integrity protection */ |
| 8909 | err = -NFS4ERR_WRONGSEC; |
| 8910 | |
| 8911 | /* try to use integrity protection with machine cred */ |
| 8912 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8913 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8914 | flavors, true); |
| 8915 | |
| 8916 | /* |
| 8917 | * if unable to use integrity protection, or SECINFO with |
| 8918 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8919 | * disallowed by spec, but exists in deployed servers) use |
| 8920 | * the current filesystem's rpc_client and the user cred. |
| 8921 | */ |
| 8922 | if (err == -NFS4ERR_WRONGSEC) |
| 8923 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8924 | flavors, false); |
| 8925 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8926 | switch (err) { |
| 8927 | case 0: |
| 8928 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8929 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8930 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8931 | default: |
| 8932 | err = nfs4_handle_exception(server, err, &exception); |
| 8933 | } |
| 8934 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8935 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8936 | return err; |
| 8937 | } |
| 8938 | |
| 8939 | static int |
| 8940 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8941 | struct nfs_fsinfo *info) |
| 8942 | { |
| 8943 | int err; |
| 8944 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8945 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8946 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8947 | struct nfs4_secinfo4 *secinfo; |
| 8948 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8949 | |
| 8950 | page = alloc_page(GFP_KERNEL); |
| 8951 | if (!page) { |
| 8952 | err = -ENOMEM; |
| 8953 | goto out; |
| 8954 | } |
| 8955 | |
| 8956 | flavors = page_address(page); |
| 8957 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8958 | |
| 8959 | /* |
| 8960 | * Fall back on "guess and check" method if |
| 8961 | * the server doesn't support SECINFO_NO_NAME |
| 8962 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8963 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8964 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8965 | goto out_freepage; |
| 8966 | } |
| 8967 | if (err) |
| 8968 | goto out_freepage; |
| 8969 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8970 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8971 | secinfo = &flavors->flavors[i]; |
| 8972 | |
| 8973 | switch (secinfo->flavor) { |
| 8974 | case RPC_AUTH_NULL: |
| 8975 | case RPC_AUTH_UNIX: |
| 8976 | case RPC_AUTH_GSS: |
| 8977 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8978 | &secinfo->flavor_info); |
| 8979 | break; |
| 8980 | default: |
| 8981 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8982 | break; |
| 8983 | } |
| 8984 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8985 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8986 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8987 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8988 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8989 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8990 | info, flavor); |
| 8991 | if (!err) |
| 8992 | break; |
| 8993 | } |
| 8994 | } |
| 8995 | |
| 8996 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8997 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8998 | |
| 8999 | out_freepage: |
| 9000 | put_page(page); |
| 9001 | if (err == -EACCES) |
| 9002 | return -EPERM; |
| 9003 | out: |
| 9004 | return err; |
| 9005 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9006 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9007 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 9008 | nfs4_stateid *stateid, |
| 9009 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9010 | { |
| 9011 | int status; |
| 9012 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9013 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9014 | }; |
| 9015 | struct nfs41_test_stateid_res res; |
| 9016 | struct rpc_message msg = { |
| 9017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 9018 | .rpc_argp = &args, |
| 9019 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9020 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9021 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9022 | struct rpc_clnt *rpc_client = server->client; |
| 9023 | |
| 9024 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9025 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9026 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9027 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9028 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9029 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9030 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9031 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9032 | if (status != NFS_OK) { |
| 9033 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9034 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9035 | } |
| 9036 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9037 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9038 | } |
| 9039 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9040 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9041 | int err, struct nfs4_exception *exception) |
| 9042 | { |
| 9043 | exception->retry = 0; |
| 9044 | switch(err) { |
| 9045 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9046 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9047 | nfs4_handle_exception(server, err, exception); |
| 9048 | break; |
| 9049 | case -NFS4ERR_BADSESSION: |
| 9050 | case -NFS4ERR_BADSLOT: |
| 9051 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9052 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9053 | case -NFS4ERR_DEADSESSION: |
| 9054 | nfs4_do_handle_exception(server, err, exception); |
| 9055 | } |
| 9056 | } |
| 9057 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9058 | /** |
| 9059 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9060 | * |
| 9061 | * @server: server / transport on which to perform the operation |
| 9062 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9063 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9064 | * |
| 9065 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9066 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9067 | * failed or the state ID is not currently valid. |
| 9068 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9069 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9070 | nfs4_stateid *stateid, |
| 9071 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9072 | { |
| 9073 | struct nfs4_exception exception = { }; |
| 9074 | int err; |
| 9075 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9076 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9077 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9078 | } while (exception.retry); |
| 9079 | return err; |
| 9080 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9081 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9082 | struct nfs_free_stateid_data { |
| 9083 | struct nfs_server *server; |
| 9084 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9085 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9086 | }; |
| 9087 | |
| 9088 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9089 | { |
| 9090 | struct nfs_free_stateid_data *data = calldata; |
| 9091 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 9092 | &data->args.seq_args, |
| 9093 | &data->res.seq_res, |
| 9094 | task); |
| 9095 | } |
| 9096 | |
| 9097 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9098 | { |
| 9099 | struct nfs_free_stateid_data *data = calldata; |
| 9100 | |
| 9101 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9102 | |
| 9103 | switch (task->tk_status) { |
| 9104 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9105 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9106 | rpc_restart_call_prepare(task); |
| 9107 | } |
| 9108 | } |
| 9109 | |
| 9110 | static void nfs41_free_stateid_release(void *calldata) |
| 9111 | { |
| 9112 | kfree(calldata); |
| 9113 | } |
| 9114 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9115 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9116 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9117 | .rpc_call_done = nfs41_free_stateid_done, |
| 9118 | .rpc_release = nfs41_free_stateid_release, |
| 9119 | }; |
| 9120 | |
| 9121 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9122 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9123 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9124 | bool privileged) |
| 9125 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9126 | struct rpc_message msg = { |
| 9127 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9128 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9129 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9130 | struct rpc_task_setup task_setup = { |
| 9131 | .rpc_client = server->client, |
| 9132 | .rpc_message = &msg, |
| 9133 | .callback_ops = &nfs41_free_stateid_ops, |
| 9134 | .flags = RPC_TASK_ASYNC, |
| 9135 | }; |
| 9136 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9137 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9138 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9139 | &task_setup.rpc_client, &msg); |
| 9140 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9141 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9142 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9143 | if (!data) |
| 9144 | return ERR_PTR(-ENOMEM); |
| 9145 | data->server = server; |
| 9146 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9147 | |
| 9148 | task_setup.callback_data = data; |
| 9149 | |
| 9150 | msg.rpc_argp = &data->args; |
| 9151 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9152 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9153 | if (privileged) |
| 9154 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9155 | |
| 9156 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9157 | } |
| 9158 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9159 | /** |
| 9160 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9161 | * |
| 9162 | * @server: server / transport on which to perform the operation |
| 9163 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9164 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9165 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9166 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9167 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9168 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9169 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9170 | const nfs4_stateid *stateid, |
| 9171 | struct rpc_cred *cred, |
| 9172 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9173 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9174 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9175 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9176 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9177 | if (IS_ERR(task)) |
| 9178 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9179 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9180 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9181 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9182 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9183 | static void |
| 9184 | 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] | 9185 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9186 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9187 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9188 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9189 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9190 | } |
| 9191 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9192 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9193 | const nfs4_stateid *s2) |
| 9194 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9195 | if (s1->type != s2->type) |
| 9196 | return false; |
| 9197 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9198 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9199 | return false; |
| 9200 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9201 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9202 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9203 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9204 | return true; |
| 9205 | |
| 9206 | return false; |
| 9207 | } |
| 9208 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9209 | #endif /* CONFIG_NFS_V4_1 */ |
| 9210 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9211 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9212 | const nfs4_stateid *s2) |
| 9213 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9214 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9215 | } |
| 9216 | |
| 9217 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9218 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9219 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9220 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9221 | .recover_open = nfs4_open_reclaim, |
| 9222 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9223 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9224 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9225 | }; |
| 9226 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9227 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9228 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9229 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9230 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9231 | .recover_open = nfs4_open_reclaim, |
| 9232 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9233 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9234 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9235 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9236 | }; |
| 9237 | #endif /* CONFIG_NFS_V4_1 */ |
| 9238 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9239 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9240 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9241 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9242 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9243 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9244 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9245 | }; |
| 9246 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9247 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9248 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9249 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9250 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9251 | .recover_open = nfs41_open_expired, |
| 9252 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9253 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9254 | }; |
| 9255 | #endif /* CONFIG_NFS_V4_1 */ |
| 9256 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9257 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9258 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9259 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9260 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9261 | }; |
| 9262 | |
| 9263 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9264 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9265 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9266 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9267 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9268 | }; |
| 9269 | #endif |
| 9270 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9271 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9272 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9273 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9274 | }; |
| 9275 | |
| 9276 | #if defined(CONFIG_NFS_V4_1) |
| 9277 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9278 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9279 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9280 | }; |
| 9281 | #endif /* CONFIG_NFS_V4_1 */ |
| 9282 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9283 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9284 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9285 | .init_caps = NFS_CAP_READDIRPLUS |
| 9286 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9287 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9288 | .init_client = nfs40_init_client, |
| 9289 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9290 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9291 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9292 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9293 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9294 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9295 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9296 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9297 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9298 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9299 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9300 | }; |
| 9301 | |
| 9302 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9303 | static struct nfs_seqid * |
| 9304 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9305 | { |
| 9306 | return NULL; |
| 9307 | } |
| 9308 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9309 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9310 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9311 | .init_caps = NFS_CAP_READDIRPLUS |
| 9312 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9313 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9314 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9315 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9316 | .init_client = nfs41_init_client, |
| 9317 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9318 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9319 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9320 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9321 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9322 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9323 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9324 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9325 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9326 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9327 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9328 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9329 | }; |
| 9330 | #endif |
| 9331 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9332 | #if defined(CONFIG_NFS_V4_2) |
| 9333 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9334 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9335 | .init_caps = NFS_CAP_READDIRPLUS |
| 9336 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9337 | | NFS_CAP_POSIX_LOCK |
| 9338 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9339 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9340 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9341 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9342 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9343 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9344 | | NFS_CAP_LAYOUTSTATS |
| 9345 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9346 | .init_client = nfs41_init_client, |
| 9347 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9348 | .match_stateid = nfs41_match_stateid, |
| 9349 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9350 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9351 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9352 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9353 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9354 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9355 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9356 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9357 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9358 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9359 | }; |
| 9360 | #endif |
| 9361 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9362 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9363 | [0] = &nfs_v4_0_minor_ops, |
| 9364 | #if defined(CONFIG_NFS_V4_1) |
| 9365 | [1] = &nfs_v4_1_minor_ops, |
| 9366 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9367 | #if defined(CONFIG_NFS_V4_2) |
| 9368 | [2] = &nfs_v4_2_minor_ops, |
| 9369 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9370 | }; |
| 9371 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9372 | 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] | 9373 | { |
| 9374 | ssize_t error, error2; |
| 9375 | |
| 9376 | error = generic_listxattr(dentry, list, size); |
| 9377 | if (error < 0) |
| 9378 | return error; |
| 9379 | if (list) { |
| 9380 | list += error; |
| 9381 | size -= error; |
| 9382 | } |
| 9383 | |
| 9384 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9385 | if (error2 < 0) |
| 9386 | return error2; |
| 9387 | return error + error2; |
| 9388 | } |
| 9389 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9390 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9391 | .create = nfs_create, |
| 9392 | .lookup = nfs_lookup, |
| 9393 | .atomic_open = nfs_atomic_open, |
| 9394 | .link = nfs_link, |
| 9395 | .unlink = nfs_unlink, |
| 9396 | .symlink = nfs_symlink, |
| 9397 | .mkdir = nfs_mkdir, |
| 9398 | .rmdir = nfs_rmdir, |
| 9399 | .mknod = nfs_mknod, |
| 9400 | .rename = nfs_rename, |
| 9401 | .permission = nfs_permission, |
| 9402 | .getattr = nfs_getattr, |
| 9403 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9404 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9405 | }; |
| 9406 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9407 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9408 | .permission = nfs_permission, |
| 9409 | .getattr = nfs_getattr, |
| 9410 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9411 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9412 | }; |
| 9413 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9414 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9415 | .version = 4, /* protocol version */ |
| 9416 | .dentry_ops = &nfs4_dentry_operations, |
| 9417 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9418 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9419 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9420 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9421 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9422 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9423 | .getattr = nfs4_proc_getattr, |
| 9424 | .setattr = nfs4_proc_setattr, |
| 9425 | .lookup = nfs4_proc_lookup, |
| 9426 | .access = nfs4_proc_access, |
| 9427 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9428 | .create = nfs4_proc_create, |
| 9429 | .remove = nfs4_proc_remove, |
| 9430 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9431 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9432 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9433 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9434 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9435 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9436 | .link = nfs4_proc_link, |
| 9437 | .symlink = nfs4_proc_symlink, |
| 9438 | .mkdir = nfs4_proc_mkdir, |
| 9439 | .rmdir = nfs4_proc_remove, |
| 9440 | .readdir = nfs4_proc_readdir, |
| 9441 | .mknod = nfs4_proc_mknod, |
| 9442 | .statfs = nfs4_proc_statfs, |
| 9443 | .fsinfo = nfs4_proc_fsinfo, |
| 9444 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9445 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9446 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9447 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9448 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9449 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9450 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9451 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9452 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9453 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9454 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9455 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9456 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9457 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9458 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9459 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9460 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9461 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9462 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9463 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9464 | .create_server = nfs4_create_server, |
| 9465 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9466 | }; |
| 9467 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9468 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9469 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9470 | .list = nfs4_xattr_list_nfs4_acl, |
| 9471 | .get = nfs4_xattr_get_nfs4_acl, |
| 9472 | .set = nfs4_xattr_set_nfs4_acl, |
| 9473 | }; |
| 9474 | |
| 9475 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9476 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9477 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9478 | &nfs4_xattr_nfs4_label_handler, |
| 9479 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9480 | NULL |
| 9481 | }; |
| 9482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9483 | /* |
| 9484 | * Local variables: |
| 9485 | * c-basic-offset: 8 |
| 9486 | * End: |
| 9487 | */ |