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 | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 819 | default: |
| 820 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 821 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 822 | } |
| 823 | out: |
| 824 | /* The session may be reset by one of the error handlers. */ |
| 825 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 826 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 827 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 828 | retry_nowait: |
| 829 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 830 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 831 | task->tk_status = 0; |
| 832 | ret = 0; |
| 833 | } |
| 834 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 835 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 836 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 837 | goto out; |
| 838 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 839 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 840 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 841 | |
| 842 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 843 | { |
| 844 | if (!nfs41_sequence_process(task, res)) |
| 845 | return 0; |
| 846 | if (res->sr_slot != NULL) |
| 847 | nfs41_sequence_free_slot(res); |
| 848 | return 1; |
| 849 | |
| 850 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 851 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 852 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 853 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 854 | { |
| 855 | if (res->sr_slot == NULL) |
| 856 | return 1; |
| 857 | if (res->sr_slot->table->session != NULL) |
| 858 | return nfs41_sequence_process(task, res); |
| 859 | return nfs40_sequence_done(task, res); |
| 860 | } |
| 861 | |
| 862 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 863 | { |
| 864 | if (res->sr_slot != NULL) { |
| 865 | if (res->sr_slot->table->session != NULL) |
| 866 | nfs41_sequence_free_slot(res); |
| 867 | else |
| 868 | nfs40_sequence_free_slot(res); |
| 869 | } |
| 870 | } |
| 871 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 872 | 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] | 873 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 874 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 875 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 876 | if (!res->sr_slot->table->session) |
| 877 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 878 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 879 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 880 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 881 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 882 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 883 | struct nfs4_sequence_args *args, |
| 884 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 885 | struct rpc_task *task) |
| 886 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 887 | struct nfs4_slot *slot; |
| 888 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | |
| 890 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 891 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 892 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 893 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 894 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 895 | tbl = &session->fc_slot_table; |
| 896 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 897 | task->tk_timeout = 0; |
| 898 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 899 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 900 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 901 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 902 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 903 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 904 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 907 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 908 | if (IS_ERR(slot)) { |
| 909 | /* If out of memory, try again in 1/4 second */ |
| 910 | if (slot == ERR_PTR(-ENOMEM)) |
| 911 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 912 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 913 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 914 | } |
| 915 | spin_unlock(&tbl->slot_tbl_lock); |
| 916 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 917 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 918 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 919 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 920 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 921 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 922 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 923 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 924 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 925 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 926 | /* |
| 927 | * sr_status is only set in decode_sequence, and so will remain |
| 928 | * set to 1 if an rpc level failure occurs. |
| 929 | */ |
| 930 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 931 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 932 | out_success: |
| 933 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 934 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 935 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 936 | /* Privileged tasks are queued with top priority */ |
| 937 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 938 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 939 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 940 | else |
| 941 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 942 | spin_unlock(&tbl->slot_tbl_lock); |
| 943 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 944 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 945 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 946 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 947 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 948 | struct nfs4_sequence_args *args, |
| 949 | struct nfs4_sequence_res *res, |
| 950 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 951 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 952 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 953 | int ret = 0; |
| 954 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 955 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 956 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 957 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 958 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 959 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 960 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 961 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 962 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 963 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 964 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 965 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 966 | return ret; |
| 967 | } |
| 968 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 969 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 970 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 971 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 972 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 973 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 974 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 975 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 976 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 977 | } |
| 978 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 979 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 980 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 981 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 982 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 983 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 986 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 987 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 988 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 989 | }; |
| 990 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 991 | #else /* !CONFIG_NFS_V4_1 */ |
| 992 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 993 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 994 | struct nfs4_sequence_args *args, |
| 995 | struct nfs4_sequence_res *res, |
| 996 | struct rpc_task *task) |
| 997 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 998 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 999 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 1000 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 1001 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1002 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 1003 | { |
| 1004 | return nfs40_sequence_done(task, res); |
| 1005 | } |
| 1006 | |
| 1007 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 1008 | { |
| 1009 | if (res->sr_slot != NULL) |
| 1010 | nfs40_sequence_free_slot(res); |
| 1011 | } |
| 1012 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1013 | int nfs4_sequence_done(struct rpc_task *task, |
| 1014 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1015 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1016 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1017 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1018 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1019 | |
| 1020 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1021 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1022 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1023 | { |
| 1024 | struct nfs4_call_sync_data *data = calldata; |
| 1025 | nfs4_setup_sequence(data->seq_server, |
| 1026 | data->seq_args, data->seq_res, task); |
| 1027 | } |
| 1028 | |
| 1029 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1030 | { |
| 1031 | struct nfs4_call_sync_data *data = calldata; |
| 1032 | nfs4_sequence_done(task, data->seq_res); |
| 1033 | } |
| 1034 | |
| 1035 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1036 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1037 | .rpc_call_done = nfs40_call_sync_done, |
| 1038 | }; |
| 1039 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1040 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1041 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1042 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1043 | struct nfs4_sequence_args *args, |
| 1044 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1045 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1046 | int ret; |
| 1047 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1048 | struct nfs_client *clp = server->nfs_client; |
| 1049 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1050 | .seq_server = server, |
| 1051 | .seq_args = args, |
| 1052 | .seq_res = res, |
| 1053 | }; |
| 1054 | struct rpc_task_setup task_setup = { |
| 1055 | .rpc_client = clnt, |
| 1056 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1057 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1058 | .callback_data = &data |
| 1059 | }; |
| 1060 | |
| 1061 | task = rpc_run_task(&task_setup); |
| 1062 | if (IS_ERR(task)) |
| 1063 | ret = PTR_ERR(task); |
| 1064 | else { |
| 1065 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1066 | rpc_put_task(task); |
| 1067 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1068 | return ret; |
| 1069 | } |
| 1070 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1071 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1072 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1073 | struct rpc_message *msg, |
| 1074 | struct nfs4_sequence_args *args, |
| 1075 | struct nfs4_sequence_res *res, |
| 1076 | int cache_reply) |
| 1077 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1078 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1079 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1080 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1083 | { |
| 1084 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1085 | |
| 1086 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1087 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1088 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1090 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1091 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1092 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | spin_unlock(&dir->i_lock); |
| 1094 | } |
| 1095 | |
| 1096 | struct nfs4_opendata { |
| 1097 | struct kref kref; |
| 1098 | struct nfs_openargs o_arg; |
| 1099 | struct nfs_openres o_res; |
| 1100 | struct nfs_open_confirmargs c_arg; |
| 1101 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1102 | struct nfs4_string owner_name; |
| 1103 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1104 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1106 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1108 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | struct nfs4_state_owner *owner; |
| 1110 | struct nfs4_state *state; |
| 1111 | struct iattr attrs; |
| 1112 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1113 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1114 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1115 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1116 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | int cancelled; |
| 1118 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1119 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1120 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1121 | int err, struct nfs4_exception *exception) |
| 1122 | { |
| 1123 | if (err != -EINVAL) |
| 1124 | return false; |
| 1125 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1126 | return false; |
| 1127 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1128 | exception->retry = 1; |
| 1129 | return true; |
| 1130 | } |
| 1131 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1132 | static u32 |
| 1133 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1134 | fmode_t fmode, int openflags) |
| 1135 | { |
| 1136 | u32 res = 0; |
| 1137 | |
| 1138 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1139 | case FMODE_READ: |
| 1140 | res = NFS4_SHARE_ACCESS_READ; |
| 1141 | break; |
| 1142 | case FMODE_WRITE: |
| 1143 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1144 | break; |
| 1145 | case FMODE_READ|FMODE_WRITE: |
| 1146 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1147 | } |
| 1148 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1149 | goto out; |
| 1150 | /* Want no delegation if we're using O_DIRECT */ |
| 1151 | if (openflags & O_DIRECT) |
| 1152 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1153 | out: |
| 1154 | return res; |
| 1155 | } |
| 1156 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1157 | static enum open_claim_type4 |
| 1158 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1159 | enum open_claim_type4 claim) |
| 1160 | { |
| 1161 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1162 | return claim; |
| 1163 | switch (claim) { |
| 1164 | default: |
| 1165 | return claim; |
| 1166 | case NFS4_OPEN_CLAIM_FH: |
| 1167 | return NFS4_OPEN_CLAIM_NULL; |
| 1168 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1169 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1170 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1171 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1172 | } |
| 1173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1176 | { |
| 1177 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1178 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1179 | p->o_res.seqid = p->o_arg.seqid; |
| 1180 | p->c_res.seqid = p->c_arg.seqid; |
| 1181 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1182 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1184 | 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] | 1185 | } |
| 1186 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1187 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1188 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1189 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1190 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1191 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1192 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1193 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1194 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1195 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1196 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1197 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1198 | struct nfs4_opendata *p; |
| 1199 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1200 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1201 | if (p == NULL) |
| 1202 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1203 | |
| 1204 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1205 | if (IS_ERR(p->f_label)) |
| 1206 | goto err_free_p; |
| 1207 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1208 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1209 | if (IS_ERR(p->a_label)) |
| 1210 | goto err_free_f; |
| 1211 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1212 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1213 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1214 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1215 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1216 | nfs_sb_active(dentry->d_sb); |
| 1217 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1218 | p->dir = parent; |
| 1219 | p->owner = sp; |
| 1220 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1221 | p->o_arg.open_flags = flags; |
| 1222 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1223 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1224 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1225 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1226 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1227 | * will return permission denied for all bits until close */ |
| 1228 | if (!(flags & O_EXCL)) { |
| 1229 | /* ask server to check for all possible rights as results |
| 1230 | * are cached */ |
Trond Myklebust | 536585c | 2016-11-10 15:40:34 -0500 | [diff] [blame] | 1231 | switch (p->o_arg.claim) { |
| 1232 | default: |
| 1233 | break; |
| 1234 | case NFS4_OPEN_CLAIM_NULL: |
| 1235 | case NFS4_OPEN_CLAIM_FH: |
| 1236 | p->o_arg.access = NFS4_ACCESS_READ | |
| 1237 | NFS4_ACCESS_MODIFY | |
| 1238 | NFS4_ACCESS_EXTEND | |
| 1239 | NFS4_ACCESS_EXECUTE; |
| 1240 | } |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1241 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1242 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1243 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1244 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1245 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1246 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1247 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1248 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1249 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1250 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1251 | case NFS4_OPEN_CLAIM_NULL: |
| 1252 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1253 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1254 | p->o_arg.fh = NFS_FH(dir); |
| 1255 | break; |
| 1256 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1257 | case NFS4_OPEN_CLAIM_FH: |
| 1258 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1259 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1260 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1261 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1262 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1263 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1264 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1265 | p->o_arg.u.attrs = &p->attrs; |
| 1266 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1267 | |
| 1268 | verf[0] = jiffies; |
| 1269 | verf[1] = current->pid; |
| 1270 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1271 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1272 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1273 | p->c_arg.fh = &p->o_res.fh; |
| 1274 | p->c_arg.stateid = &p->o_res.stateid; |
| 1275 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1276 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1278 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1279 | |
| 1280 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1281 | nfs4_label_free(p->a_label); |
| 1282 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1283 | nfs4_label_free(p->f_label); |
| 1284 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1285 | kfree(p); |
| 1286 | err: |
| 1287 | dput(parent); |
| 1288 | return NULL; |
| 1289 | } |
| 1290 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1291 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1292 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1293 | struct nfs4_opendata *p = container_of(kref, |
| 1294 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1295 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1296 | |
| 1297 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1298 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1299 | if (p->state != NULL) |
| 1300 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1301 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1302 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1303 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1304 | nfs4_label_free(p->f_label); |
| 1305 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1306 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1307 | dput(p->dentry); |
| 1308 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1309 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1310 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1311 | kfree(p); |
| 1312 | } |
| 1313 | |
| 1314 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1315 | { |
| 1316 | if (p != NULL) |
| 1317 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1320 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1321 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1322 | int ret; |
| 1323 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1324 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1325 | return ret; |
| 1326 | } |
| 1327 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1328 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1329 | fmode_t fmode) |
| 1330 | { |
| 1331 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1332 | case FMODE_READ|FMODE_WRITE: |
| 1333 | return state->n_rdwr != 0; |
| 1334 | case FMODE_WRITE: |
| 1335 | return state->n_wronly != 0; |
| 1336 | case FMODE_READ: |
| 1337 | return state->n_rdonly != 0; |
| 1338 | } |
| 1339 | WARN_ON_ONCE(1); |
| 1340 | return false; |
| 1341 | } |
| 1342 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1343 | 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] | 1344 | { |
| 1345 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1347 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | goto out; |
| 1349 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1350 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1351 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1352 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1353 | break; |
| 1354 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1355 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1356 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1357 | break; |
| 1358 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1359 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1360 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1361 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1362 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1363 | return ret; |
| 1364 | } |
| 1365 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1366 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1367 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1368 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1369 | if (delegation == NULL) |
| 1370 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1372 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1373 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1374 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1375 | switch (claim) { |
| 1376 | case NFS4_OPEN_CLAIM_NULL: |
| 1377 | case NFS4_OPEN_CLAIM_FH: |
| 1378 | break; |
| 1379 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1380 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1381 | break; |
| 1382 | default: |
| 1383 | return 0; |
| 1384 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1385 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
| 1388 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1389 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1390 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1391 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1392 | case FMODE_WRITE: |
| 1393 | state->n_wronly++; |
| 1394 | break; |
| 1395 | case FMODE_READ: |
| 1396 | state->n_rdonly++; |
| 1397 | break; |
| 1398 | case FMODE_READ|FMODE_WRITE: |
| 1399 | state->n_rdwr++; |
| 1400 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1401 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 1404 | #ifdef CONFIG_NFS_V4_1 |
| 1405 | static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) |
| 1406 | { |
| 1407 | if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) |
| 1408 | return true; |
| 1409 | if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) |
| 1410 | return true; |
| 1411 | if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) |
| 1412 | return true; |
| 1413 | return false; |
| 1414 | } |
| 1415 | #endif /* CONFIG_NFS_V4_1 */ |
| 1416 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1417 | 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] | 1418 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1419 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1420 | bool need_recover = false; |
| 1421 | |
| 1422 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1423 | need_recover = true; |
| 1424 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1425 | need_recover = true; |
| 1426 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1427 | need_recover = true; |
| 1428 | if (need_recover) |
| 1429 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1430 | } |
| 1431 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1432 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1433 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1434 | { |
| 1435 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1436 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1437 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1438 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1439 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1440 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1441 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1442 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1443 | return true; |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1447 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1448 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1449 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1450 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1451 | if (state->n_wronly) |
| 1452 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1453 | if (state->n_rdonly) |
| 1454 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1455 | if (state->n_rdwr) |
| 1456 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1457 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1458 | } |
| 1459 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1460 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1461 | nfs4_stateid *stateid, fmode_t fmode) |
| 1462 | { |
| 1463 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1464 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1465 | case FMODE_WRITE: |
| 1466 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1467 | break; |
| 1468 | case FMODE_READ: |
| 1469 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1470 | break; |
| 1471 | case 0: |
| 1472 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1473 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1474 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1475 | } |
| 1476 | if (stateid == NULL) |
| 1477 | return; |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1478 | /* Handle OPEN+OPEN_DOWNGRADE races */ |
| 1479 | if (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1480 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1481 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1482 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1483 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1484 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1485 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1486 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1489 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1490 | nfs4_stateid *arg_stateid, |
| 1491 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1492 | { |
| 1493 | write_seqlock(&state->seqlock); |
Trond Myklebust | 3e7dfb1 | 2016-11-14 11:19:55 -0500 | [diff] [blame] | 1494 | /* Ignore, if the CLOSE argment doesn't match the current stateid */ |
| 1495 | if (nfs4_state_match_open_stateid_other(state, arg_stateid)) |
| 1496 | nfs_clear_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1497 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1498 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1499 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1500 | } |
| 1501 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1502 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1503 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1504 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1505 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1506 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1507 | case FMODE_READ: |
| 1508 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1509 | break; |
| 1510 | case FMODE_WRITE: |
| 1511 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1512 | break; |
| 1513 | case FMODE_READ|FMODE_WRITE: |
| 1514 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1515 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1516 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1517 | return; |
| 1518 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1519 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1520 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1521 | } |
| 1522 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1523 | static void __update_open_stateid(struct nfs4_state *state, |
| 1524 | const nfs4_stateid *open_stateid, |
| 1525 | const nfs4_stateid *deleg_stateid, |
| 1526 | fmode_t fmode, |
| 1527 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1529 | /* |
| 1530 | * Protect the call to nfs4_state_set_mode_locked and |
| 1531 | * serialise the stateid update |
| 1532 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1533 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1534 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1535 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1536 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1537 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1538 | } |
| 1539 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1540 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1541 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1542 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1543 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1546 | static int update_open_stateid(struct nfs4_state *state, |
| 1547 | const nfs4_stateid *open_stateid, |
| 1548 | const nfs4_stateid *delegation, |
| 1549 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1550 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1551 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1552 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1553 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1554 | struct nfs_delegation *deleg_cur; |
Arnd Bergmann | 83aa3e0 | 2016-10-18 17:21:30 +0200 | [diff] [blame] | 1555 | nfs4_stateid freeme = { }; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1556 | int ret = 0; |
| 1557 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1558 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1559 | |
| 1560 | rcu_read_lock(); |
| 1561 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1562 | if (deleg_cur == NULL) |
| 1563 | goto no_delegation; |
| 1564 | |
| 1565 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1566 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1567 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1568 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1569 | goto no_delegation_unlock; |
| 1570 | |
| 1571 | if (delegation == NULL) |
| 1572 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1573 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | goto no_delegation_unlock; |
| 1575 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1576 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1577 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1578 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1579 | ret = 1; |
| 1580 | no_delegation_unlock: |
| 1581 | spin_unlock(&deleg_cur->lock); |
| 1582 | no_delegation: |
| 1583 | rcu_read_unlock(); |
| 1584 | |
| 1585 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1586 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1587 | ret = 1; |
| 1588 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1589 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame] | 1590 | nfs4_schedule_state_manager(clp); |
| 1591 | if (freeme.type != 0) |
| 1592 | nfs4_test_and_free_stateid(server, &freeme, |
| 1593 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1594 | |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1598 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1599 | const nfs4_stateid *stateid) |
| 1600 | { |
| 1601 | struct nfs4_state *state = lsp->ls_state; |
| 1602 | bool ret = false; |
| 1603 | |
| 1604 | spin_lock(&state->state_lock); |
| 1605 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1606 | goto out_noupdate; |
| 1607 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1608 | goto out_noupdate; |
| 1609 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1610 | ret = true; |
| 1611 | out_noupdate: |
| 1612 | spin_unlock(&state->state_lock); |
| 1613 | return ret; |
| 1614 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1615 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1616 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1617 | { |
| 1618 | struct nfs_delegation *delegation; |
| 1619 | |
| 1620 | rcu_read_lock(); |
| 1621 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1622 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1623 | rcu_read_unlock(); |
| 1624 | return; |
| 1625 | } |
| 1626 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1627 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1630 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1631 | { |
| 1632 | struct nfs4_state *state = opendata->state; |
| 1633 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1634 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1635 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1636 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1637 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1638 | nfs4_stateid stateid; |
| 1639 | int ret = -EAGAIN; |
| 1640 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1641 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1642 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1643 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1644 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1645 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1646 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1647 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1648 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1649 | rcu_read_lock(); |
| 1650 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1651 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1652 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1653 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1654 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1655 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1656 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1657 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1658 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1659 | if (!opendata->is_recover) { |
| 1660 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1661 | if (ret != 0) |
| 1662 | goto out; |
| 1663 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1664 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1665 | |
| 1666 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1667 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1668 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1669 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1670 | out: |
| 1671 | return ERR_PTR(ret); |
| 1672 | out_return_state: |
| 1673 | atomic_inc(&state->count); |
| 1674 | return state; |
| 1675 | } |
| 1676 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1677 | static void |
| 1678 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1679 | { |
| 1680 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1681 | struct nfs_delegation *delegation; |
| 1682 | int delegation_flags = 0; |
| 1683 | |
| 1684 | rcu_read_lock(); |
| 1685 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1686 | if (delegation) |
| 1687 | delegation_flags = delegation->flags; |
| 1688 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1689 | switch (data->o_arg.claim) { |
| 1690 | default: |
| 1691 | break; |
| 1692 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1693 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1694 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1695 | "returning a delegation for " |
| 1696 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1697 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1698 | return; |
| 1699 | } |
| 1700 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1701 | nfs_inode_set_delegation(state->inode, |
| 1702 | data->owner->so_cred, |
| 1703 | &data->o_res); |
| 1704 | else |
| 1705 | nfs_inode_reclaim_delegation(state->inode, |
| 1706 | data->owner->so_cred, |
| 1707 | &data->o_res); |
| 1708 | } |
| 1709 | |
| 1710 | /* |
| 1711 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1712 | * and update the nfs4_state. |
| 1713 | */ |
| 1714 | static struct nfs4_state * |
| 1715 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1716 | { |
| 1717 | struct inode *inode = data->state->inode; |
| 1718 | struct nfs4_state *state = data->state; |
| 1719 | int ret; |
| 1720 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1721 | if (!data->rpc_done) { |
| 1722 | if (data->rpc_status) { |
| 1723 | ret = data->rpc_status; |
| 1724 | goto err; |
| 1725 | } |
| 1726 | /* cached opens have already been processed */ |
| 1727 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1730 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1731 | if (ret) |
| 1732 | goto err; |
| 1733 | |
| 1734 | if (data->o_res.delegation_type != 0) |
| 1735 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1736 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1737 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1738 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1739 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1740 | |
| 1741 | return state; |
| 1742 | err: |
| 1743 | return ERR_PTR(ret); |
| 1744 | |
| 1745 | } |
| 1746 | |
| 1747 | static struct nfs4_state * |
| 1748 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1749 | { |
| 1750 | struct inode *inode; |
| 1751 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1752 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1753 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1754 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1755 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1756 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1757 | goto out; |
| 1758 | } |
| 1759 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1760 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1761 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1762 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1763 | 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] | 1764 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1765 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1766 | goto err; |
| 1767 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1768 | state = nfs4_get_open_state(inode, data->owner); |
| 1769 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1770 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1771 | if (data->o_res.delegation_type != 0) |
| 1772 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1773 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1774 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1775 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1776 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1777 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1778 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1779 | err_put_inode: |
| 1780 | iput(inode); |
| 1781 | err: |
| 1782 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1783 | } |
| 1784 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1785 | static struct nfs4_state * |
| 1786 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1787 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1788 | struct nfs4_state *ret; |
| 1789 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1790 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1791 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1792 | else |
| 1793 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1794 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1795 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1796 | } |
| 1797 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1798 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1799 | { |
| 1800 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1801 | struct nfs_open_context *ctx; |
| 1802 | |
| 1803 | spin_lock(&state->inode->i_lock); |
| 1804 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1805 | if (ctx->state != state) |
| 1806 | continue; |
| 1807 | get_nfs_open_context(ctx); |
| 1808 | spin_unlock(&state->inode->i_lock); |
| 1809 | return ctx; |
| 1810 | } |
| 1811 | spin_unlock(&state->inode->i_lock); |
| 1812 | return ERR_PTR(-ENOENT); |
| 1813 | } |
| 1814 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1815 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1816 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1817 | { |
| 1818 | struct nfs4_opendata *opendata; |
| 1819 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1820 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1821 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1822 | if (opendata == NULL) |
| 1823 | return ERR_PTR(-ENOMEM); |
| 1824 | opendata->state = state; |
| 1825 | atomic_inc(&state->count); |
| 1826 | return opendata; |
| 1827 | } |
| 1828 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1829 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1830 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1831 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1832 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1833 | int ret; |
| 1834 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1835 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1836 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1837 | opendata->o_arg.open_flags = 0; |
| 1838 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1839 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1840 | NFS_SB(opendata->dentry->d_sb), |
| 1841 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1842 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1843 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1844 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1845 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1846 | if (ret != 0) |
| 1847 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1848 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1849 | if (IS_ERR(newstate)) |
| 1850 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1851 | if (newstate != opendata->state) |
| 1852 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1853 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1854 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1858 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1859 | int ret; |
| 1860 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1861 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1862 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1863 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1864 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1865 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1866 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1867 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1868 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1869 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1870 | if (ret != 0) |
| 1871 | return ret; |
| 1872 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1873 | if (ret != 0) |
| 1874 | return ret; |
| 1875 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1876 | if (ret != 0) |
| 1877 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1878 | /* |
| 1879 | * We may have performed cached opens for all three recoveries. |
| 1880 | * Check if we need to update the current stateid. |
| 1881 | */ |
| 1882 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1883 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1884 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1885 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1886 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1887 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1888 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1889 | return 0; |
| 1890 | } |
| 1891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | /* |
| 1893 | * OPEN_RECLAIM: |
| 1894 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1896 | 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] | 1897 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1898 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1899 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1900 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | int status; |
| 1902 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1903 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1904 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1905 | if (IS_ERR(opendata)) |
| 1906 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1907 | rcu_read_lock(); |
| 1908 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1909 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1910 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1911 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1912 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1913 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1914 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | return status; |
| 1916 | } |
| 1917 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1918 | 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] | 1919 | { |
| 1920 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1921 | struct nfs4_exception exception = { }; |
| 1922 | int err; |
| 1923 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1924 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1925 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1926 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1927 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1928 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } while (exception.retry); |
| 1932 | return err; |
| 1933 | } |
| 1934 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1935 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1936 | { |
| 1937 | struct nfs_open_context *ctx; |
| 1938 | int ret; |
| 1939 | |
| 1940 | ctx = nfs4_state_find_open_context(state); |
| 1941 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1942 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1943 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1944 | put_nfs_open_context(ctx); |
| 1945 | return ret; |
| 1946 | } |
| 1947 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1948 | 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] | 1949 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1950 | switch (err) { |
| 1951 | default: |
| 1952 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1953 | "%d.\n", __func__, err); |
| 1954 | case 0: |
| 1955 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1956 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1957 | case -ESTALE: |
| 1958 | break; |
| 1959 | case -NFS4ERR_BADSESSION: |
| 1960 | case -NFS4ERR_BADSLOT: |
| 1961 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1962 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1963 | case -NFS4ERR_DEADSESSION: |
| 1964 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1965 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1966 | return -EAGAIN; |
| 1967 | case -NFS4ERR_STALE_CLIENTID: |
| 1968 | case -NFS4ERR_STALE_STATEID: |
| 1969 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1970 | /* Don't recall a delegation if it was lost */ |
| 1971 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1972 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1973 | case -NFS4ERR_MOVED: |
| 1974 | nfs4_schedule_migration_recovery(server); |
| 1975 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1976 | case -NFS4ERR_LEASE_MOVED: |
| 1977 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1978 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1979 | case -NFS4ERR_DELEG_REVOKED: |
| 1980 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1981 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1982 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1983 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1984 | nfs_inode_find_state_and_recover(state->inode, |
| 1985 | stateid); |
| 1986 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1987 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1988 | case -NFS4ERR_DELAY: |
| 1989 | case -NFS4ERR_GRACE: |
| 1990 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1991 | ssleep(1); |
| 1992 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1993 | case -ENOMEM: |
| 1994 | case -NFS4ERR_DENIED: |
| 1995 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1996 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | return err; |
| 1999 | } |
| 2000 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2001 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 2002 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 2003 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2004 | { |
| 2005 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2006 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2007 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2008 | |
| 2009 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 2010 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 2011 | if (IS_ERR(opendata)) |
| 2012 | return PTR_ERR(opendata); |
| 2013 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 2014 | write_seqlock(&state->seqlock); |
| 2015 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2016 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 2017 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2018 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 2019 | case FMODE_READ|FMODE_WRITE: |
| 2020 | case FMODE_WRITE: |
| 2021 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 2022 | if (err) |
| 2023 | break; |
| 2024 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 2025 | if (err) |
| 2026 | break; |
| 2027 | case FMODE_READ: |
| 2028 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 2029 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 2030 | nfs4_opendata_put(opendata); |
| 2031 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2032 | } |
| 2033 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2034 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2035 | { |
| 2036 | struct nfs4_opendata *data = calldata; |
| 2037 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2038 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2039 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2040 | } |
| 2041 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2042 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2043 | { |
| 2044 | struct nfs4_opendata *data = calldata; |
| 2045 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2046 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2047 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2048 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2049 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2050 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2051 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2052 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2053 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2054 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | static void nfs4_open_confirm_release(void *calldata) |
| 2058 | { |
| 2059 | struct nfs4_opendata *data = calldata; |
| 2060 | struct nfs4_state *state = NULL; |
| 2061 | |
| 2062 | /* If this request hasn't been cancelled, do nothing */ |
| 2063 | if (data->cancelled == 0) |
| 2064 | goto out_free; |
| 2065 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2066 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2067 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2068 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2069 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2070 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2071 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2072 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2076 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2077 | .rpc_call_done = nfs4_open_confirm_done, |
| 2078 | .rpc_release = nfs4_open_confirm_release, |
| 2079 | }; |
| 2080 | |
| 2081 | /* |
| 2082 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2083 | */ |
| 2084 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2085 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2086 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2087 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2088 | struct rpc_message msg = { |
| 2089 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2090 | .rpc_argp = &data->c_arg, |
| 2091 | .rpc_resp = &data->c_res, |
| 2092 | .rpc_cred = data->owner->so_cred, |
| 2093 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2094 | struct rpc_task_setup task_setup_data = { |
| 2095 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2096 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2097 | .callback_ops = &nfs4_open_confirm_ops, |
| 2098 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2099 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2100 | .flags = RPC_TASK_ASYNC, |
| 2101 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | int status; |
| 2103 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2104 | 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] | 2105 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2106 | data->rpc_done = 0; |
| 2107 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2108 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2109 | if (data->is_recover) |
| 2110 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2111 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2112 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2113 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2114 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2115 | if (status != 0) { |
| 2116 | data->cancelled = 1; |
| 2117 | smp_wmb(); |
| 2118 | } else |
| 2119 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2120 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | return status; |
| 2122 | } |
| 2123 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2124 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2126 | struct nfs4_opendata *data = calldata; |
| 2127 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2128 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2129 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2130 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2131 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2132 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2133 | /* |
| 2134 | * Check if we still need to send an OPEN call, or if we can use |
| 2135 | * a delegation instead. |
| 2136 | */ |
| 2137 | if (data->state != NULL) { |
| 2138 | struct nfs_delegation *delegation; |
| 2139 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2140 | 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] | 2141 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2142 | rcu_read_lock(); |
| 2143 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2144 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2145 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2146 | rcu_read_unlock(); |
| 2147 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2148 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2149 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2150 | switch (claim) { |
| 2151 | default: |
| 2152 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2153 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2154 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2155 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2156 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2157 | case NFS4_OPEN_CLAIM_FH: |
| 2158 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2159 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2160 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2161 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2162 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2163 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2164 | &data->o_res.seq_res, |
| 2165 | task) != 0) |
| 2166 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2167 | |
| 2168 | /* Set the create mode (note dependency on the session type) */ |
| 2169 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2170 | if (data->o_arg.open_flags & O_EXCL) { |
| 2171 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2172 | if (nfs4_has_persistent_session(clp)) |
| 2173 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2174 | else if (clp->cl_mvops->minor_version > 0) |
| 2175 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2176 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2177 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2178 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2179 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2180 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2181 | out_no_action: |
| 2182 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2183 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2184 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2187 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2188 | { |
| 2189 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2192 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2193 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2194 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2195 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2196 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2197 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2198 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2199 | case S_IFREG: |
| 2200 | break; |
| 2201 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2202 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2203 | break; |
| 2204 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2205 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2206 | break; |
| 2207 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2208 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2209 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2210 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2211 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2212 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2213 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2214 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2215 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2216 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2217 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2218 | static void nfs4_open_release(void *calldata) |
| 2219 | { |
| 2220 | struct nfs4_opendata *data = calldata; |
| 2221 | struct nfs4_state *state = NULL; |
| 2222 | |
| 2223 | /* If this request hasn't been cancelled, do nothing */ |
| 2224 | if (data->cancelled == 0) |
| 2225 | goto out_free; |
| 2226 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2227 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2228 | goto out_free; |
| 2229 | /* In case we need an open_confirm, no cleanup! */ |
| 2230 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2231 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2232 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2233 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2234 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2235 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2236 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2240 | .rpc_call_prepare = nfs4_open_prepare, |
| 2241 | .rpc_call_done = nfs4_open_done, |
| 2242 | .rpc_release = nfs4_open_release, |
| 2243 | }; |
| 2244 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2245 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2246 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2247 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2248 | struct nfs_server *server = NFS_SERVER(dir); |
| 2249 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2250 | struct nfs_openres *o_res = &data->o_res; |
| 2251 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2252 | struct rpc_message msg = { |
| 2253 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2254 | .rpc_argp = o_arg, |
| 2255 | .rpc_resp = o_res, |
| 2256 | .rpc_cred = data->owner->so_cred, |
| 2257 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2258 | struct rpc_task_setup task_setup_data = { |
| 2259 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2260 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2261 | .callback_ops = &nfs4_open_ops, |
| 2262 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2263 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2264 | .flags = RPC_TASK_ASYNC, |
| 2265 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2266 | int status; |
| 2267 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2268 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2269 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2270 | data->rpc_done = 0; |
| 2271 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2272 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2273 | data->is_recover = 0; |
| 2274 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2275 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2276 | data->is_recover = 1; |
| 2277 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2278 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2279 | if (IS_ERR(task)) |
| 2280 | return PTR_ERR(task); |
| 2281 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2282 | if (status != 0) { |
| 2283 | data->cancelled = 1; |
| 2284 | smp_wmb(); |
| 2285 | } else |
| 2286 | status = data->rpc_status; |
| 2287 | rpc_put_task(task); |
| 2288 | |
| 2289 | return status; |
| 2290 | } |
| 2291 | |
| 2292 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2293 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2294 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2295 | struct nfs_openres *o_res = &data->o_res; |
| 2296 | int status; |
| 2297 | |
| 2298 | status = nfs4_run_open_task(data, 1); |
| 2299 | if (status != 0 || !data->rpc_done) |
| 2300 | return status; |
| 2301 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2302 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2303 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2304 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2305 | status = _nfs4_proc_open_confirm(data); |
| 2306 | if (status != 0) |
| 2307 | return status; |
| 2308 | } |
| 2309 | |
| 2310 | return status; |
| 2311 | } |
| 2312 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2313 | /* |
| 2314 | * Additional permission checks in order to distinguish between an |
| 2315 | * open for read, and an open for execute. This works around the |
| 2316 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2317 | * the same. |
| 2318 | * Note that in the non-execute case, we want to turn off permission |
| 2319 | * checking if we just created a new file (POSIX open() semantics). |
| 2320 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2321 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2322 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2323 | struct nfs4_state *state, fmode_t fmode, |
| 2324 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2325 | { |
| 2326 | struct nfs_access_entry cache; |
| 2327 | u32 mask; |
| 2328 | |
| 2329 | /* access call failed or for some reason the server doesn't |
| 2330 | * support any access modes -- defer access call until later */ |
| 2331 | if (opendata->o_res.access_supported == 0) |
| 2332 | return 0; |
| 2333 | |
| 2334 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2335 | /* |
| 2336 | * Use openflags to check for exec, because fmode won't |
| 2337 | * always have FMODE_EXEC set when file open for exec. |
| 2338 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2339 | if (openflags & __FMODE_EXEC) { |
| 2340 | /* ONLY check for exec rights */ |
| 2341 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2342 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2343 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2344 | |
| 2345 | cache.cred = cred; |
| 2346 | cache.jiffies = jiffies; |
| 2347 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2348 | nfs_access_add_cache(state->inode, &cache); |
| 2349 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2350 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2351 | return 0; |
| 2352 | |
| 2353 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2354 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2355 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2356 | } |
| 2357 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2358 | /* |
| 2359 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2360 | */ |
| 2361 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2362 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2363 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2364 | struct nfs_server *server = NFS_SERVER(dir); |
| 2365 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2366 | struct nfs_openres *o_res = &data->o_res; |
| 2367 | int status; |
| 2368 | |
| 2369 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2370 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2371 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2372 | if (status != 0) { |
| 2373 | if (status == -NFS4ERR_BADNAME && |
| 2374 | !(o_arg->open_flags & O_CREAT)) |
| 2375 | return -ENOENT; |
| 2376 | return status; |
| 2377 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2378 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2379 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2380 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2381 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2382 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2383 | if (o_arg->open_flags & O_EXCL) |
| 2384 | data->file_created = 1; |
| 2385 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2386 | data->file_created = 1; |
| 2387 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2388 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2389 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2391 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2393 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | } |
| 2395 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2396 | 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] | 2397 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2400 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2401 | { |
| 2402 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2403 | } |
| 2404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | /* |
| 2406 | * OPEN_EXPIRED: |
| 2407 | * reclaim state on the server after a network partition. |
| 2408 | * Assumes caller holds the appropriate lock |
| 2409 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2410 | 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] | 2411 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2412 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2413 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2415 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2416 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2417 | if (IS_ERR(opendata)) |
| 2418 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2419 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2420 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2421 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2422 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2423 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2426 | 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] | 2427 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2428 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2429 | struct nfs4_exception exception = { }; |
| 2430 | int err; |
| 2431 | |
| 2432 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2433 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2434 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2435 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2436 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2437 | switch (err) { |
| 2438 | default: |
| 2439 | goto out; |
| 2440 | case -NFS4ERR_GRACE: |
| 2441 | case -NFS4ERR_DELAY: |
| 2442 | nfs4_handle_exception(server, err, &exception); |
| 2443 | err = 0; |
| 2444 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2445 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2446 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2447 | return err; |
| 2448 | } |
| 2449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2451 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2453 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2455 | ctx = nfs4_state_find_open_context(state); |
| 2456 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2457 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2458 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2459 | put_nfs_open_context(ctx); |
| 2460 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2463 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2464 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2465 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2466 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2467 | write_seqlock(&state->seqlock); |
| 2468 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2469 | write_sequnlock(&state->seqlock); |
| 2470 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2471 | } |
| 2472 | |
| 2473 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2474 | { |
| 2475 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2476 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2480 | { |
| 2481 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2482 | nfs40_clear_delegation_stateid(state); |
| 2483 | return nfs4_open_expired(sp, state); |
| 2484 | } |
| 2485 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2486 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2487 | nfs4_stateid *stateid, |
| 2488 | struct rpc_cred *cred) |
| 2489 | { |
| 2490 | return -NFS4ERR_BAD_STATEID; |
| 2491 | } |
| 2492 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2493 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2494 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2495 | nfs4_stateid *stateid, |
| 2496 | struct rpc_cred *cred) |
| 2497 | { |
| 2498 | int status; |
| 2499 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2500 | switch (stateid->type) { |
| 2501 | default: |
| 2502 | break; |
| 2503 | case NFS4_INVALID_STATEID_TYPE: |
| 2504 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2505 | return -NFS4ERR_BAD_STATEID; |
| 2506 | case NFS4_REVOKED_STATEID_TYPE: |
| 2507 | goto out_free; |
| 2508 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2509 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2510 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2511 | switch (status) { |
| 2512 | case -NFS4ERR_EXPIRED: |
| 2513 | case -NFS4ERR_ADMIN_REVOKED: |
| 2514 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2515 | break; |
| 2516 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2517 | return status; |
| 2518 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2519 | out_free: |
| 2520 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2521 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2522 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2523 | } |
| 2524 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2525 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2526 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2527 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2528 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2529 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2530 | struct rpc_cred *cred; |
| 2531 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2532 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2533 | /* Get the delegation credential for use by test/free_stateid */ |
| 2534 | rcu_read_lock(); |
| 2535 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2536 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2537 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2538 | return; |
| 2539 | } |
| 2540 | |
| 2541 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2542 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2543 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2544 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2545 | return; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2546 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2547 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2548 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2549 | rcu_read_unlock(); |
| 2550 | return; |
| 2551 | } |
| 2552 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2553 | cred = get_rpccred(delegation->cred); |
| 2554 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2555 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2556 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2557 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2558 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2559 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2560 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2564 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2565 | * |
| 2566 | * @state: NFSv4 state for an inode |
| 2567 | * |
| 2568 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2569 | * Otherwise a negative NFS4ERR value is returned. |
| 2570 | */ |
| 2571 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2572 | { |
| 2573 | int status, ret = NFS_OK; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2574 | struct nfs4_lock_state *lsp, *prev = NULL; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2575 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2576 | |
| 2577 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2578 | goto out; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2579 | |
| 2580 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2581 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2582 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2583 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2584 | |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2585 | atomic_inc(&lsp->ls_count); |
| 2586 | spin_unlock(&state->state_lock); |
| 2587 | |
| 2588 | nfs4_put_lock_state(prev); |
| 2589 | prev = lsp; |
| 2590 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2591 | status = nfs41_test_and_free_expired_stateid(server, |
| 2592 | &lsp->ls_stateid, |
| 2593 | cred); |
| 2594 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2595 | if (status == -NFS4ERR_EXPIRED || |
| 2596 | status == -NFS4ERR_BAD_STATEID) { |
| 2597 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2598 | lsp->ls_stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2599 | if (!recover_lost_locks) |
| 2600 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2601 | } else if (status != NFS_OK) { |
| 2602 | ret = status; |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2603 | nfs4_put_lock_state(prev); |
| 2604 | goto out; |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2605 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2606 | spin_lock(&state->state_lock); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2607 | } |
Benjamin Coddington | d75a6a0 | 2016-11-18 21:11:39 -0500 | [diff] [blame] | 2608 | } |
| 2609 | spin_unlock(&state->state_lock); |
| 2610 | nfs4_put_lock_state(prev); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2611 | out: |
| 2612 | return ret; |
| 2613 | } |
| 2614 | |
| 2615 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2616 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2617 | * |
| 2618 | * @state: NFSv4 state for an inode |
| 2619 | * |
| 2620 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2621 | * Otherwise a negative NFS4ERR value is returned. |
| 2622 | */ |
| 2623 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2624 | { |
| 2625 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2626 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2627 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2628 | int status; |
| 2629 | |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2630 | if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2631 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
| 2632 | if (nfs4_have_delegation(state->inode, state->state)) |
| 2633 | return NFS_OK; |
| 2634 | return -NFS4ERR_OPENMODE; |
| 2635 | } |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2636 | return -NFS4ERR_BAD_STATEID; |
Trond Myklebust | b134fc4 | 2016-09-22 13:39:16 -0400 | [diff] [blame] | 2637 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2638 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2639 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2640 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2641 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2642 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2643 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2644 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 67dd483 | 2016-09-22 13:39:17 -0400 | [diff] [blame] | 2645 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2646 | } |
Trond Myklebust | 8a64c4e | 2016-09-22 13:39:21 -0400 | [diff] [blame] | 2647 | if (status != NFS_OK) |
| 2648 | return status; |
| 2649 | if (nfs_open_stateid_recover_openmode(state)) |
| 2650 | return -NFS4ERR_OPENMODE; |
| 2651 | return NFS_OK; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2655 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2656 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2657 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2658 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2659 | status = nfs41_check_expired_locks(state); |
| 2660 | if (status != NFS_OK) |
| 2661 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2662 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2663 | if (status != NFS_OK) |
| 2664 | status = nfs4_open_expired(sp, state); |
| 2665 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2666 | } |
| 2667 | #endif |
| 2668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2670 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2671 | * fields corresponding to attributes that were used to store the verifier. |
| 2672 | * Make sure we clobber those fields in the later setattr call |
| 2673 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2674 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2675 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2676 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2677 | const u32 *attrset = opendata->o_res.attrset; |
| 2678 | |
| 2679 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2680 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2681 | sattr->ia_valid |= ATTR_ATIME; |
| 2682 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2683 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2684 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2685 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2686 | |
| 2687 | /* Except MODE, it seems harmless of setting twice. */ |
| 2688 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2689 | sattr->ia_valid &= ~ATTR_MODE; |
| 2690 | |
| 2691 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2692 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2693 | } |
| 2694 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2695 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2696 | fmode_t fmode, |
| 2697 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2698 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2699 | { |
| 2700 | struct nfs4_state_owner *sp = opendata->owner; |
| 2701 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2702 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2703 | struct nfs4_state *state; |
| 2704 | unsigned int seq; |
| 2705 | int ret; |
| 2706 | |
| 2707 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2708 | |
| 2709 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2710 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2711 | goto out; |
| 2712 | |
| 2713 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2714 | ret = PTR_ERR(state); |
| 2715 | if (IS_ERR(state)) |
| 2716 | goto out; |
| 2717 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2718 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2719 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2720 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2721 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2722 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2723 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2724 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2725 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2726 | alias = d_exact_alias(dentry, state->inode); |
| 2727 | if (!alias) |
| 2728 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2729 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2730 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2731 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2732 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2733 | } |
| 2734 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2735 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2738 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2739 | if (ret != 0) |
| 2740 | goto out; |
| 2741 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2742 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2743 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2744 | nfs_inode_attach_open_context(ctx); |
| 2745 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2746 | nfs4_schedule_stateid_recovery(server, state); |
| 2747 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2748 | out: |
| 2749 | return ret; |
| 2750 | } |
| 2751 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2752 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2753 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2755 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2756 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2757 | int flags, |
| 2758 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2759 | struct nfs4_label *label, |
| 2760 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | { |
| 2762 | struct nfs4_state_owner *sp; |
| 2763 | struct nfs4_state *state = NULL; |
| 2764 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2765 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2766 | struct dentry *dentry = ctx->dentry; |
| 2767 | struct rpc_cred *cred = ctx->cred; |
| 2768 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2769 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2770 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2771 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2772 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | |
| 2774 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2776 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2777 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2779 | goto out_err; |
| 2780 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2781 | status = nfs4_recover_expired_lease(server); |
| 2782 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2783 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2784 | if (d_really_is_positive(dentry)) |
| 2785 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2786 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2787 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2788 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2789 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2790 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2791 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2792 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2794 | if (label) { |
| 2795 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2796 | if (IS_ERR(olabel)) { |
| 2797 | status = PTR_ERR(olabel); |
| 2798 | goto err_opendata_put; |
| 2799 | } |
| 2800 | } |
| 2801 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2802 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2803 | if (!opendata->f_attr.mdsthreshold) { |
| 2804 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2805 | if (!opendata->f_attr.mdsthreshold) |
| 2806 | goto err_free_label; |
| 2807 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2808 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2809 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2810 | if (d_really_is_positive(dentry)) |
| 2811 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2812 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2813 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2814 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2815 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2816 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2817 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2818 | 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] | 2819 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2820 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2821 | /* |
| 2822 | * send create attributes which was not set by open |
| 2823 | * with an extra setattr. |
| 2824 | */ |
| 2825 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2826 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2827 | status = nfs4_do_setattr(state->inode, cred, |
| 2828 | opendata->o_res.f_attr, sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2829 | ctx, label, olabel); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2830 | if (status == 0) { |
| 2831 | nfs_setattr_update_inode(state->inode, sattr, |
| 2832 | opendata->o_res.f_attr); |
| 2833 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2834 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2835 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2836 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2837 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2838 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2839 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2840 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2841 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2842 | opendata->f_attr.mdsthreshold = NULL; |
| 2843 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2844 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2845 | nfs4_label_free(olabel); |
| 2846 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2847 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2850 | err_free_label: |
| 2851 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2852 | err_opendata_put: |
| 2853 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2854 | err_put_state_owner: |
| 2855 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | return status; |
| 2858 | } |
| 2859 | |
| 2860 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2861 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2862 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2863 | int flags, |
| 2864 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2865 | struct nfs4_label *label, |
| 2866 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2868 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | struct nfs4_exception exception = { }; |
| 2870 | struct nfs4_state *res; |
| 2871 | int status; |
| 2872 | |
| 2873 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2874 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2875 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2876 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | if (status == 0) |
| 2878 | break; |
| 2879 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2880 | * book-keeping w.r.t. state-changing operations |
| 2881 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2882 | * It is actually a sign of a bug on the client or on the server. |
| 2883 | * |
| 2884 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2885 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | * have unhashed the old state_owner for us, and that we can |
| 2887 | * therefore safely retry using a new one. We should still warn |
| 2888 | * the user though... |
| 2889 | */ |
| 2890 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2891 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2892 | " returned a bad sequence-id error!\n", |
| 2893 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | exception.retry = 1; |
| 2895 | continue; |
| 2896 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2897 | /* |
| 2898 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2899 | * state before it received the OPEN_CONFIRM. |
| 2900 | * Recover by retrying the request as per the discussion |
| 2901 | * on Page 181 of RFC3530. |
| 2902 | */ |
| 2903 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2904 | exception.retry = 1; |
| 2905 | continue; |
| 2906 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2907 | if (status == -EAGAIN) { |
| 2908 | /* We must have found a delegation */ |
| 2909 | exception.retry = 1; |
| 2910 | continue; |
| 2911 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2912 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2913 | continue; |
| 2914 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | status, &exception)); |
| 2916 | } while (exception.retry); |
| 2917 | return res; |
| 2918 | } |
| 2919 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2920 | static int _nfs4_do_setattr(struct inode *inode, |
| 2921 | struct nfs_setattrargs *arg, |
| 2922 | struct nfs_setattrres *res, |
| 2923 | struct rpc_cred *cred, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2924 | struct nfs_open_context *ctx) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2925 | { |
| 2926 | struct nfs_server *server = NFS_SERVER(inode); |
| 2927 | struct rpc_message msg = { |
| 2928 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2929 | .rpc_argp = arg, |
| 2930 | .rpc_resp = res, |
| 2931 | .rpc_cred = cred, |
| 2932 | }; |
| 2933 | struct rpc_cred *delegation_cred = NULL; |
| 2934 | unsigned long timestamp = jiffies; |
| 2935 | fmode_t fmode; |
| 2936 | bool truncate; |
| 2937 | int status; |
| 2938 | |
| 2939 | nfs_fattr_init(res->fattr); |
| 2940 | |
| 2941 | /* Servers should only apply open mode checks for file size changes */ |
| 2942 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2943 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2944 | |
| 2945 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2946 | /* Use that stateid */ |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2947 | } else if (truncate && ctx != NULL) { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame^] | 2948 | struct nfs_lock_context *l_ctx; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2949 | if (!nfs4_valid_open_stateid(ctx->state)) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2950 | return -EBADF; |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame^] | 2951 | l_ctx = nfs_get_lock_context(ctx); |
| 2952 | if (IS_ERR(l_ctx)) |
| 2953 | return PTR_ERR(l_ctx); |
| 2954 | if (nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2955 | &arg->stateid, &delegation_cred) == -EIO) |
| 2956 | return -EBADF; |
| 2957 | } else |
| 2958 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2959 | if (delegation_cred) |
| 2960 | msg.rpc_cred = delegation_cred; |
| 2961 | |
| 2962 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2963 | |
| 2964 | put_rpccred(delegation_cred); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2965 | if (status == 0 && ctx != NULL) |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2966 | renew_lease(server, timestamp); |
| 2967 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2968 | return status; |
| 2969 | } |
| 2970 | |
| 2971 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2972 | struct nfs_fattr *fattr, struct iattr *sattr, |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2973 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2974 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2976 | struct nfs_server *server = NFS_SERVER(inode); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 2977 | struct nfs4_state *state = ctx ? ctx->state : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2979 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | .iap = sattr, |
| 2981 | .server = server, |
| 2982 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2983 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | }; |
| 2985 | struct nfs_setattrres res = { |
| 2986 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2987 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | .server = server, |
| 2989 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2990 | struct nfs4_exception exception = { |
| 2991 | .state = state, |
| 2992 | .inode = inode, |
| 2993 | .stateid = &arg.stateid, |
| 2994 | }; |
| 2995 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2997 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2998 | if (ilabel) |
| 2999 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 3000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | do { |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3002 | err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3003 | switch (err) { |
| 3004 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 3005 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 3006 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 3007 | "applying open mode checks to " |
| 3008 | "a SETATTR that is not " |
| 3009 | "changing file size.\n", |
| 3010 | server->nfs_client->cl_hostname); |
| 3011 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3012 | if (state && !(state->state & FMODE_WRITE)) { |
| 3013 | err = -EBADF; |
| 3014 | if (sattr->ia_valid & ATTR_OPEN) |
| 3015 | err = -EACCES; |
| 3016 | goto out; |
| 3017 | } |
| 3018 | } |
| 3019 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 3021 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | return err; |
| 3023 | } |
| 3024 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3025 | static bool |
| 3026 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 3027 | { |
| 3028 | if (inode == NULL || !nfs_have_layout(inode)) |
| 3029 | return false; |
| 3030 | |
| 3031 | return pnfs_wait_on_layoutreturn(inode, task); |
| 3032 | } |
| 3033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | struct nfs4_closedata { |
| 3035 | struct inode *inode; |
| 3036 | struct nfs4_state *state; |
| 3037 | struct nfs_closeargs arg; |
| 3038 | struct nfs_closeres res; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3039 | struct { |
| 3040 | struct nfs4_layoutreturn_args arg; |
| 3041 | struct nfs4_layoutreturn_res res; |
| 3042 | u32 roc_barrier; |
| 3043 | bool roc; |
| 3044 | } lr; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3045 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3046 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | }; |
| 3048 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3049 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3050 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3051 | struct nfs4_closedata *calldata = data; |
| 3052 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3053 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3054 | |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3055 | if (calldata->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3056 | pnfs_roc_release(&calldata->lr.arg, &calldata->lr.res, |
| 3057 | calldata->res.lr_ret); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3058 | nfs4_put_open_state(calldata->state); |
| 3059 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3060 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3061 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3062 | kfree(calldata); |
| 3063 | } |
| 3064 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3065 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3067 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3070 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3072 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3073 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3074 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3075 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3076 | |
| 3077 | /* Handle Layoutreturn errors */ |
| 3078 | if (calldata->arg.lr_args && task->tk_status != 0) { |
| 3079 | switch (calldata->res.lr_ret) { |
| 3080 | default: |
| 3081 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 3082 | break; |
| 3083 | case 0: |
| 3084 | calldata->arg.lr_args = NULL; |
| 3085 | calldata->res.lr_res = NULL; |
| 3086 | break; |
| 3087 | case -NFS4ERR_ADMIN_REVOKED: |
| 3088 | case -NFS4ERR_DELEG_REVOKED: |
| 3089 | case -NFS4ERR_EXPIRED: |
| 3090 | case -NFS4ERR_BAD_STATEID: |
| 3091 | case -NFS4ERR_OLD_STATEID: |
| 3092 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 3093 | case -NFS4ERR_WRONG_CRED: |
| 3094 | calldata->arg.lr_args = NULL; |
| 3095 | calldata->res.lr_res = NULL; |
| 3096 | calldata->res.lr_ret = 0; |
| 3097 | rpc_restart_call_prepare(task); |
| 3098 | return; |
| 3099 | } |
| 3100 | } |
| 3101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | /* hmm. we are done with the inode, and in the process of freeing |
| 3103 | * the state_owner. we keep this around to process errors |
| 3104 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | switch (task->tk_status) { |
| 3106 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3107 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3108 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3109 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3110 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3112 | case -NFS4ERR_EXPIRED: |
| 3113 | nfs4_free_revoked_stateid(server, |
| 3114 | &calldata->arg.stateid, |
| 3115 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3116 | case -NFS4ERR_OLD_STATEID: |
| 3117 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3118 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3119 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3120 | rpc_restart_call_prepare(task); |
| 3121 | goto out_release; |
| 3122 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3123 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3124 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3126 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3127 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3128 | goto out_release; |
| 3129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3131 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3132 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3133 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3134 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3135 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3136 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3139 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3141 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3142 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3143 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3144 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3145 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3146 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3147 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3148 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3149 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3150 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3151 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3152 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3153 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3154 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3155 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3156 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3157 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3158 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3159 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3160 | if (state->n_rdonly == 0) |
| 3161 | call_close |= is_rdonly; |
| 3162 | else if (is_rdonly) |
| 3163 | calldata->arg.fmode |= FMODE_READ; |
| 3164 | if (state->n_wronly == 0) |
| 3165 | call_close |= is_wronly; |
| 3166 | else if (is_wronly) |
| 3167 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3168 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3169 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3170 | } else if (is_rdwr) |
| 3171 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3172 | |
Trond Myklebust | 5cc7861 | 2016-11-14 11:19:56 -0500 | [diff] [blame] | 3173 | if (!nfs4_valid_open_stateid(state) || |
| 3174 | test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3175 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3176 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3177 | |
| 3178 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3179 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3180 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3181 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3182 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3183 | if (!calldata->lr.roc && nfs4_wait_on_layoutreturn(inode, task)) { |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3184 | nfs_release_seqid(calldata->arg.seqid); |
| 3185 | goto out_wait; |
| 3186 | } |
| 3187 | |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3188 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3189 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3ecefc9 | 2016-10-27 18:25:04 -0400 | [diff] [blame] | 3190 | |
| 3191 | /* Close-to-open cache consistency revalidation */ |
| 3192 | if (!nfs4_have_delegation(inode, FMODE_READ)) |
| 3193 | calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 3194 | else |
| 3195 | calldata->arg.bitmask = NULL; |
| 3196 | } |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3197 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3198 | calldata->arg.share_access = |
| 3199 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3200 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3201 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3202 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3203 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3204 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3205 | &calldata->arg.seq_args, |
| 3206 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3207 | task) != 0) |
| 3208 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3209 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3210 | return; |
| 3211 | out_no_action: |
| 3212 | task->tk_action = NULL; |
| 3213 | out_wait: |
| 3214 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3217 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3218 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3219 | .rpc_call_done = nfs4_close_done, |
| 3220 | .rpc_release = nfs4_free_closedata, |
| 3221 | }; |
| 3222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | /* |
| 3224 | * It is possible for data to be read/written from a mem-mapped file |
| 3225 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3226 | * This means that we can't safely call nfsv4 close on a file until |
| 3227 | * the inode is cleared. This in turn means that we are not good |
| 3228 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3229 | * share state even when we are done with one of the three share |
| 3230 | * stateid's in the inode. |
| 3231 | * |
| 3232 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3233 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3234 | 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] | 3235 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3236 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3237 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3239 | struct nfs4_state_owner *sp = state->owner; |
| 3240 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3241 | struct rpc_message msg = { |
| 3242 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3243 | .rpc_cred = state->owner->so_cred, |
| 3244 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3245 | struct rpc_task_setup task_setup_data = { |
| 3246 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3247 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3248 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3249 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3250 | .flags = RPC_TASK_ASYNC, |
| 3251 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3252 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3254 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3255 | &task_setup_data.rpc_client, &msg); |
| 3256 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3257 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3259 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3260 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3261 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3263 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3265 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3266 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3267 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3268 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3269 | calldata->arg.fmode = 0; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3270 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3271 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3272 | calldata->res.server = server; |
Trond Myklebust | cf80516 | 2016-11-15 14:56:07 -0500 | [diff] [blame] | 3273 | calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 3274 | calldata->lr.roc = pnfs_roc(state->inode, |
| 3275 | &calldata->lr.arg, &calldata->lr.res, msg.rpc_cred); |
| 3276 | if (calldata->lr.roc) { |
| 3277 | calldata->arg.lr_args = &calldata->lr.arg; |
| 3278 | calldata->res.lr_res = &calldata->lr.res; |
| 3279 | } |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3280 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3281 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3282 | msg.rpc_argp = &calldata->arg; |
| 3283 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3284 | task_setup_data.callback_data = calldata; |
| 3285 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3286 | if (IS_ERR(task)) |
| 3287 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3288 | status = 0; |
| 3289 | if (wait) |
| 3290 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3291 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3292 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3293 | out_free_calldata: |
| 3294 | kfree(calldata); |
| 3295 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3296 | nfs4_put_open_state(state); |
| 3297 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3298 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3301 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3302 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3303 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3306 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3307 | |
| 3308 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3310 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3311 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3312 | |
| 3313 | nfs4_label_release_security(label); |
| 3314 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3315 | if (IS_ERR(state)) |
| 3316 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3317 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3320 | 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] | 3321 | { |
| 3322 | if (ctx->state == NULL) |
| 3323 | return; |
| 3324 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3325 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3326 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3327 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3330 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3331 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3332 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3335 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3336 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3337 | struct nfs4_server_caps_arg args = { |
| 3338 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3339 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3340 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | struct nfs4_server_caps_res res = {}; |
| 3342 | struct rpc_message msg = { |
| 3343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3344 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | .rpc_resp = &res, |
| 3346 | }; |
| 3347 | int status; |
| 3348 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3349 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3350 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3351 | FATTR4_WORD0_LINK_SUPPORT | |
| 3352 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3353 | FATTR4_WORD0_ACLSUPPORT; |
| 3354 | if (minorversion) |
| 3355 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3356 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3357 | 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] | 3358 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3359 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3360 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3361 | case 0: |
| 3362 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3363 | res.attr_bitmask[2] = 0; |
| 3364 | break; |
| 3365 | case 1: |
| 3366 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3367 | break; |
| 3368 | case 2: |
| 3369 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3372 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3373 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3374 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3375 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3376 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3377 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3378 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3379 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | server->caps |= NFS_CAP_ACLS; |
| 3381 | if (res.has_links != 0) |
| 3382 | server->caps |= NFS_CAP_HARDLINKS; |
| 3383 | if (res.has_symlinks != 0) |
| 3384 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3385 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3386 | server->caps |= NFS_CAP_FILEID; |
| 3387 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3388 | server->caps |= NFS_CAP_MODE; |
| 3389 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3390 | server->caps |= NFS_CAP_NLINK; |
| 3391 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3392 | server->caps |= NFS_CAP_OWNER; |
| 3393 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3394 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3395 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3396 | server->caps |= NFS_CAP_ATIME; |
| 3397 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3398 | server->caps |= NFS_CAP_CTIME; |
| 3399 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3400 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3401 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3402 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3403 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3404 | #endif |
| 3405 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3406 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3407 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3408 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3409 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3410 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3411 | 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] | 3412 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3413 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3414 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3416 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | return status; |
| 3420 | } |
| 3421 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3422 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | { |
| 3424 | struct nfs4_exception exception = { }; |
| 3425 | int err; |
| 3426 | do { |
| 3427 | err = nfs4_handle_exception(server, |
| 3428 | _nfs4_server_capabilities(server, fhandle), |
| 3429 | &exception); |
| 3430 | } while (exception.retry); |
| 3431 | return err; |
| 3432 | } |
| 3433 | |
| 3434 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3435 | struct nfs_fsinfo *info) |
| 3436 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3437 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3439 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | }; |
| 3441 | struct nfs4_lookup_res res = { |
| 3442 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3443 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | .fh = fhandle, |
| 3445 | }; |
| 3446 | struct rpc_message msg = { |
| 3447 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3448 | .rpc_argp = &args, |
| 3449 | .rpc_resp = &res, |
| 3450 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3451 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3452 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3453 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3454 | /* |
| 3455 | * Process the label in the upcoming getfattr |
| 3456 | */ |
| 3457 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3458 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3459 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3460 | 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] | 3461 | } |
| 3462 | |
| 3463 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3464 | struct nfs_fsinfo *info) |
| 3465 | { |
| 3466 | struct nfs4_exception exception = { }; |
| 3467 | int err; |
| 3468 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3469 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3470 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3471 | switch (err) { |
| 3472 | case 0: |
| 3473 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3474 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3475 | default: |
| 3476 | err = nfs4_handle_exception(server, err, &exception); |
| 3477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3479 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | return err; |
| 3481 | } |
| 3482 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3483 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3484 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3485 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3486 | struct rpc_auth_create_args auth_args = { |
| 3487 | .pseudoflavor = flavor, |
| 3488 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3489 | struct rpc_auth *auth; |
| 3490 | int ret; |
| 3491 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3492 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3493 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3494 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3495 | goto out; |
| 3496 | } |
| 3497 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3498 | out: |
| 3499 | return ret; |
| 3500 | } |
| 3501 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3502 | /* |
| 3503 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3504 | * |
| 3505 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3506 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3507 | * |
| 3508 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3509 | * negative errno value. |
| 3510 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3511 | 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] | 3512 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3514 | /* Per 3530bis 15.33.5 */ |
| 3515 | static const rpc_authflavor_t flav_array[] = { |
| 3516 | RPC_AUTH_GSS_KRB5P, |
| 3517 | RPC_AUTH_GSS_KRB5I, |
| 3518 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3519 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3520 | RPC_AUTH_NULL, |
| 3521 | }; |
| 3522 | int status = -EPERM; |
| 3523 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3525 | if (server->auth_info.flavor_len > 0) { |
| 3526 | /* try each flavor specified by user */ |
| 3527 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3528 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3529 | server->auth_info.flavors[i]); |
| 3530 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3531 | continue; |
| 3532 | break; |
| 3533 | } |
| 3534 | } else { |
| 3535 | /* no flavors specified by user, try default list */ |
| 3536 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3537 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3538 | flav_array[i]); |
| 3539 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3540 | continue; |
| 3541 | break; |
| 3542 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3543 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3544 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3545 | /* |
| 3546 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3547 | * to access the mount. It could also mean that we tried to mount |
| 3548 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3549 | * existing mount programs don't handle -EACCES very well so it should |
| 3550 | * be mapped to -EPERM instead. |
| 3551 | */ |
| 3552 | if (status == -EACCES) |
| 3553 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3554 | return status; |
| 3555 | } |
| 3556 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3557 | /** |
| 3558 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3559 | * @server: initialized nfs_server handle |
| 3560 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3561 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3562 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3563 | * |
| 3564 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3565 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3566 | 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] | 3567 | struct nfs_fsinfo *info, |
| 3568 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3569 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3570 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3571 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3572 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3573 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3574 | |
| 3575 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3576 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3577 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | if (status == 0) |
| 3580 | status = nfs4_server_capabilities(server, fhandle); |
| 3581 | if (status == 0) |
| 3582 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3583 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3584 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3587 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3588 | struct nfs_fsinfo *info) |
| 3589 | { |
| 3590 | int error; |
| 3591 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3592 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3593 | |
| 3594 | error = nfs4_server_capabilities(server, mntfh); |
| 3595 | if (error < 0) { |
| 3596 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3597 | return error; |
| 3598 | } |
| 3599 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3600 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3601 | if (IS_ERR(label)) |
| 3602 | return PTR_ERR(label); |
| 3603 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3604 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3605 | if (error < 0) { |
| 3606 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3607 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3611 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3612 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3613 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3614 | err_free_label: |
| 3615 | nfs4_label_free(label); |
| 3616 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3617 | return error; |
| 3618 | } |
| 3619 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3620 | /* |
| 3621 | * Get locations and (maybe) other attributes of a referral. |
| 3622 | * Note that we'll actually follow the referral later when |
| 3623 | * we detect fsid mismatch in inode revalidation |
| 3624 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3625 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3626 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3627 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3628 | { |
| 3629 | int status = -ENOMEM; |
| 3630 | struct page *page = NULL; |
| 3631 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3632 | |
| 3633 | page = alloc_page(GFP_KERNEL); |
| 3634 | if (page == NULL) |
| 3635 | goto out; |
| 3636 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3637 | if (locations == NULL) |
| 3638 | goto out; |
| 3639 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3640 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3641 | if (status != 0) |
| 3642 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3643 | |
| 3644 | /* |
| 3645 | * If the fsid didn't change, this is a migration event, not a |
| 3646 | * referral. Cause us to drop into the exception handler, which |
| 3647 | * will kick off migration recovery. |
| 3648 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3649 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3650 | dprintk("%s: server did not return a different fsid for" |
| 3651 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3652 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3653 | goto out; |
| 3654 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3655 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3656 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3657 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3658 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3659 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3660 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3661 | out: |
| 3662 | if (page) |
| 3663 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3664 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3665 | return status; |
| 3666 | } |
| 3667 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3668 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3669 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | { |
| 3671 | struct nfs4_getattr_arg args = { |
| 3672 | .fh = fhandle, |
| 3673 | .bitmask = server->attr_bitmask, |
| 3674 | }; |
| 3675 | struct nfs4_getattr_res res = { |
| 3676 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3677 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | .server = server, |
| 3679 | }; |
| 3680 | struct rpc_message msg = { |
| 3681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3682 | .rpc_argp = &args, |
| 3683 | .rpc_resp = &res, |
| 3684 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3685 | |
| 3686 | args.bitmask = nfs4_bitmask(server, label); |
| 3687 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3688 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3689 | 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] | 3690 | } |
| 3691 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3692 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3693 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | { |
| 3695 | struct nfs4_exception exception = { }; |
| 3696 | int err; |
| 3697 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3698 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3699 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3700 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | &exception); |
| 3702 | } while (exception.retry); |
| 3703 | return err; |
| 3704 | } |
| 3705 | |
| 3706 | /* |
| 3707 | * The file is not closed if it is opened due to the a request to change |
| 3708 | * the size of the file. The open call will not be needed once the |
| 3709 | * VFS layer lookup-intents are implemented. |
| 3710 | * |
| 3711 | * Close is called when the inode is destroyed. |
| 3712 | * If we haven't opened the file for O_WRONLY, we |
| 3713 | * need to in the size_change case to obtain a stateid. |
| 3714 | * |
| 3715 | * Got race? |
| 3716 | * Because OPEN is always done by name in nfsv4, it is |
| 3717 | * possible that we opened a different file by the same |
| 3718 | * name. We can recognize this race condition, but we |
| 3719 | * can't do anything about it besides returning an error. |
| 3720 | * |
| 3721 | * This will be fixed with VFS changes (lookup-intent). |
| 3722 | */ |
| 3723 | static int |
| 3724 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3725 | struct iattr *sattr) |
| 3726 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3727 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3728 | struct rpc_cred *cred = NULL; |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3729 | struct nfs_open_context *ctx = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3730 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | int status; |
| 3732 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3733 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3734 | sattr->ia_valid & ATTR_SIZE && |
| 3735 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3736 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3737 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3738 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3740 | /* Deal with open(O_TRUNC) */ |
| 3741 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3742 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3743 | |
| 3744 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3745 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3746 | return 0; |
| 3747 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3748 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3749 | if (sattr->ia_valid & ATTR_FILE) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3750 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3751 | ctx = nfs_file_open_context(sattr->ia_file); |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3752 | if (ctx) |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3753 | cred = ctx->cred; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3754 | } |
| 3755 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3756 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3757 | if (IS_ERR(label)) |
| 3758 | return PTR_ERR(label); |
| 3759 | |
NeilBrown | 29b59f9 | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 3760 | status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3761 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3762 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3763 | nfs_setsecurity(inode, fattr, label); |
| 3764 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3765 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | return status; |
| 3767 | } |
| 3768 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3769 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3770 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3771 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3772 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3773 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3774 | int status; |
| 3775 | struct nfs4_lookup_arg args = { |
| 3776 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3777 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3778 | .name = name, |
| 3779 | }; |
| 3780 | struct nfs4_lookup_res res = { |
| 3781 | .server = server, |
| 3782 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3783 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3784 | .fh = fhandle, |
| 3785 | }; |
| 3786 | struct rpc_message msg = { |
| 3787 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3788 | .rpc_argp = &args, |
| 3789 | .rpc_resp = &res, |
| 3790 | }; |
| 3791 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3792 | args.bitmask = nfs4_bitmask(server, label); |
| 3793 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3794 | nfs_fattr_init(fattr); |
| 3795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3797 | 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] | 3798 | dprintk("NFS reply lookup: %d\n", status); |
| 3799 | return status; |
| 3800 | } |
| 3801 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3802 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3803 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3804 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3805 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3806 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3807 | fattr->nlink = 2; |
| 3808 | } |
| 3809 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3810 | 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] | 3811 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3812 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3813 | { |
| 3814 | struct nfs4_exception exception = { }; |
| 3815 | struct rpc_clnt *client = *clnt; |
| 3816 | int err; |
| 3817 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3818 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3819 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3820 | switch (err) { |
| 3821 | case -NFS4ERR_BADNAME: |
| 3822 | err = -ENOENT; |
| 3823 | goto out; |
| 3824 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3825 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3826 | if (err == -NFS4ERR_MOVED) |
| 3827 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3828 | goto out; |
| 3829 | case -NFS4ERR_WRONGSEC: |
| 3830 | err = -EPERM; |
| 3831 | if (client != *clnt) |
| 3832 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3833 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3834 | if (IS_ERR(client)) |
| 3835 | return PTR_ERR(client); |
| 3836 | |
| 3837 | exception.retry = 1; |
| 3838 | break; |
| 3839 | default: |
| 3840 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3841 | } |
| 3842 | } while (exception.retry); |
| 3843 | |
| 3844 | out: |
| 3845 | if (err == 0) |
| 3846 | *clnt = client; |
| 3847 | else if (client != *clnt) |
| 3848 | rpc_shutdown_client(client); |
| 3849 | |
| 3850 | return err; |
| 3851 | } |
| 3852 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3853 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3854 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3855 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3857 | int status; |
| 3858 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3859 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3860 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3861 | if (client != NFS_CLIENT(dir)) { |
| 3862 | rpc_shutdown_client(client); |
| 3863 | nfs_fixup_secinfo_attributes(fattr); |
| 3864 | } |
| 3865 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3868 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3869 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3870 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3871 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3872 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3873 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3874 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3875 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3876 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3877 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3878 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3879 | } |
| 3880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3882 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3883 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | struct nfs4_accessargs args = { |
| 3885 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3886 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3888 | struct nfs4_accessres res = { |
| 3889 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3890 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | struct rpc_message msg = { |
| 3892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3893 | .rpc_argp = &args, |
| 3894 | .rpc_resp = &res, |
| 3895 | .rpc_cred = entry->cred, |
| 3896 | }; |
| 3897 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3898 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | |
| 3900 | /* |
| 3901 | * Determine which access bits we want to ask for... |
| 3902 | */ |
| 3903 | if (mode & MAY_READ) |
| 3904 | args.access |= NFS4_ACCESS_READ; |
| 3905 | if (S_ISDIR(inode->i_mode)) { |
| 3906 | if (mode & MAY_WRITE) |
| 3907 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3908 | if (mode & MAY_EXEC) |
| 3909 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3910 | } else { |
| 3911 | if (mode & MAY_WRITE) |
| 3912 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3913 | if (mode & MAY_EXEC) |
| 3914 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3915 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3916 | |
| 3917 | res.fattr = nfs_alloc_fattr(); |
| 3918 | if (res.fattr == NULL) |
| 3919 | return -ENOMEM; |
| 3920 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3921 | 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] | 3922 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3923 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3924 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3926 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | return status; |
| 3928 | } |
| 3929 | |
| 3930 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3931 | { |
| 3932 | struct nfs4_exception exception = { }; |
| 3933 | int err; |
| 3934 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3935 | err = _nfs4_proc_access(inode, entry); |
| 3936 | trace_nfs4_access(inode, err); |
| 3937 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | &exception); |
| 3939 | } while (exception.retry); |
| 3940 | return err; |
| 3941 | } |
| 3942 | |
| 3943 | /* |
| 3944 | * TODO: For the time being, we don't try to get any attributes |
| 3945 | * along with any of the zero-copy operations READ, READDIR, |
| 3946 | * READLINK, WRITE. |
| 3947 | * |
| 3948 | * In the case of the first three, we want to put the GETATTR |
| 3949 | * after the read-type operation -- this is because it is hard |
| 3950 | * to predict the length of a GETATTR response in v4, and thus |
| 3951 | * align the READ data correctly. This means that the GETATTR |
| 3952 | * may end up partially falling into the page cache, and we should |
| 3953 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3954 | * To do this efficiently, we need to know the total length |
| 3955 | * of data received, which doesn't seem to be available outside |
| 3956 | * of the RPC layer. |
| 3957 | * |
| 3958 | * In the case of WRITE, we also want to put the GETATTR after |
| 3959 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3960 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | * |
| 3962 | * Both of these changes to the XDR layer would in fact be quite |
| 3963 | * minor, but I decided to leave them for a subsequent patch. |
| 3964 | */ |
| 3965 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3966 | unsigned int pgbase, unsigned int pglen) |
| 3967 | { |
| 3968 | struct nfs4_readlink args = { |
| 3969 | .fh = NFS_FH(inode), |
| 3970 | .pgbase = pgbase, |
| 3971 | .pglen = pglen, |
| 3972 | .pages = &page, |
| 3973 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3974 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | struct rpc_message msg = { |
| 3976 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3977 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3978 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | }; |
| 3980 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3981 | 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] | 3982 | } |
| 3983 | |
| 3984 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3985 | unsigned int pgbase, unsigned int pglen) |
| 3986 | { |
| 3987 | struct nfs4_exception exception = { }; |
| 3988 | int err; |
| 3989 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3990 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3991 | trace_nfs4_readlink(inode, err); |
| 3992 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | &exception); |
| 3994 | } while (exception.retry); |
| 3995 | return err; |
| 3996 | } |
| 3997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3999 | * 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] | 4000 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | static int |
| 4002 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4003 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4005 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4006 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | int status = 0; |
| 4009 | |
NeilBrown | 532d4de | 2016-10-13 15:26:47 +1100 | [diff] [blame] | 4010 | ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4011 | if (IS_ERR(ctx)) |
| 4012 | return PTR_ERR(ctx); |
| 4013 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4014 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4015 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4016 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 4017 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | if (IS_ERR(state)) { |
| 4019 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 4020 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4023 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 4024 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | return status; |
| 4026 | } |
| 4027 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4028 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4030 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4031 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 4033 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4035 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4036 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4037 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 4039 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 4040 | .rpc_argp = &args, |
| 4041 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4043 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 4044 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4045 | 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] | 4046 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4047 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | return status; |
| 4049 | } |
| 4050 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4051 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | { |
| 4053 | struct nfs4_exception exception = { }; |
| 4054 | int err; |
| 4055 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4056 | err = _nfs4_proc_remove(dir, name); |
| 4057 | trace_nfs4_remove(dir, name, err); |
| 4058 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | &exception); |
| 4060 | } while (exception.retry); |
| 4061 | return err; |
| 4062 | } |
| 4063 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4064 | 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] | 4065 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4066 | struct nfs_server *server = NFS_SERVER(dir); |
| 4067 | struct nfs_removeargs *args = msg->rpc_argp; |
| 4068 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4070 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4072 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4073 | |
| 4074 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 4077 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 4078 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 4079 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4080 | &data->args.seq_args, |
| 4081 | &data->res.seq_res, |
| 4082 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4085 | 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] | 4086 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4087 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4088 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4089 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4090 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4091 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4092 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4093 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4094 | return 0; |
| 4095 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4096 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4099 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4100 | { |
| 4101 | struct nfs_server *server = NFS_SERVER(dir); |
| 4102 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4103 | struct nfs_renameres *res = msg->rpc_resp; |
| 4104 | |
| 4105 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4106 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4107 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4108 | } |
| 4109 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4110 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4111 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4112 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4113 | &data->args.seq_args, |
| 4114 | &data->res.seq_res, |
| 4115 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4119 | struct inode *new_dir) |
| 4120 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4121 | struct nfs_renamedata *data = task->tk_calldata; |
| 4122 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4123 | |
| 4124 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4125 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4126 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4127 | return 0; |
| 4128 | |
| 4129 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4130 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4131 | return 1; |
| 4132 | } |
| 4133 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4134 | 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] | 4135 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4136 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | struct nfs4_link_arg arg = { |
| 4138 | .fh = NFS_FH(inode), |
| 4139 | .dir_fh = NFS_FH(dir), |
| 4140 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4141 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4143 | struct nfs4_link_res res = { |
| 4144 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4145 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4146 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | struct rpc_message msg = { |
| 4148 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4149 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4150 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4152 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4154 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4155 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4156 | goto out; |
| 4157 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4158 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4159 | if (IS_ERR(res.label)) { |
| 4160 | status = PTR_ERR(res.label); |
| 4161 | goto out; |
| 4162 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4163 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4164 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4165 | 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] | 4166 | if (!status) { |
| 4167 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4168 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4169 | if (!status) |
| 4170 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4171 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4172 | |
| 4173 | |
| 4174 | nfs4_label_free(res.label); |
| 4175 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4176 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4177 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | return status; |
| 4179 | } |
| 4180 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4181 | 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] | 4182 | { |
| 4183 | struct nfs4_exception exception = { }; |
| 4184 | int err; |
| 4185 | do { |
| 4186 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4187 | _nfs4_proc_link(inode, dir, name), |
| 4188 | &exception); |
| 4189 | } while (exception.retry); |
| 4190 | return err; |
| 4191 | } |
| 4192 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4193 | struct nfs4_createdata { |
| 4194 | struct rpc_message msg; |
| 4195 | struct nfs4_create_arg arg; |
| 4196 | struct nfs4_create_res res; |
| 4197 | struct nfs_fh fh; |
| 4198 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4199 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4200 | }; |
| 4201 | |
| 4202 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4203 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4204 | { |
| 4205 | struct nfs4_createdata *data; |
| 4206 | |
| 4207 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4208 | if (data != NULL) { |
| 4209 | struct nfs_server *server = NFS_SERVER(dir); |
| 4210 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4211 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4212 | if (IS_ERR(data->label)) |
| 4213 | goto out_free; |
| 4214 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4215 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4216 | data->msg.rpc_argp = &data->arg; |
| 4217 | data->msg.rpc_resp = &data->res; |
| 4218 | data->arg.dir_fh = NFS_FH(dir); |
| 4219 | data->arg.server = server; |
| 4220 | data->arg.name = name; |
| 4221 | data->arg.attrs = sattr; |
| 4222 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4223 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4224 | data->res.server = server; |
| 4225 | data->res.fh = &data->fh; |
| 4226 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4227 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4228 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4229 | } |
| 4230 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4231 | out_free: |
| 4232 | kfree(data); |
| 4233 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4234 | } |
| 4235 | |
| 4236 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4237 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4238 | 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] | 4239 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4240 | if (status == 0) { |
| 4241 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4242 | 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] | 4243 | } |
| 4244 | return status; |
| 4245 | } |
| 4246 | |
| 4247 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4248 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4249 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4250 | kfree(data); |
| 4251 | } |
| 4252 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4253 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4254 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4255 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4257 | struct nfs4_createdata *data; |
| 4258 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4260 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4261 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4262 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4263 | status = -ENOMEM; |
| 4264 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4265 | if (data == NULL) |
| 4266 | goto out; |
| 4267 | |
| 4268 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4269 | data->arg.u.symlink.pages = &page; |
| 4270 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4271 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4273 | status = nfs4_do_create(dir, dentry, data); |
| 4274 | |
| 4275 | nfs4_free_createdata(data); |
| 4276 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | return status; |
| 4278 | } |
| 4279 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4280 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4281 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | { |
| 4283 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4284 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4286 | |
| 4287 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4290 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4291 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4292 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | &exception); |
| 4294 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4295 | |
| 4296 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | return err; |
| 4298 | } |
| 4299 | |
| 4300 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4301 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4303 | struct nfs4_createdata *data; |
| 4304 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4306 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4307 | if (data == NULL) |
| 4308 | goto out; |
| 4309 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4310 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4311 | status = nfs4_do_create(dir, dentry, data); |
| 4312 | |
| 4313 | nfs4_free_createdata(data); |
| 4314 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | return status; |
| 4316 | } |
| 4317 | |
| 4318 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4319 | struct iattr *sattr) |
| 4320 | { |
| 4321 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4322 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4324 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4325 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4326 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4327 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4329 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4330 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4331 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | &exception); |
| 4333 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4334 | nfs4_label_release_security(label); |
| 4335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | return err; |
| 4337 | } |
| 4338 | |
| 4339 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4340 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4342 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | struct nfs4_readdir_arg args = { |
| 4344 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4345 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | .pgbase = 0, |
| 4347 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4348 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4349 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | }; |
| 4351 | struct nfs4_readdir_res res; |
| 4352 | struct rpc_message msg = { |
| 4353 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4354 | .rpc_argp = &args, |
| 4355 | .rpc_resp = &res, |
| 4356 | .rpc_cred = cred, |
| 4357 | }; |
| 4358 | int status; |
| 4359 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4360 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4361 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4362 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4363 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4365 | 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] | 4366 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4367 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4368 | status += args.pgbase; |
| 4369 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4370 | |
| 4371 | nfs_invalidate_atime(dir); |
| 4372 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4373 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | return status; |
| 4375 | } |
| 4376 | |
| 4377 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4378 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | { |
| 4380 | struct nfs4_exception exception = { }; |
| 4381 | int err; |
| 4382 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4383 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4384 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4385 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4386 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | &exception); |
| 4388 | } while (exception.retry); |
| 4389 | return err; |
| 4390 | } |
| 4391 | |
| 4392 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4393 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4395 | struct nfs4_createdata *data; |
| 4396 | int mode = sattr->ia_mode; |
| 4397 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4399 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4400 | if (data == NULL) |
| 4401 | goto out; |
| 4402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4404 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4406 | data->arg.ftype = NF4BLK; |
| 4407 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4408 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | } |
| 4410 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4411 | data->arg.ftype = NF4CHR; |
| 4412 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4413 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4414 | } else if (!S_ISSOCK(mode)) { |
| 4415 | status = -EINVAL; |
| 4416 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4418 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4419 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4420 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4421 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4422 | nfs4_free_createdata(data); |
| 4423 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | return status; |
| 4425 | } |
| 4426 | |
| 4427 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4428 | struct iattr *sattr, dev_t rdev) |
| 4429 | { |
| 4430 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4431 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4433 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4434 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4435 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4436 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4438 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4439 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4440 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | &exception); |
| 4442 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4443 | |
| 4444 | nfs4_label_release_security(label); |
| 4445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | return err; |
| 4447 | } |
| 4448 | |
| 4449 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4450 | struct nfs_fsstat *fsstat) |
| 4451 | { |
| 4452 | struct nfs4_statfs_arg args = { |
| 4453 | .fh = fhandle, |
| 4454 | .bitmask = server->attr_bitmask, |
| 4455 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4456 | struct nfs4_statfs_res res = { |
| 4457 | .fsstat = fsstat, |
| 4458 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | struct rpc_message msg = { |
| 4460 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4461 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4462 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | }; |
| 4464 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4465 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4466 | 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] | 4467 | } |
| 4468 | |
| 4469 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4470 | { |
| 4471 | struct nfs4_exception exception = { }; |
| 4472 | int err; |
| 4473 | do { |
| 4474 | err = nfs4_handle_exception(server, |
| 4475 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4476 | &exception); |
| 4477 | } while (exception.retry); |
| 4478 | return err; |
| 4479 | } |
| 4480 | |
| 4481 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4482 | struct nfs_fsinfo *fsinfo) |
| 4483 | { |
| 4484 | struct nfs4_fsinfo_arg args = { |
| 4485 | .fh = fhandle, |
| 4486 | .bitmask = server->attr_bitmask, |
| 4487 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4488 | struct nfs4_fsinfo_res res = { |
| 4489 | .fsinfo = fsinfo, |
| 4490 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | struct rpc_message msg = { |
| 4492 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4493 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4494 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | }; |
| 4496 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4497 | 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] | 4498 | } |
| 4499 | |
| 4500 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4501 | { |
| 4502 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4503 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | int err; |
| 4505 | |
| 4506 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4507 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4508 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4509 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4510 | nfs4_set_lease_period(server->nfs_client, |
| 4511 | fsinfo->lease_time * HZ, |
| 4512 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4513 | break; |
| 4514 | } |
| 4515 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | } while (exception.retry); |
| 4517 | return err; |
| 4518 | } |
| 4519 | |
| 4520 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4521 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4522 | int error; |
| 4523 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4524 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4525 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4526 | if (error == 0) { |
| 4527 | /* block layout checks this! */ |
| 4528 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4529 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4530 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4531 | |
| 4532 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4536 | struct nfs_pathconf *pathconf) |
| 4537 | { |
| 4538 | struct nfs4_pathconf_arg args = { |
| 4539 | .fh = fhandle, |
| 4540 | .bitmask = server->attr_bitmask, |
| 4541 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4542 | struct nfs4_pathconf_res res = { |
| 4543 | .pathconf = pathconf, |
| 4544 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | struct rpc_message msg = { |
| 4546 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4547 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4548 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | }; |
| 4550 | |
| 4551 | /* None of the pathconf attributes are mandatory to implement */ |
| 4552 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4553 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4554 | return 0; |
| 4555 | } |
| 4556 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4557 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4558 | 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] | 4559 | } |
| 4560 | |
| 4561 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4562 | struct nfs_pathconf *pathconf) |
| 4563 | { |
| 4564 | struct nfs4_exception exception = { }; |
| 4565 | int err; |
| 4566 | |
| 4567 | do { |
| 4568 | err = nfs4_handle_exception(server, |
| 4569 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4570 | &exception); |
| 4571 | } while (exception.retry); |
| 4572 | return err; |
| 4573 | } |
| 4574 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4575 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4576 | const struct nfs_open_context *ctx, |
| 4577 | const struct nfs_lock_context *l_ctx, |
| 4578 | fmode_t fmode) |
| 4579 | { |
NeilBrown | 1739347 | 2016-10-13 15:26:47 +1100 | [diff] [blame^] | 4580 | return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4581 | } |
| 4582 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4583 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4584 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4585 | const struct nfs_open_context *ctx, |
| 4586 | const struct nfs_lock_context *l_ctx, |
| 4587 | fmode_t fmode) |
| 4588 | { |
| 4589 | nfs4_stateid current_stateid; |
| 4590 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4591 | /* If the current stateid represents a lost lock, then exit */ |
| 4592 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4593 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4594 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4595 | } |
| 4596 | |
| 4597 | static bool nfs4_error_stateid_expired(int err) |
| 4598 | { |
| 4599 | switch (err) { |
| 4600 | case -NFS4ERR_DELEG_REVOKED: |
| 4601 | case -NFS4ERR_ADMIN_REVOKED: |
| 4602 | case -NFS4ERR_BAD_STATEID: |
| 4603 | case -NFS4ERR_STALE_STATEID: |
| 4604 | case -NFS4ERR_OLD_STATEID: |
| 4605 | case -NFS4ERR_OPENMODE: |
| 4606 | case -NFS4ERR_EXPIRED: |
| 4607 | return true; |
| 4608 | } |
| 4609 | return false; |
| 4610 | } |
| 4611 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4612 | 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] | 4613 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4614 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4616 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4617 | if (task->tk_status < 0) { |
| 4618 | struct nfs4_exception exception = { |
| 4619 | .inode = hdr->inode, |
| 4620 | .state = hdr->args.context->state, |
| 4621 | .stateid = &hdr->args.stateid, |
| 4622 | }; |
| 4623 | task->tk_status = nfs4_async_handle_exception(task, |
| 4624 | server, task->tk_status, &exception); |
| 4625 | if (exception.retry) { |
| 4626 | rpc_restart_call_prepare(task); |
| 4627 | return -EAGAIN; |
| 4628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4632 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4633 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4636 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4637 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4638 | { |
| 4639 | |
| 4640 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4641 | nfs4_stateid_is_current(&args->stateid, |
| 4642 | args->context, |
| 4643 | args->lock_context, |
| 4644 | FMODE_READ)) |
| 4645 | return false; |
| 4646 | rpc_restart_call_prepare(task); |
| 4647 | return true; |
| 4648 | } |
| 4649 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4650 | 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] | 4651 | { |
| 4652 | |
| 4653 | dprintk("--> %s\n", __func__); |
| 4654 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4655 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4656 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4657 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4658 | return -EAGAIN; |
Trond Myklebust | bfc505d | 2016-09-15 18:26:05 -0400 | [diff] [blame] | 4659 | if (task->tk_status > 0) |
| 4660 | nfs_invalidate_atime(hdr->inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4662 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4665 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4666 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4668 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4669 | if (!hdr->pgio_done_cb) |
| 4670 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4671 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4672 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4675 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4676 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4677 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4678 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4679 | &hdr->args.seq_args, |
| 4680 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4681 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4682 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4683 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4684 | hdr->args.lock_context, |
| 4685 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4686 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4687 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4688 | return -EIO; |
| 4689 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4692 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4693 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4695 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4696 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4697 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4698 | if (task->tk_status < 0) { |
| 4699 | struct nfs4_exception exception = { |
| 4700 | .inode = hdr->inode, |
| 4701 | .state = hdr->args.context->state, |
| 4702 | .stateid = &hdr->args.stateid, |
| 4703 | }; |
| 4704 | task->tk_status = nfs4_async_handle_exception(task, |
| 4705 | NFS_SERVER(inode), task->tk_status, |
| 4706 | &exception); |
| 4707 | if (exception.retry) { |
| 4708 | rpc_restart_call_prepare(task); |
| 4709 | return -EAGAIN; |
| 4710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4712 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4713 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4714 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4715 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4716 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4719 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4720 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4721 | { |
| 4722 | |
| 4723 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4724 | nfs4_stateid_is_current(&args->stateid, |
| 4725 | args->context, |
| 4726 | args->lock_context, |
| 4727 | FMODE_WRITE)) |
| 4728 | return false; |
| 4729 | rpc_restart_call_prepare(task); |
| 4730 | return true; |
| 4731 | } |
| 4732 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4733 | 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] | 4734 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4735 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4736 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4737 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4738 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4739 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4740 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4743 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4744 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4745 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4746 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4747 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4748 | return false; |
| 4749 | /* Otherwise, request attributes if and only if we don't hold |
| 4750 | * a delegation |
| 4751 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4752 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4753 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4754 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4755 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4756 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4758 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4759 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4760 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4761 | hdr->args.bitmask = NULL; |
| 4762 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4763 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4764 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4765 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4766 | if (!hdr->pgio_done_cb) |
| 4767 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4768 | hdr->res.server = server; |
| 4769 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4771 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4772 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | } |
| 4774 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4775 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4776 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4777 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4778 | &data->args.seq_args, |
| 4779 | &data->res.seq_res, |
| 4780 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4783 | 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] | 4784 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4786 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4787 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4788 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4789 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4790 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4791 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4793 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | } |
| 4795 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4796 | 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] | 4797 | { |
| 4798 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4799 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4800 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4803 | 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] | 4804 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4805 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4806 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4807 | if (data->commit_done_cb == NULL) |
| 4808 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4809 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4810 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4811 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4814 | struct nfs4_renewdata { |
| 4815 | struct nfs_client *client; |
| 4816 | unsigned long timestamp; |
| 4817 | }; |
| 4818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | /* |
| 4820 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4821 | * standalone procedure for queueing an asynchronous RENEW. |
| 4822 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4823 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4824 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4825 | struct nfs4_renewdata *data = calldata; |
| 4826 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4827 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4828 | if (atomic_read(&clp->cl_count) > 1) |
| 4829 | nfs4_schedule_state_renewal(clp); |
| 4830 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4831 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4832 | } |
| 4833 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4834 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4836 | struct nfs4_renewdata *data = calldata; |
| 4837 | struct nfs_client *clp = data->client; |
| 4838 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4840 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4841 | switch (task->tk_status) { |
| 4842 | case 0: |
| 4843 | break; |
| 4844 | case -NFS4ERR_LEASE_MOVED: |
| 4845 | nfs4_schedule_lease_moved_recovery(clp); |
| 4846 | break; |
| 4847 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4848 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4849 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4850 | return; |
| 4851 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4852 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4853 | return; |
| 4854 | } |
| 4855 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4857 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4860 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4861 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4862 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4863 | }; |
| 4864 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4865 | 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] | 4866 | { |
| 4867 | struct rpc_message msg = { |
| 4868 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4869 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4870 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4872 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4874 | if (renew_flags == 0) |
| 4875 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4876 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4877 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4878 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4879 | if (data == NULL) |
| 4880 | return -ENOMEM; |
| 4881 | data->client = clp; |
| 4882 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4883 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4884 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | } |
| 4886 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4887 | 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] | 4888 | { |
| 4889 | struct rpc_message msg = { |
| 4890 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4891 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4892 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | }; |
| 4894 | unsigned long now = jiffies; |
| 4895 | int status; |
| 4896 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4897 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | if (status < 0) |
| 4899 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4900 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | return 0; |
| 4902 | } |
| 4903 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4904 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4905 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4906 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4909 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4910 | * 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] | 4911 | * the stack. |
| 4912 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4913 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4914 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4915 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4916 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4917 | { |
| 4918 | struct page *newpage, **spages; |
| 4919 | int rc = 0; |
| 4920 | size_t len; |
| 4921 | spages = pages; |
| 4922 | |
| 4923 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4924 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4925 | newpage = alloc_page(GFP_KERNEL); |
| 4926 | |
| 4927 | if (newpage == NULL) |
| 4928 | goto unwind; |
| 4929 | memcpy(page_address(newpage), buf, len); |
| 4930 | buf += len; |
| 4931 | buflen -= len; |
| 4932 | *pages++ = newpage; |
| 4933 | rc++; |
| 4934 | } while (buflen != 0); |
| 4935 | |
| 4936 | return rc; |
| 4937 | |
| 4938 | unwind: |
| 4939 | for(; rc > 0; rc--) |
| 4940 | __free_page(spages[rc-1]); |
| 4941 | return -ENOMEM; |
| 4942 | } |
| 4943 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4944 | struct nfs4_cached_acl { |
| 4945 | int cached; |
| 4946 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4947 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4948 | }; |
| 4949 | |
| 4950 | 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] | 4951 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4952 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4953 | |
| 4954 | spin_lock(&inode->i_lock); |
| 4955 | kfree(nfsi->nfs4_acl); |
| 4956 | nfsi->nfs4_acl = acl; |
| 4957 | spin_unlock(&inode->i_lock); |
| 4958 | } |
| 4959 | |
| 4960 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4961 | { |
| 4962 | nfs4_set_cached_acl(inode, NULL); |
| 4963 | } |
| 4964 | |
| 4965 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4966 | { |
| 4967 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4968 | struct nfs4_cached_acl *acl; |
| 4969 | int ret = -ENOENT; |
| 4970 | |
| 4971 | spin_lock(&inode->i_lock); |
| 4972 | acl = nfsi->nfs4_acl; |
| 4973 | if (acl == NULL) |
| 4974 | goto out; |
| 4975 | if (buf == NULL) /* user is just asking for length */ |
| 4976 | goto out_len; |
| 4977 | if (acl->cached == 0) |
| 4978 | goto out; |
| 4979 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4980 | if (acl->len > buflen) |
| 4981 | goto out; |
| 4982 | memcpy(buf, acl->data, acl->len); |
| 4983 | out_len: |
| 4984 | ret = acl->len; |
| 4985 | out: |
| 4986 | spin_unlock(&inode->i_lock); |
| 4987 | return ret; |
| 4988 | } |
| 4989 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4990 | 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] | 4991 | { |
| 4992 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4993 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4994 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4995 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4996 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4997 | if (acl == NULL) |
| 4998 | goto out; |
| 4999 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 5000 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5001 | } else { |
| 5002 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 5003 | if (acl == NULL) |
| 5004 | goto out; |
| 5005 | acl->cached = 0; |
| 5006 | } |
| 5007 | acl->len = acl_len; |
| 5008 | out: |
| 5009 | nfs4_set_cached_acl(inode, acl); |
| 5010 | } |
| 5011 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5012 | /* |
| 5013 | * The getxattr API returns the required buffer length when called with a |
| 5014 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 5015 | * the required buf. On a NULL buf, we send a page of data to the server |
| 5016 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 5017 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 5018 | * the cache. If not so, we throw away the page, and cache the required |
| 5019 | * length. The next getxattr call will then produce another round trip to |
| 5020 | * the server, this time with the input buf of the required size. |
| 5021 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5022 | 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] | 5023 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5024 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5025 | struct nfs_getaclargs args = { |
| 5026 | .fh = NFS_FH(inode), |
| 5027 | .acl_pages = pages, |
| 5028 | .acl_len = buflen, |
| 5029 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5030 | struct nfs_getaclres res = { |
| 5031 | .acl_len = buflen, |
| 5032 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5033 | struct rpc_message msg = { |
| 5034 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 5035 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 5036 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5037 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5038 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 5039 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5040 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5041 | /* As long as we're doing a round trip to the server anyway, |
| 5042 | * let's be prepared for a page of acl data. */ |
| 5043 | if (npages == 0) |
| 5044 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5045 | if (npages > ARRAY_SIZE(pages)) |
| 5046 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5047 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5048 | for (i = 0; i < npages; i++) { |
| 5049 | pages[i] = alloc_page(GFP_KERNEL); |
| 5050 | if (!pages[i]) |
| 5051 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5052 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5053 | |
| 5054 | /* for decoding across pages */ |
| 5055 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 5056 | if (!res.acl_scratch) |
| 5057 | goto out_free; |
| 5058 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5059 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 5060 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 5061 | 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] | 5062 | __func__, buf, buflen, npages, args.acl_len); |
| 5063 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 5064 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5065 | if (ret) |
| 5066 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5067 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5068 | /* Handle the case where the passed-in buffer is too short */ |
| 5069 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 5070 | /* Did the user only issue a request for the acl length? */ |
| 5071 | if (buf == NULL) |
| 5072 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5073 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5074 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5075 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5076 | 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] | 5077 | if (buf) { |
| 5078 | if (res.acl_len > buflen) { |
| 5079 | ret = -ERANGE; |
| 5080 | goto out_free; |
| 5081 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5082 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5083 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5084 | out_ok: |
| 5085 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5086 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5087 | for (i = 0; i < npages; i++) |
| 5088 | if (pages[i]) |
| 5089 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5090 | if (res.acl_scratch) |
| 5091 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5092 | return ret; |
| 5093 | } |
| 5094 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5095 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5096 | { |
| 5097 | struct nfs4_exception exception = { }; |
| 5098 | ssize_t ret; |
| 5099 | do { |
| 5100 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5101 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5102 | if (ret >= 0) |
| 5103 | break; |
| 5104 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5105 | } while (exception.retry); |
| 5106 | return ret; |
| 5107 | } |
| 5108 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5109 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5110 | { |
| 5111 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5112 | int ret; |
| 5113 | |
| 5114 | if (!nfs4_server_supports_acls(server)) |
| 5115 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5116 | ret = nfs_revalidate_inode(server, inode); |
| 5117 | if (ret < 0) |
| 5118 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5119 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5120 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5121 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5122 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5123 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5124 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5125 | return ret; |
| 5126 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5129 | 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] | 5130 | { |
| 5131 | struct nfs_server *server = NFS_SERVER(inode); |
| 5132 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5133 | struct nfs_setaclargs arg = { |
| 5134 | .fh = NFS_FH(inode), |
| 5135 | .acl_pages = pages, |
| 5136 | .acl_len = buflen, |
| 5137 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5138 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5139 | struct rpc_message msg = { |
| 5140 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5141 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5142 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5143 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5144 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5145 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5146 | |
| 5147 | if (!nfs4_server_supports_acls(server)) |
| 5148 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5149 | if (npages > ARRAY_SIZE(pages)) |
| 5150 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5151 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5152 | if (i < 0) |
| 5153 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5154 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5155 | 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] | 5156 | |
| 5157 | /* |
| 5158 | * Free each page after tx, so the only ref left is |
| 5159 | * held by the network stack |
| 5160 | */ |
| 5161 | for (; i > 0; i--) |
| 5162 | put_page(pages[i-1]); |
| 5163 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5164 | /* |
| 5165 | * Acl update can result in inode attribute update. |
| 5166 | * so mark the attribute cache invalid. |
| 5167 | */ |
| 5168 | spin_lock(&inode->i_lock); |
| 5169 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5170 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5171 | nfs_access_zap_cache(inode); |
| 5172 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5173 | return ret; |
| 5174 | } |
| 5175 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5176 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5177 | { |
| 5178 | struct nfs4_exception exception = { }; |
| 5179 | int err; |
| 5180 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5181 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5182 | trace_nfs4_set_acl(inode, err); |
| 5183 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5184 | &exception); |
| 5185 | } while (exception.retry); |
| 5186 | return err; |
| 5187 | } |
| 5188 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5189 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5190 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5191 | size_t buflen) |
| 5192 | { |
| 5193 | struct nfs_server *server = NFS_SERVER(inode); |
| 5194 | struct nfs_fattr fattr; |
| 5195 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5196 | |
| 5197 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5198 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5199 | .fh = NFS_FH(inode), |
| 5200 | .bitmask = bitmask, |
| 5201 | }; |
| 5202 | struct nfs4_getattr_res res = { |
| 5203 | .fattr = &fattr, |
| 5204 | .label = &label, |
| 5205 | .server = server, |
| 5206 | }; |
| 5207 | struct rpc_message msg = { |
| 5208 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5209 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5210 | .rpc_resp = &res, |
| 5211 | }; |
| 5212 | int ret; |
| 5213 | |
| 5214 | nfs_fattr_init(&fattr); |
| 5215 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5216 | 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] | 5217 | if (ret) |
| 5218 | return ret; |
| 5219 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5220 | return -ENOENT; |
| 5221 | if (buflen < label.len) |
| 5222 | return -ERANGE; |
| 5223 | return 0; |
| 5224 | } |
| 5225 | |
| 5226 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5227 | size_t buflen) |
| 5228 | { |
| 5229 | struct nfs4_exception exception = { }; |
| 5230 | int err; |
| 5231 | |
| 5232 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5233 | return -EOPNOTSUPP; |
| 5234 | |
| 5235 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5236 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5237 | trace_nfs4_get_security_label(inode, err); |
| 5238 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5239 | &exception); |
| 5240 | } while (exception.retry); |
| 5241 | return err; |
| 5242 | } |
| 5243 | |
| 5244 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5245 | struct nfs4_label *ilabel, |
| 5246 | struct nfs_fattr *fattr, |
| 5247 | struct nfs4_label *olabel) |
| 5248 | { |
| 5249 | |
| 5250 | struct iattr sattr = {0}; |
| 5251 | struct nfs_server *server = NFS_SERVER(inode); |
| 5252 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5253 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5254 | .fh = NFS_FH(inode), |
| 5255 | .iap = &sattr, |
| 5256 | .server = server, |
| 5257 | .bitmask = bitmask, |
| 5258 | .label = ilabel, |
| 5259 | }; |
| 5260 | struct nfs_setattrres res = { |
| 5261 | .fattr = fattr, |
| 5262 | .label = olabel, |
| 5263 | .server = server, |
| 5264 | }; |
| 5265 | struct rpc_message msg = { |
| 5266 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5267 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5268 | .rpc_resp = &res, |
| 5269 | }; |
| 5270 | int status; |
| 5271 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5272 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5273 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5274 | 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] | 5275 | if (status) |
| 5276 | dprintk("%s failed: %d\n", __func__, status); |
| 5277 | |
| 5278 | return status; |
| 5279 | } |
| 5280 | |
| 5281 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5282 | struct nfs4_label *ilabel, |
| 5283 | struct nfs_fattr *fattr, |
| 5284 | struct nfs4_label *olabel) |
| 5285 | { |
| 5286 | struct nfs4_exception exception = { }; |
| 5287 | int err; |
| 5288 | |
| 5289 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5290 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5291 | fattr, olabel); |
| 5292 | trace_nfs4_set_security_label(inode, err); |
| 5293 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5294 | &exception); |
| 5295 | } while (exception.retry); |
| 5296 | return err; |
| 5297 | } |
| 5298 | |
| 5299 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5300 | 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] | 5301 | { |
| 5302 | struct nfs4_label ilabel, *olabel = NULL; |
| 5303 | struct nfs_fattr fattr; |
| 5304 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5305 | int status; |
| 5306 | |
| 5307 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5308 | return -EOPNOTSUPP; |
| 5309 | |
| 5310 | nfs_fattr_init(&fattr); |
| 5311 | |
| 5312 | ilabel.pi = 0; |
| 5313 | ilabel.lfs = 0; |
| 5314 | ilabel.label = (char *)buf; |
| 5315 | ilabel.len = buflen; |
| 5316 | |
| 5317 | cred = rpc_lookup_cred(); |
| 5318 | if (IS_ERR(cred)) |
| 5319 | return PTR_ERR(cred); |
| 5320 | |
| 5321 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5322 | if (IS_ERR(olabel)) { |
| 5323 | status = -PTR_ERR(olabel); |
| 5324 | goto out; |
| 5325 | } |
| 5326 | |
| 5327 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5328 | if (status == 0) |
| 5329 | nfs_setsecurity(inode, &fattr, olabel); |
| 5330 | |
| 5331 | nfs4_label_free(olabel); |
| 5332 | out: |
| 5333 | put_rpccred(cred); |
| 5334 | return status; |
| 5335 | } |
| 5336 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5337 | |
| 5338 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5339 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5340 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5341 | { |
| 5342 | __be32 verf[2]; |
| 5343 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5344 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5345 | /* An impossible timestamp guarantees this value |
| 5346 | * will never match a generated boot time. */ |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5347 | verf[0] = cpu_to_be32(U32_MAX); |
| 5348 | verf[1] = cpu_to_be32(U32_MAX); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5349 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5350 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Deepa Dinamani | 2f86e09 | 2016-10-01 16:46:26 -0700 | [diff] [blame] | 5351 | u64 ns = ktime_to_ns(nn->boot_time); |
| 5352 | |
| 5353 | verf[0] = cpu_to_be32(ns >> 32); |
| 5354 | verf[1] = cpu_to_be32(ns); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5355 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5356 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5357 | } |
| 5358 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5359 | static int |
| 5360 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5361 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5362 | size_t len; |
| 5363 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5364 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5365 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5366 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5367 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5368 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5369 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5370 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5371 | 1 + |
| 5372 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5373 | 1; |
| 5374 | rcu_read_unlock(); |
| 5375 | |
| 5376 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5377 | return -EINVAL; |
| 5378 | |
| 5379 | /* |
| 5380 | * Since this string is allocated at mount time, and held until the |
| 5381 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5382 | * about a memory-reclaim deadlock. |
| 5383 | */ |
| 5384 | str = kmalloc(len, GFP_KERNEL); |
| 5385 | if (!str) |
| 5386 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5387 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5388 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5389 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5390 | clp->cl_ipaddr, |
| 5391 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5392 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5393 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5394 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5395 | clp->cl_owner_id = str; |
| 5396 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5397 | } |
| 5398 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5399 | static int |
| 5400 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5401 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5402 | size_t len; |
| 5403 | char *str; |
| 5404 | |
| 5405 | len = 10 + 10 + 1 + 10 + 1 + |
| 5406 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5407 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5408 | |
| 5409 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5410 | return -EINVAL; |
| 5411 | |
| 5412 | /* |
| 5413 | * Since this string is allocated at mount time, and held until the |
| 5414 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5415 | * about a memory-reclaim deadlock. |
| 5416 | */ |
| 5417 | str = kmalloc(len, GFP_KERNEL); |
| 5418 | if (!str) |
| 5419 | return -ENOMEM; |
| 5420 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5421 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5422 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5423 | nfs4_client_id_uniquifier, |
| 5424 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5425 | clp->cl_owner_id = str; |
| 5426 | return 0; |
| 5427 | } |
| 5428 | |
| 5429 | static int |
| 5430 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5431 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5432 | size_t len; |
| 5433 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5434 | |
| 5435 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5436 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5437 | |
| 5438 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5439 | return nfs4_init_uniquifier_client_string(clp); |
| 5440 | |
| 5441 | len = 10 + 10 + 1 + 10 + 1 + |
| 5442 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5443 | |
| 5444 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5445 | return -EINVAL; |
| 5446 | |
| 5447 | /* |
| 5448 | * Since this string is allocated at mount time, and held until the |
| 5449 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5450 | * about a memory-reclaim deadlock. |
| 5451 | */ |
| 5452 | str = kmalloc(len, GFP_KERNEL); |
| 5453 | if (!str) |
| 5454 | return -ENOMEM; |
| 5455 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5456 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5457 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5458 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5459 | clp->cl_owner_id = str; |
| 5460 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5461 | } |
| 5462 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5463 | /* |
| 5464 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5465 | * services. Advertise one based on the address family of the |
| 5466 | * clientaddr. |
| 5467 | */ |
| 5468 | static unsigned int |
| 5469 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5470 | { |
| 5471 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5472 | return scnprintf(buf, len, "tcp6"); |
| 5473 | else |
| 5474 | return scnprintf(buf, len, "tcp"); |
| 5475 | } |
| 5476 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5477 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5478 | { |
| 5479 | struct nfs4_setclientid *sc = calldata; |
| 5480 | |
| 5481 | if (task->tk_status == 0) |
| 5482 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5483 | } |
| 5484 | |
| 5485 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5486 | .rpc_call_done = nfs4_setclientid_done, |
| 5487 | }; |
| 5488 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5489 | /** |
| 5490 | * nfs4_proc_setclientid - Negotiate client ID |
| 5491 | * @clp: state data structure |
| 5492 | * @program: RPC program for NFSv4 callback service |
| 5493 | * @port: IP port number for NFS4 callback service |
| 5494 | * @cred: RPC credential to use for this call |
| 5495 | * @res: where to place the result |
| 5496 | * |
| 5497 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5498 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5499 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5500 | unsigned short port, struct rpc_cred *cred, |
| 5501 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | { |
| 5503 | nfs4_verifier sc_verifier; |
| 5504 | struct nfs4_setclientid setclientid = { |
| 5505 | .sc_verifier = &sc_verifier, |
| 5506 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5507 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | }; |
| 5509 | struct rpc_message msg = { |
| 5510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5511 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5512 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5513 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5515 | struct rpc_task *task; |
| 5516 | struct rpc_task_setup task_setup_data = { |
| 5517 | .rpc_client = clp->cl_rpcclient, |
| 5518 | .rpc_message = &msg, |
| 5519 | .callback_ops = &nfs4_setclientid_ops, |
| 5520 | .callback_data = &setclientid, |
| 5521 | .flags = RPC_TASK_TIMEOUT, |
| 5522 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5523 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5525 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5526 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5527 | |
| 5528 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5529 | status = nfs4_init_uniform_client_string(clp); |
| 5530 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5531 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5532 | |
| 5533 | if (status) |
| 5534 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5535 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5536 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5537 | setclientid.sc_netid_len = |
| 5538 | nfs4_init_callback_netid(clp, |
| 5539 | setclientid.sc_netid, |
| 5540 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5541 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5542 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5544 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5545 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5546 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5547 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5548 | task = rpc_run_task(&task_setup_data); |
| 5549 | if (IS_ERR(task)) { |
| 5550 | status = PTR_ERR(task); |
| 5551 | goto out; |
| 5552 | } |
| 5553 | status = task->tk_status; |
| 5554 | if (setclientid.sc_cred) { |
| 5555 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5556 | put_rpccred(setclientid.sc_cred); |
| 5557 | } |
| 5558 | rpc_put_task(task); |
| 5559 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5560 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5561 | dprintk("NFS reply setclientid: %d\n", status); |
| 5562 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5565 | /** |
| 5566 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5567 | * @clp: state data structure |
| 5568 | * @res: result of a previous SETCLIENTID |
| 5569 | * @cred: RPC credential to use for this call |
| 5570 | * |
| 5571 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5572 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5573 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5574 | struct nfs4_setclientid_res *arg, |
| 5575 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | struct rpc_message msg = { |
| 5578 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5579 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5580 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5581 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 | int status; |
| 5583 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5584 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5585 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5586 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5587 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5588 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5589 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | return status; |
| 5591 | } |
| 5592 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5593 | struct nfs4_delegreturndata { |
| 5594 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5595 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5596 | struct nfs_fh fh; |
| 5597 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5598 | unsigned long timestamp; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5599 | struct { |
| 5600 | struct nfs4_layoutreturn_args arg; |
| 5601 | struct nfs4_layoutreturn_res res; |
| 5602 | u32 roc_barrier; |
| 5603 | bool roc; |
| 5604 | } lr; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5605 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5606 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5607 | struct inode *inode; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5608 | }; |
| 5609 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5610 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5611 | { |
| 5612 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5613 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5614 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5615 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5616 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5617 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5618 | |
| 5619 | /* Handle Layoutreturn errors */ |
| 5620 | if (data->args.lr_args && task->tk_status != 0) { |
| 5621 | switch(data->res.lr_ret) { |
| 5622 | default: |
| 5623 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
| 5624 | break; |
| 5625 | case 0: |
| 5626 | data->args.lr_args = NULL; |
| 5627 | data->res.lr_res = NULL; |
| 5628 | break; |
| 5629 | case -NFS4ERR_ADMIN_REVOKED: |
| 5630 | case -NFS4ERR_DELEG_REVOKED: |
| 5631 | case -NFS4ERR_EXPIRED: |
| 5632 | case -NFS4ERR_BAD_STATEID: |
| 5633 | case -NFS4ERR_OLD_STATEID: |
| 5634 | case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
| 5635 | case -NFS4ERR_WRONG_CRED: |
| 5636 | data->args.lr_args = NULL; |
| 5637 | data->res.lr_res = NULL; |
| 5638 | data->res.lr_ret = 0; |
| 5639 | rpc_restart_call_prepare(task); |
| 5640 | return; |
| 5641 | } |
| 5642 | } |
| 5643 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5644 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5645 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5646 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | 23ea44c | 2016-11-10 16:06:28 -0500 | [diff] [blame] | 5647 | break; |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5648 | case -NFS4ERR_ADMIN_REVOKED: |
| 5649 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5650 | case -NFS4ERR_EXPIRED: |
| 5651 | nfs4_free_revoked_stateid(data->res.server, |
| 5652 | data->args.stateid, |
| 5653 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5654 | case -NFS4ERR_BAD_STATEID: |
| 5655 | case -NFS4ERR_OLD_STATEID: |
| 5656 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5657 | task->tk_status = 0; |
| 5658 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5659 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5660 | if (nfs4_async_handle_error(task, data->res.server, |
| 5661 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5662 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5663 | return; |
| 5664 | } |
| 5665 | } |
| 5666 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | static void nfs4_delegreturn_release(void *calldata) |
| 5670 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5671 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5672 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5673 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5674 | if (inode) { |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5675 | if (data->lr.roc) |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5676 | pnfs_roc_release(&data->lr.arg, &data->lr.res, |
| 5677 | data->res.lr_ret); |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5678 | nfs_iput_and_deactive(inode); |
| 5679 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5680 | kfree(calldata); |
| 5681 | } |
| 5682 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5683 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5684 | { |
| 5685 | struct nfs4_delegreturndata *d_data; |
| 5686 | |
| 5687 | d_data = (struct nfs4_delegreturndata *)data; |
| 5688 | |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5689 | 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] | 5690 | return; |
| 5691 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5692 | nfs4_setup_sequence(d_data->res.server, |
| 5693 | &d_data->args.seq_args, |
| 5694 | &d_data->res.seq_res, |
| 5695 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5696 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5697 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5698 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5699 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5700 | .rpc_call_done = nfs4_delegreturn_done, |
| 5701 | .rpc_release = nfs4_delegreturn_release, |
| 5702 | }; |
| 5703 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5704 | 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] | 5705 | { |
| 5706 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5707 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5708 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5709 | struct rpc_message msg = { |
| 5710 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5711 | .rpc_cred = cred, |
| 5712 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5713 | struct rpc_task_setup task_setup_data = { |
| 5714 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5715 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5716 | .callback_ops = &nfs4_delegreturn_ops, |
| 5717 | .flags = RPC_TASK_ASYNC, |
| 5718 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5719 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5720 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5721 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5722 | if (data == NULL) |
| 5723 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5724 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5725 | |
| 5726 | nfs4_state_protect(server->nfs_client, |
| 5727 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5728 | &task_setup_data.rpc_client, &msg); |
| 5729 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5730 | data->args.fhandle = &data->fh; |
| 5731 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5732 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5733 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5734 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5735 | data->res.fattr = &data->fattr; |
| 5736 | data->res.server = server; |
Trond Myklebust | 586f1c3 | 2016-11-15 15:03:33 -0500 | [diff] [blame] | 5737 | data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5738 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5739 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5740 | data->rpc_status = 0; |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5741 | 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] | 5742 | data->inode = nfs_igrab_and_active(inode); |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5743 | if (data->inode) { |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5744 | if (data->lr.roc) { |
| 5745 | data->args.lr_args = &data->lr.arg; |
| 5746 | data->res.lr_res = &data->lr.res; |
| 5747 | } |
Trond Myklebust | 53e6fc8 | 2016-11-19 08:48:47 -0500 | [diff] [blame] | 5748 | } else if (data->lr.roc) { |
| 5749 | pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
| 5750 | data->lr.roc = false; |
Trond Myklebust | 1c5bd76d | 2016-11-16 01:11:25 -0500 | [diff] [blame] | 5751 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5752 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5753 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5754 | msg.rpc_argp = &data->args; |
| 5755 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5756 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5757 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5758 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5759 | if (!issync) |
| 5760 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5761 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5762 | if (status != 0) |
| 5763 | goto out; |
| 5764 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5765 | if (status == 0) |
| 5766 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5767 | else |
| 5768 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5769 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5770 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5771 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 | } |
| 5773 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5774 | 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] | 5775 | { |
| 5776 | struct nfs_server *server = NFS_SERVER(inode); |
| 5777 | struct nfs4_exception exception = { }; |
| 5778 | int err; |
| 5779 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5780 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5781 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | switch (err) { |
| 5783 | case -NFS4ERR_STALE_STATEID: |
| 5784 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | case 0: |
| 5786 | return 0; |
| 5787 | } |
| 5788 | err = nfs4_handle_exception(server, err, &exception); |
| 5789 | } while (exception.retry); |
| 5790 | return err; |
| 5791 | } |
| 5792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5793 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5794 | { |
| 5795 | struct inode *inode = state->inode; |
| 5796 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5797 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5798 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5800 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5802 | struct nfs_lockt_res res = { |
| 5803 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5804 | }; |
| 5805 | struct rpc_message msg = { |
| 5806 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5807 | .rpc_argp = &arg, |
| 5808 | .rpc_resp = &res, |
| 5809 | .rpc_cred = state->owner->so_cred, |
| 5810 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5811 | struct nfs4_lock_state *lsp; |
| 5812 | int status; |
| 5813 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5814 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5815 | status = nfs4_set_lock_state(state, request); |
| 5816 | if (status != 0) |
| 5817 | goto out; |
| 5818 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5819 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5820 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5821 | 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] | 5822 | switch (status) { |
| 5823 | case 0: |
| 5824 | request->fl_type = F_UNLCK; |
| 5825 | break; |
| 5826 | case -NFS4ERR_DENIED: |
| 5827 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5829 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5830 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5831 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | return status; |
| 5833 | } |
| 5834 | |
| 5835 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5836 | { |
| 5837 | struct nfs4_exception exception = { }; |
| 5838 | int err; |
| 5839 | |
| 5840 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5841 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5842 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5843 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | &exception); |
| 5845 | } while (exception.retry); |
| 5846 | return err; |
| 5847 | } |
| 5848 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5849 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5850 | struct nfs_locku_args arg; |
| 5851 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5852 | struct nfs4_lock_state *lsp; |
| 5853 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5854 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5855 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5856 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5857 | }; |
| 5858 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5859 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5860 | struct nfs_open_context *ctx, |
| 5861 | struct nfs4_lock_state *lsp, |
| 5862 | struct nfs_seqid *seqid) |
| 5863 | { |
| 5864 | struct nfs4_unlockdata *p; |
| 5865 | struct inode *inode = lsp->ls_state->inode; |
| 5866 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5867 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5868 | if (p == NULL) |
| 5869 | return NULL; |
| 5870 | p->arg.fh = NFS_FH(inode); |
| 5871 | p->arg.fl = &p->fl; |
| 5872 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5873 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5874 | p->lsp = lsp; |
| 5875 | atomic_inc(&lsp->ls_count); |
| 5876 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5877 | p->ctx = get_nfs_open_context(ctx); |
| 5878 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5879 | p->server = NFS_SERVER(inode); |
| 5880 | return p; |
| 5881 | } |
| 5882 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5883 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5884 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5885 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5886 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5887 | nfs4_put_lock_state(calldata->lsp); |
| 5888 | put_nfs_open_context(calldata->ctx); |
| 5889 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5892 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5893 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5894 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5895 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5896 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5897 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5898 | switch (task->tk_status) { |
| 5899 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5900 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5901 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5902 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5903 | &calldata->res.stateid)) |
| 5904 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5905 | case -NFS4ERR_ADMIN_REVOKED: |
| 5906 | case -NFS4ERR_EXPIRED: |
| 5907 | nfs4_free_revoked_stateid(calldata->server, |
| 5908 | &calldata->arg.stateid, |
| 5909 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5910 | case -NFS4ERR_BAD_STATEID: |
| 5911 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5912 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5913 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5914 | &calldata->lsp->ls_stateid)) |
| 5915 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5916 | break; |
| 5917 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5918 | if (nfs4_async_handle_error(task, calldata->server, |
| 5919 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5920 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5921 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5922 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5925 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5926 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5927 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5929 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5930 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5931 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5932 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5933 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5934 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5935 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5936 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5937 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5938 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5939 | &calldata->res.seq_res, |
| 5940 | task) != 0) |
| 5941 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5942 | return; |
| 5943 | out_no_action: |
| 5944 | task->tk_action = NULL; |
| 5945 | out_wait: |
| 5946 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5949 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5950 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5951 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5952 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5953 | }; |
| 5954 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5955 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5956 | struct nfs_open_context *ctx, |
| 5957 | struct nfs4_lock_state *lsp, |
| 5958 | struct nfs_seqid *seqid) |
| 5959 | { |
| 5960 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5961 | struct rpc_message msg = { |
| 5962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5963 | .rpc_cred = ctx->cred, |
| 5964 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5965 | struct rpc_task_setup task_setup_data = { |
| 5966 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5967 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5968 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5969 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5970 | .flags = RPC_TASK_ASYNC, |
| 5971 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5972 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5973 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5974 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5975 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5976 | /* Ensure this is an unlock - when canceling a lock, the |
| 5977 | * canceled lock is passed in, and it won't be an unlock. |
| 5978 | */ |
| 5979 | fl->fl_type = F_UNLCK; |
| 5980 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5981 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5982 | if (data == NULL) { |
| 5983 | nfs_free_seqid(seqid); |
| 5984 | return ERR_PTR(-ENOMEM); |
| 5985 | } |
| 5986 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5987 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5988 | msg.rpc_argp = &data->arg; |
| 5989 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5990 | task_setup_data.callback_data = data; |
| 5991 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5992 | } |
| 5993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5995 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5996 | struct inode *inode = state->inode; |
| 5997 | struct nfs4_state_owner *sp = state->owner; |
| 5998 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5999 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6000 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6001 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6002 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 6003 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6004 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6006 | status = nfs4_set_lock_state(state, request); |
| 6007 | /* Unlock _before_ we do the RPC call */ |
| 6008 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6009 | /* Exclude nfs_delegation_claim_locks() */ |
| 6010 | mutex_lock(&sp->so_delegreturn_mutex); |
| 6011 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6012 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6013 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6014 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6015 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6016 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6017 | } |
| 6018 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 6019 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6020 | if (status != 0) |
| 6021 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6022 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6023 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 6024 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 6025 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6026 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 6027 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6028 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6029 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6030 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6031 | 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] | 6032 | status = PTR_ERR(task); |
| 6033 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6034 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6035 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6036 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 6037 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 6038 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 6039 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 6040 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6041 | } |
| 6042 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6043 | struct nfs4_lockdata { |
| 6044 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 6045 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6046 | struct nfs4_lock_state *lsp; |
| 6047 | struct nfs_open_context *ctx; |
| 6048 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6049 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6050 | int rpc_status; |
| 6051 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6052 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6053 | }; |
| 6054 | |
| 6055 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6056 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 6057 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6058 | { |
| 6059 | struct nfs4_lockdata *p; |
| 6060 | struct inode *inode = lsp->ls_state->inode; |
| 6061 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6062 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6063 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6064 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6065 | if (p == NULL) |
| 6066 | return NULL; |
| 6067 | |
| 6068 | p->arg.fh = NFS_FH(inode); |
| 6069 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6070 | 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] | 6071 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6072 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 6073 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 6074 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 6075 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6076 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6077 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6078 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 6079 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6080 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6081 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6082 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6083 | atomic_inc(&lsp->ls_count); |
| 6084 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6085 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6086 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 6087 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6088 | out_free_seqid: |
| 6089 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6090 | out_free: |
| 6091 | kfree(p); |
| 6092 | return NULL; |
| 6093 | } |
| 6094 | |
| 6095 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 6096 | { |
| 6097 | struct nfs4_lockdata *data = calldata; |
| 6098 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6099 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6100 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6101 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6102 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6103 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 6104 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6105 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6106 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6107 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6108 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 6109 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6110 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6111 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6112 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6113 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6114 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6115 | &data->lsp->ls_stateid); |
| 6116 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6117 | if (!nfs4_valid_open_stateid(state)) { |
| 6118 | data->rpc_status = -EBADF; |
| 6119 | task->tk_action = NULL; |
| 6120 | goto out_release_open_seqid; |
| 6121 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6122 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6123 | if (nfs4_setup_sequence(data->server, |
| 6124 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6125 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6126 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6127 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6128 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6129 | nfs_release_seqid(data->arg.open_seqid); |
| 6130 | out_release_lock_seqid: |
| 6131 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6132 | out_wait: |
| 6133 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6134 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6135 | } |
| 6136 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6137 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6138 | { |
| 6139 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6140 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6141 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6142 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6143 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6144 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6145 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6146 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6147 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6148 | switch (task->tk_status) { |
| 6149 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6150 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6151 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6152 | if (data->arg.new_lock) { |
| 6153 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6154 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6155 | rpc_restart_call_prepare(task); |
| 6156 | break; |
| 6157 | } |
| 6158 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6159 | if (data->arg.new_lock_owner != 0) { |
| 6160 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6161 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6162 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6163 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6164 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6165 | break; |
| 6166 | case -NFS4ERR_BAD_STATEID: |
| 6167 | case -NFS4ERR_OLD_STATEID: |
| 6168 | case -NFS4ERR_STALE_STATEID: |
| 6169 | case -NFS4ERR_EXPIRED: |
| 6170 | if (data->arg.new_lock_owner != 0) { |
| 6171 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6172 | &lsp->ls_state->open_stateid)) |
| 6173 | rpc_restart_call_prepare(task); |
| 6174 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6175 | &lsp->ls_stateid)) |
| 6176 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6177 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6178 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | static void nfs4_lock_release(void *calldata) |
| 6182 | { |
| 6183 | struct nfs4_lockdata *data = calldata; |
| 6184 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6185 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6186 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6187 | if (data->cancelled != 0) { |
| 6188 | struct rpc_task *task; |
| 6189 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6190 | data->arg.lock_seqid); |
| 6191 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6192 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6193 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6194 | } else |
| 6195 | nfs_free_seqid(data->arg.lock_seqid); |
| 6196 | nfs4_put_lock_state(data->lsp); |
| 6197 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6198 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6199 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6200 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6204 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6205 | .rpc_call_done = nfs4_lock_done, |
| 6206 | .rpc_release = nfs4_lock_release, |
| 6207 | }; |
| 6208 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6209 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6210 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6211 | switch (error) { |
| 6212 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6213 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6214 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6215 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6216 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6217 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6218 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6219 | break; |
| 6220 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6221 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6222 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6223 | }; |
| 6224 | } |
| 6225 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6226 | 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] | 6227 | { |
| 6228 | struct nfs4_lockdata *data; |
| 6229 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6230 | struct rpc_message msg = { |
| 6231 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6232 | .rpc_cred = state->owner->so_cred, |
| 6233 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6234 | struct rpc_task_setup task_setup_data = { |
| 6235 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6236 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6237 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6238 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6239 | .flags = RPC_TASK_ASYNC, |
| 6240 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6241 | int ret; |
| 6242 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6243 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6244 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6245 | fl->fl_u.nfs4_fl.owner, |
| 6246 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6247 | if (data == NULL) |
| 6248 | return -ENOMEM; |
| 6249 | if (IS_SETLKW(cmd)) |
| 6250 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6251 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6252 | msg.rpc_argp = &data->arg; |
| 6253 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6254 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6255 | if (recovery_type > NFS_LOCK_NEW) { |
| 6256 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6257 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6258 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6259 | } else |
| 6260 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6261 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6262 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6263 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6264 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6265 | if (ret == 0) { |
| 6266 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6267 | if (ret) |
| 6268 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6269 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6270 | } else |
| 6271 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6272 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6273 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6274 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6275 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6279 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6280 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6281 | struct nfs4_exception exception = { |
| 6282 | .inode = state->inode, |
| 6283 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6284 | int err; |
| 6285 | |
| 6286 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6287 | /* Cache the lock if possible... */ |
| 6288 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6289 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6290 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6291 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6292 | break; |
| 6293 | nfs4_handle_exception(server, err, &exception); |
| 6294 | } while (exception.retry); |
| 6295 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | } |
| 6297 | |
| 6298 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6299 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6300 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6301 | struct nfs4_exception exception = { |
| 6302 | .inode = state->inode, |
| 6303 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6304 | int err; |
| 6305 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6306 | err = nfs4_set_lock_state(state, request); |
| 6307 | if (err != 0) |
| 6308 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6309 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6310 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6311 | return 0; |
| 6312 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6313 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6314 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6315 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6316 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6317 | switch (err) { |
| 6318 | default: |
| 6319 | goto out; |
| 6320 | case -NFS4ERR_GRACE: |
| 6321 | case -NFS4ERR_DELAY: |
| 6322 | nfs4_handle_exception(server, err, &exception); |
| 6323 | err = 0; |
| 6324 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6325 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6326 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6327 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6330 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6331 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6332 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6333 | struct nfs4_lock_state *lsp; |
| 6334 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6335 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6336 | status = nfs4_set_lock_state(state, request); |
| 6337 | if (status != 0) |
| 6338 | return status; |
| 6339 | lsp = request->fl_u.nfs4_fl.owner; |
| 6340 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6341 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6342 | return 0; |
| 6343 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6344 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6345 | } |
| 6346 | #endif |
| 6347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6349 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6350 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6351 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6352 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6353 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6354 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6355 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6356 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6357 | if (status < 0) |
| 6358 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6359 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6360 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6361 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6362 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6363 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6364 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6365 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6366 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6367 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6368 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6369 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6370 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6371 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6372 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6373 | out: |
| 6374 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | return status; |
| 6376 | } |
| 6377 | |
| 6378 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6379 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6380 | struct nfs4_exception exception = { |
| 6381 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6382 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6383 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | int err; |
| 6385 | |
| 6386 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6387 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6388 | if (err == -NFS4ERR_DENIED) |
| 6389 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6391 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6392 | } while (exception.retry); |
| 6393 | return err; |
| 6394 | } |
| 6395 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6396 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6397 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6398 | |
| 6399 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6400 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6401 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6402 | { |
| 6403 | int status = -ERESTARTSYS; |
| 6404 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6405 | |
| 6406 | while(!signalled()) { |
| 6407 | status = nfs4_proc_setlk(state, cmd, request); |
| 6408 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6409 | break; |
| 6410 | freezable_schedule_timeout_interruptible(timeout); |
| 6411 | timeout *= 2; |
| 6412 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6413 | status = -ERESTARTSYS; |
| 6414 | } |
| 6415 | return status; |
| 6416 | } |
| 6417 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6418 | #ifdef CONFIG_NFS_V4_1 |
| 6419 | struct nfs4_lock_waiter { |
| 6420 | struct task_struct *task; |
| 6421 | struct inode *inode; |
| 6422 | struct nfs_lowner *owner; |
| 6423 | bool notified; |
| 6424 | }; |
| 6425 | |
| 6426 | static int |
| 6427 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6428 | { |
| 6429 | int ret; |
| 6430 | struct cb_notify_lock_args *cbnl = key; |
| 6431 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6432 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6433 | *wowner = waiter->owner; |
| 6434 | |
| 6435 | /* Only wake if the callback was for the same owner */ |
| 6436 | if (lowner->clientid != wowner->clientid || |
| 6437 | lowner->id != wowner->id || |
| 6438 | lowner->s_dev != wowner->s_dev) |
| 6439 | return 0; |
| 6440 | |
| 6441 | /* Make sure it's for the right inode */ |
| 6442 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6443 | return 0; |
| 6444 | |
| 6445 | waiter->notified = true; |
| 6446 | |
| 6447 | /* override "private" so we can use default_wake_function */ |
| 6448 | wait->private = waiter->task; |
| 6449 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6450 | wait->private = waiter; |
| 6451 | return ret; |
| 6452 | } |
| 6453 | |
| 6454 | static int |
| 6455 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6456 | { |
| 6457 | int status = -ERESTARTSYS; |
| 6458 | unsigned long flags; |
| 6459 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6460 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6461 | struct nfs_client *clp = server->nfs_client; |
| 6462 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6463 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6464 | .id = lsp->ls_seqid.owner_id, |
| 6465 | .s_dev = server->s_dev }; |
| 6466 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6467 | .inode = state->inode, |
| 6468 | .owner = &owner, |
| 6469 | .notified = false }; |
| 6470 | wait_queue_t wait; |
| 6471 | |
| 6472 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6473 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6474 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6475 | |
| 6476 | init_wait(&wait); |
| 6477 | wait.private = &waiter; |
| 6478 | wait.func = nfs4_wake_lock_waiter; |
| 6479 | add_wait_queue(q, &wait); |
| 6480 | |
| 6481 | while(!signalled()) { |
| 6482 | status = nfs4_proc_setlk(state, cmd, request); |
| 6483 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6484 | break; |
| 6485 | |
| 6486 | status = -ERESTARTSYS; |
| 6487 | spin_lock_irqsave(&q->lock, flags); |
| 6488 | if (waiter.notified) { |
| 6489 | spin_unlock_irqrestore(&q->lock, flags); |
| 6490 | continue; |
| 6491 | } |
| 6492 | set_current_state(TASK_INTERRUPTIBLE); |
| 6493 | spin_unlock_irqrestore(&q->lock, flags); |
| 6494 | |
| 6495 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6496 | } |
| 6497 | |
| 6498 | finish_wait(q, &wait); |
| 6499 | return status; |
| 6500 | } |
| 6501 | #else /* !CONFIG_NFS_V4_1 */ |
| 6502 | static inline int |
| 6503 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6504 | { |
| 6505 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6506 | } |
| 6507 | #endif |
| 6508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6509 | static int |
| 6510 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6511 | { |
| 6512 | struct nfs_open_context *ctx; |
| 6513 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6514 | int status; |
| 6515 | |
| 6516 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6517 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6518 | state = ctx->state; |
| 6519 | |
| 6520 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6521 | return -EINVAL; |
| 6522 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6523 | if (IS_GETLK(cmd)) { |
| 6524 | if (state != NULL) |
| 6525 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6526 | return 0; |
| 6527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6528 | |
| 6529 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6530 | return -EINVAL; |
| 6531 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6532 | if (request->fl_type == F_UNLCK) { |
| 6533 | if (state != NULL) |
| 6534 | return nfs4_proc_unlck(state, cmd, request); |
| 6535 | return 0; |
| 6536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6537 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6538 | if (state == NULL) |
| 6539 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6540 | |
| 6541 | if ((request->fl_flags & FL_POSIX) && |
| 6542 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6543 | return -ENOLCK; |
| 6544 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6545 | /* |
| 6546 | * Don't rely on the VFS having checked the file open mode, |
| 6547 | * since it won't do this for flock() locks. |
| 6548 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6549 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6550 | case F_RDLCK: |
| 6551 | if (!(filp->f_mode & FMODE_READ)) |
| 6552 | return -EBADF; |
| 6553 | break; |
| 6554 | case F_WRLCK: |
| 6555 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6556 | return -EBADF; |
| 6557 | } |
| 6558 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6559 | status = nfs4_set_lock_state(state, request); |
| 6560 | if (status != 0) |
| 6561 | return status; |
| 6562 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6563 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6564 | } |
| 6565 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6566 | 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] | 6567 | { |
| 6568 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6569 | int err; |
| 6570 | |
| 6571 | err = nfs4_set_lock_state(state, fl); |
| 6572 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6573 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6574 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6575 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6576 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6577 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6578 | struct nfs_release_lockowner_data { |
| 6579 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6580 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6581 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6582 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6583 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6584 | }; |
| 6585 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6586 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6587 | { |
| 6588 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6589 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6590 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6591 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6592 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6593 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6597 | { |
| 6598 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6599 | struct nfs_server *server = data->server; |
| 6600 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6601 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6602 | |
| 6603 | switch (task->tk_status) { |
| 6604 | case 0: |
| 6605 | renew_lease(server, data->timestamp); |
| 6606 | break; |
| 6607 | case -NFS4ERR_STALE_CLIENTID: |
| 6608 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6609 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6610 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6611 | case -NFS4ERR_LEASE_MOVED: |
| 6612 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6613 | if (nfs4_async_handle_error(task, server, |
| 6614 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6615 | rpc_restart_call_prepare(task); |
| 6616 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6617 | } |
| 6618 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6619 | static void nfs4_release_lockowner_release(void *calldata) |
| 6620 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6621 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6622 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6623 | kfree(calldata); |
| 6624 | } |
| 6625 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6626 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6627 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6628 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6629 | .rpc_release = nfs4_release_lockowner_release, |
| 6630 | }; |
| 6631 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6632 | static void |
| 6633 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6634 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6635 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6636 | struct rpc_message msg = { |
| 6637 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6638 | }; |
| 6639 | |
| 6640 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6641 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6642 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6643 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6644 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6645 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6646 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6647 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6648 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6649 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6650 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6651 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6652 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6653 | msg.rpc_resp = &data->res; |
| 6654 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6655 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6656 | } |
| 6657 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6658 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6659 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6660 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6661 | struct dentry *unused, struct inode *inode, |
| 6662 | const char *key, const void *buf, |
| 6663 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6664 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6665 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6666 | } |
| 6667 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6668 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6669 | struct dentry *unused, struct inode *inode, |
| 6670 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6671 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6672 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6673 | } |
| 6674 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6675 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6676 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6677 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6678 | } |
| 6679 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6680 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6681 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6682 | static int nfs4_xattr_set_nfs4_label(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) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6686 | { |
| 6687 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6688 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6689 | |
| 6690 | return -EOPNOTSUPP; |
| 6691 | } |
| 6692 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6693 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6694 | struct dentry *unused, struct inode *inode, |
| 6695 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6696 | { |
| 6697 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6698 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6699 | return -EOPNOTSUPP; |
| 6700 | } |
| 6701 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6702 | static ssize_t |
| 6703 | 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] | 6704 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6705 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6706 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6707 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6708 | len = security_inode_listsecurity(inode, list, list_len); |
| 6709 | if (list_len && len > list_len) |
| 6710 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6711 | } |
| 6712 | return len; |
| 6713 | } |
| 6714 | |
| 6715 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6716 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6717 | .get = nfs4_xattr_get_nfs4_label, |
| 6718 | .set = nfs4_xattr_set_nfs4_label, |
| 6719 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6720 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6721 | #else |
| 6722 | |
| 6723 | static ssize_t |
| 6724 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6725 | { |
| 6726 | return 0; |
| 6727 | } |
| 6728 | |
| 6729 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6730 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6731 | /* |
| 6732 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6733 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6734 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6735 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6736 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6737 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6738 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6739 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6740 | return; |
| 6741 | |
| 6742 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6743 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6744 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6745 | fattr->nlink = 2; |
| 6746 | } |
| 6747 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6748 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6749 | const struct qstr *name, |
| 6750 | struct nfs4_fs_locations *fs_locations, |
| 6751 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6752 | { |
| 6753 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6754 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6755 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6756 | }; |
| 6757 | struct nfs4_fs_locations_arg args = { |
| 6758 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6759 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6760 | .page = page, |
| 6761 | .bitmask = bitmask, |
| 6762 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6763 | struct nfs4_fs_locations_res res = { |
| 6764 | .fs_locations = fs_locations, |
| 6765 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6766 | struct rpc_message msg = { |
| 6767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6768 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6769 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6770 | }; |
| 6771 | int status; |
| 6772 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6773 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6774 | |
| 6775 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6776 | * is not supported */ |
| 6777 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6778 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6779 | else |
| 6780 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6781 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6782 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6783 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6784 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6785 | 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] | 6786 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6787 | return status; |
| 6788 | } |
| 6789 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6790 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6791 | const struct qstr *name, |
| 6792 | struct nfs4_fs_locations *fs_locations, |
| 6793 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6794 | { |
| 6795 | struct nfs4_exception exception = { }; |
| 6796 | int err; |
| 6797 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6798 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6799 | fs_locations, page); |
| 6800 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6801 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6802 | &exception); |
| 6803 | } while (exception.retry); |
| 6804 | return err; |
| 6805 | } |
| 6806 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6807 | /* |
| 6808 | * This operation also signals the server that this client is |
| 6809 | * performing migration recovery. The server can stop returning |
| 6810 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6811 | * appended to this compound to identify the client ID which is |
| 6812 | * performing recovery. |
| 6813 | */ |
| 6814 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6815 | struct nfs4_fs_locations *locations, |
| 6816 | struct page *page, struct rpc_cred *cred) |
| 6817 | { |
| 6818 | struct nfs_server *server = NFS_SERVER(inode); |
| 6819 | struct rpc_clnt *clnt = server->client; |
| 6820 | u32 bitmask[2] = { |
| 6821 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6822 | }; |
| 6823 | struct nfs4_fs_locations_arg args = { |
| 6824 | .clientid = server->nfs_client->cl_clientid, |
| 6825 | .fh = NFS_FH(inode), |
| 6826 | .page = page, |
| 6827 | .bitmask = bitmask, |
| 6828 | .migration = 1, /* skip LOOKUP */ |
| 6829 | .renew = 1, /* append RENEW */ |
| 6830 | }; |
| 6831 | struct nfs4_fs_locations_res res = { |
| 6832 | .fs_locations = locations, |
| 6833 | .migration = 1, |
| 6834 | .renew = 1, |
| 6835 | }; |
| 6836 | struct rpc_message msg = { |
| 6837 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6838 | .rpc_argp = &args, |
| 6839 | .rpc_resp = &res, |
| 6840 | .rpc_cred = cred, |
| 6841 | }; |
| 6842 | unsigned long now = jiffies; |
| 6843 | int status; |
| 6844 | |
| 6845 | nfs_fattr_init(&locations->fattr); |
| 6846 | locations->server = server; |
| 6847 | locations->nlocations = 0; |
| 6848 | |
| 6849 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6850 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6851 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6852 | &args.seq_args, &res.seq_res); |
| 6853 | if (status) |
| 6854 | return status; |
| 6855 | |
| 6856 | renew_lease(server, now); |
| 6857 | return 0; |
| 6858 | } |
| 6859 | |
| 6860 | #ifdef CONFIG_NFS_V4_1 |
| 6861 | |
| 6862 | /* |
| 6863 | * This operation also signals the server that this client is |
| 6864 | * performing migration recovery. The server can stop asserting |
| 6865 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6866 | * performing this operation is identified in the SEQUENCE |
| 6867 | * operation in this compound. |
| 6868 | * |
| 6869 | * When the client supports GETATTR(fs_locations_info), it can |
| 6870 | * be plumbed in here. |
| 6871 | */ |
| 6872 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6873 | struct nfs4_fs_locations *locations, |
| 6874 | struct page *page, struct rpc_cred *cred) |
| 6875 | { |
| 6876 | struct nfs_server *server = NFS_SERVER(inode); |
| 6877 | struct rpc_clnt *clnt = server->client; |
| 6878 | u32 bitmask[2] = { |
| 6879 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6880 | }; |
| 6881 | struct nfs4_fs_locations_arg args = { |
| 6882 | .fh = NFS_FH(inode), |
| 6883 | .page = page, |
| 6884 | .bitmask = bitmask, |
| 6885 | .migration = 1, /* skip LOOKUP */ |
| 6886 | }; |
| 6887 | struct nfs4_fs_locations_res res = { |
| 6888 | .fs_locations = locations, |
| 6889 | .migration = 1, |
| 6890 | }; |
| 6891 | struct rpc_message msg = { |
| 6892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6893 | .rpc_argp = &args, |
| 6894 | .rpc_resp = &res, |
| 6895 | .rpc_cred = cred, |
| 6896 | }; |
| 6897 | int status; |
| 6898 | |
| 6899 | nfs_fattr_init(&locations->fattr); |
| 6900 | locations->server = server; |
| 6901 | locations->nlocations = 0; |
| 6902 | |
| 6903 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6904 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6905 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6906 | &args.seq_args, &res.seq_res); |
| 6907 | if (status == NFS4_OK && |
| 6908 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6909 | status = -NFS4ERR_LEASE_MOVED; |
| 6910 | return status; |
| 6911 | } |
| 6912 | |
| 6913 | #endif /* CONFIG_NFS_V4_1 */ |
| 6914 | |
| 6915 | /** |
| 6916 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6917 | * @inode: inode on FSID that is migrating |
| 6918 | * @locations: result of query |
| 6919 | * @page: buffer |
| 6920 | * @cred: credential to use for this operation |
| 6921 | * |
| 6922 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6923 | * operation failed, or a negative errno if a local error occurred. |
| 6924 | * |
| 6925 | * On success, "locations" is filled in, but if the server has |
| 6926 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6927 | * asserted. |
| 6928 | * |
| 6929 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6930 | * from this client that require migration recovery. |
| 6931 | */ |
| 6932 | int nfs4_proc_get_locations(struct inode *inode, |
| 6933 | struct nfs4_fs_locations *locations, |
| 6934 | struct page *page, struct rpc_cred *cred) |
| 6935 | { |
| 6936 | struct nfs_server *server = NFS_SERVER(inode); |
| 6937 | struct nfs_client *clp = server->nfs_client; |
| 6938 | const struct nfs4_mig_recovery_ops *ops = |
| 6939 | clp->cl_mvops->mig_recovery_ops; |
| 6940 | struct nfs4_exception exception = { }; |
| 6941 | int status; |
| 6942 | |
| 6943 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6944 | (unsigned long long)server->fsid.major, |
| 6945 | (unsigned long long)server->fsid.minor, |
| 6946 | clp->cl_hostname); |
| 6947 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6948 | |
| 6949 | do { |
| 6950 | status = ops->get_locations(inode, locations, page, cred); |
| 6951 | if (status != -NFS4ERR_DELAY) |
| 6952 | break; |
| 6953 | nfs4_handle_exception(server, status, &exception); |
| 6954 | } while (exception.retry); |
| 6955 | return status; |
| 6956 | } |
| 6957 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6958 | /* |
| 6959 | * This operation also signals the server that this client is |
| 6960 | * performing "lease moved" recovery. The server can stop |
| 6961 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6962 | * is appended to this compound to identify the client ID which is |
| 6963 | * performing recovery. |
| 6964 | */ |
| 6965 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6966 | { |
| 6967 | struct nfs_server *server = NFS_SERVER(inode); |
| 6968 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6969 | struct rpc_clnt *clnt = server->client; |
| 6970 | struct nfs4_fsid_present_arg args = { |
| 6971 | .fh = NFS_FH(inode), |
| 6972 | .clientid = clp->cl_clientid, |
| 6973 | .renew = 1, /* append RENEW */ |
| 6974 | }; |
| 6975 | struct nfs4_fsid_present_res res = { |
| 6976 | .renew = 1, |
| 6977 | }; |
| 6978 | struct rpc_message msg = { |
| 6979 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6980 | .rpc_argp = &args, |
| 6981 | .rpc_resp = &res, |
| 6982 | .rpc_cred = cred, |
| 6983 | }; |
| 6984 | unsigned long now = jiffies; |
| 6985 | int status; |
| 6986 | |
| 6987 | res.fh = nfs_alloc_fhandle(); |
| 6988 | if (res.fh == NULL) |
| 6989 | return -ENOMEM; |
| 6990 | |
| 6991 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6992 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6993 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6994 | &args.seq_args, &res.seq_res); |
| 6995 | nfs_free_fhandle(res.fh); |
| 6996 | if (status) |
| 6997 | return status; |
| 6998 | |
| 6999 | do_renew_lease(clp, now); |
| 7000 | return 0; |
| 7001 | } |
| 7002 | |
| 7003 | #ifdef CONFIG_NFS_V4_1 |
| 7004 | |
| 7005 | /* |
| 7006 | * This operation also signals the server that this client is |
| 7007 | * performing "lease moved" recovery. The server can stop asserting |
| 7008 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 7009 | * this operation is identified in the SEQUENCE operation in this |
| 7010 | * compound. |
| 7011 | */ |
| 7012 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7013 | { |
| 7014 | struct nfs_server *server = NFS_SERVER(inode); |
| 7015 | struct rpc_clnt *clnt = server->client; |
| 7016 | struct nfs4_fsid_present_arg args = { |
| 7017 | .fh = NFS_FH(inode), |
| 7018 | }; |
| 7019 | struct nfs4_fsid_present_res res = { |
| 7020 | }; |
| 7021 | struct rpc_message msg = { |
| 7022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 7023 | .rpc_argp = &args, |
| 7024 | .rpc_resp = &res, |
| 7025 | .rpc_cred = cred, |
| 7026 | }; |
| 7027 | int status; |
| 7028 | |
| 7029 | res.fh = nfs_alloc_fhandle(); |
| 7030 | if (res.fh == NULL) |
| 7031 | return -ENOMEM; |
| 7032 | |
| 7033 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 7034 | nfs4_set_sequence_privileged(&args.seq_args); |
| 7035 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 7036 | &args.seq_args, &res.seq_res); |
| 7037 | nfs_free_fhandle(res.fh); |
| 7038 | if (status == NFS4_OK && |
| 7039 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 7040 | status = -NFS4ERR_LEASE_MOVED; |
| 7041 | return status; |
| 7042 | } |
| 7043 | |
| 7044 | #endif /* CONFIG_NFS_V4_1 */ |
| 7045 | |
| 7046 | /** |
| 7047 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 7048 | * @inode: inode on FSID to check |
| 7049 | * @cred: credential to use for this operation |
| 7050 | * |
| 7051 | * Server indicates whether the FSID is present, moved, or not |
| 7052 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 7053 | * condition for this client ID. |
| 7054 | * |
| 7055 | * Returns NFS4_OK if the FSID is present on this server, |
| 7056 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 7057 | * NFS4ERR code if some error occurred on the server, or a |
| 7058 | * negative errno if a local failure occurred. |
| 7059 | */ |
| 7060 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 7061 | { |
| 7062 | struct nfs_server *server = NFS_SERVER(inode); |
| 7063 | struct nfs_client *clp = server->nfs_client; |
| 7064 | const struct nfs4_mig_recovery_ops *ops = |
| 7065 | clp->cl_mvops->mig_recovery_ops; |
| 7066 | struct nfs4_exception exception = { }; |
| 7067 | int status; |
| 7068 | |
| 7069 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 7070 | (unsigned long long)server->fsid.major, |
| 7071 | (unsigned long long)server->fsid.minor, |
| 7072 | clp->cl_hostname); |
| 7073 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 7074 | |
| 7075 | do { |
| 7076 | status = ops->fsid_present(inode, cred); |
| 7077 | if (status != -NFS4ERR_DELAY) |
| 7078 | break; |
| 7079 | nfs4_handle_exception(server, status, &exception); |
| 7080 | } while (exception.retry); |
| 7081 | return status; |
| 7082 | } |
| 7083 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7084 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7085 | * If 'use_integrity' is true and the state managment nfs_client |
| 7086 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 7087 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 7088 | * Considerations sections. Otherwise, just use the user cred with the |
| 7089 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 7090 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7091 | 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] | 7092 | { |
| 7093 | int status; |
| 7094 | struct nfs4_secinfo_arg args = { |
| 7095 | .dir_fh = NFS_FH(dir), |
| 7096 | .name = name, |
| 7097 | }; |
| 7098 | struct nfs4_secinfo_res res = { |
| 7099 | .flavors = flavors, |
| 7100 | }; |
| 7101 | struct rpc_message msg = { |
| 7102 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 7103 | .rpc_argp = &args, |
| 7104 | .rpc_resp = &res, |
| 7105 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7106 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7107 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7108 | |
| 7109 | if (use_integrity) { |
| 7110 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7111 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7112 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7113 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7114 | |
| 7115 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7116 | |
| 7117 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7118 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7119 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7120 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7121 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7122 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7123 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7124 | if (cred) |
| 7125 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7126 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7127 | return status; |
| 7128 | } |
| 7129 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7130 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7131 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7132 | { |
| 7133 | struct nfs4_exception exception = { }; |
| 7134 | int err; |
| 7135 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7136 | err = -NFS4ERR_WRONGSEC; |
| 7137 | |
| 7138 | /* try to use integrity protection with machine cred */ |
| 7139 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7140 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7141 | |
| 7142 | /* |
| 7143 | * if unable to use integrity protection, or SECINFO with |
| 7144 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7145 | * disallowed by spec, but exists in deployed servers) use |
| 7146 | * the current filesystem's rpc_client and the user cred. |
| 7147 | */ |
| 7148 | if (err == -NFS4ERR_WRONGSEC) |
| 7149 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7150 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7151 | trace_nfs4_secinfo(dir, name, err); |
| 7152 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7153 | &exception); |
| 7154 | } while (exception.retry); |
| 7155 | return err; |
| 7156 | } |
| 7157 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7158 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7159 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7160 | * Check the exchange flags returned by the server for invalid flags, having |
| 7161 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7162 | * DS flags set. |
| 7163 | */ |
| 7164 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7165 | { |
| 7166 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7167 | goto out_inval; |
| 7168 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7169 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7170 | goto out_inval; |
| 7171 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7172 | goto out_inval; |
| 7173 | return NFS_OK; |
| 7174 | out_inval: |
| 7175 | return -NFS4ERR_INVAL; |
| 7176 | } |
| 7177 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7178 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7179 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7180 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7181 | { |
| 7182 | if (a->server_scope_sz == b->server_scope_sz && |
| 7183 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7184 | return true; |
| 7185 | |
| 7186 | return false; |
| 7187 | } |
| 7188 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7189 | static void |
| 7190 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7191 | { |
| 7192 | } |
| 7193 | |
| 7194 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7195 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7196 | }; |
| 7197 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7198 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7199 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7200 | * |
| 7201 | * The 4.1 client currently uses the same TCP connection for the |
| 7202 | * fore and backchannel. |
| 7203 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7204 | static |
| 7205 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7206 | struct rpc_xprt *xprt, |
| 7207 | struct nfs_client *clp, |
| 7208 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7209 | { |
| 7210 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7211 | struct nfs41_bind_conn_to_session_args args = { |
| 7212 | .client = clp, |
| 7213 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7214 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7215 | struct nfs41_bind_conn_to_session_res res; |
| 7216 | struct rpc_message msg = { |
| 7217 | .rpc_proc = |
| 7218 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7219 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7220 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7221 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7222 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7223 | struct rpc_task_setup task_setup_data = { |
| 7224 | .rpc_client = clnt, |
| 7225 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7226 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7227 | .rpc_message = &msg, |
| 7228 | .flags = RPC_TASK_TIMEOUT, |
| 7229 | }; |
| 7230 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7231 | |
| 7232 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7233 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7234 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7235 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7236 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7237 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7238 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7239 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7240 | args.dir = NFS4_CDFC4_FORE; |
| 7241 | |
| 7242 | task = rpc_run_task(&task_setup_data); |
| 7243 | if (!IS_ERR(task)) { |
| 7244 | status = task->tk_status; |
| 7245 | rpc_put_task(task); |
| 7246 | } else |
| 7247 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7248 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7249 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7250 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7251 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7252 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7253 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7254 | goto out; |
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 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7257 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7258 | __func__); |
| 7259 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7260 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7261 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7262 | 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] | 7263 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7264 | __func__); |
| 7265 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7266 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7267 | } |
| 7268 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7269 | out: |
| 7270 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7271 | return status; |
| 7272 | } |
| 7273 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7274 | struct rpc_bind_conn_calldata { |
| 7275 | struct nfs_client *clp; |
| 7276 | struct rpc_cred *cred; |
| 7277 | }; |
| 7278 | |
| 7279 | static int |
| 7280 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7281 | struct rpc_xprt *xprt, |
| 7282 | void *calldata) |
| 7283 | { |
| 7284 | struct rpc_bind_conn_calldata *p = calldata; |
| 7285 | |
| 7286 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7287 | } |
| 7288 | |
| 7289 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7290 | { |
| 7291 | struct rpc_bind_conn_calldata data = { |
| 7292 | .clp = clp, |
| 7293 | .cred = cred, |
| 7294 | }; |
| 7295 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7296 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7297 | } |
| 7298 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7299 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7300 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7301 | * 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] | 7302 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7303 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7304 | .how = SP4_MACH_CRED, |
| 7305 | .enforce.u.words = { |
| 7306 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7307 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7308 | 1 << (OP_CREATE_SESSION - 32) | |
| 7309 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7310 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7311 | }, |
| 7312 | .allow.u.words = { |
| 7313 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7314 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7315 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7316 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7317 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7318 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7319 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7320 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7321 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7322 | 1 << (OP_FREE_STATEID - 32) | |
| 7323 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7324 | } |
| 7325 | }; |
| 7326 | |
| 7327 | /* |
| 7328 | * Select the state protection mode for client `clp' given the server results |
| 7329 | * from exchange_id in `sp'. |
| 7330 | * |
| 7331 | * Returns 0 on success, negative errno otherwise. |
| 7332 | */ |
| 7333 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7334 | struct nfs41_state_protection *sp) |
| 7335 | { |
| 7336 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7337 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7338 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7339 | 1 << (OP_CREATE_SESSION - 32) | |
| 7340 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7341 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7342 | }; |
| 7343 | unsigned int i; |
| 7344 | |
| 7345 | if (sp->how == SP4_MACH_CRED) { |
| 7346 | /* Print state protect result */ |
| 7347 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7348 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7349 | if (test_bit(i, sp->enforce.u.longs)) |
| 7350 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7351 | if (test_bit(i, sp->allow.u.longs)) |
| 7352 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7353 | } |
| 7354 | |
| 7355 | /* make sure nothing is on enforce list that isn't supported */ |
| 7356 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7357 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7358 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7359 | return -EINVAL; |
| 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | /* |
| 7364 | * Minimal mode - state operations are allowed to use machine |
| 7365 | * credential. Note this already happens by default, so the |
| 7366 | * client doesn't have to do anything more than the negotiation. |
| 7367 | * |
| 7368 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7369 | * we're already using the machine cred for exchange_id |
| 7370 | * and will never use a different cred. |
| 7371 | */ |
| 7372 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7373 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7374 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7375 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7376 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7377 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7378 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7379 | } else { |
| 7380 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7381 | return -EINVAL; |
| 7382 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7383 | |
| 7384 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7385 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7386 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7387 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7388 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7389 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7390 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7391 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7392 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7393 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7394 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7395 | &clp->cl_sp4_flags); |
| 7396 | } |
| 7397 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7398 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7399 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7400 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7401 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7402 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7403 | |
| 7404 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7405 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7406 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7407 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7408 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7409 | |
| 7410 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7411 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7412 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7413 | } |
| 7414 | |
| 7415 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7416 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7417 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7418 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | return 0; |
| 7422 | } |
| 7423 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7424 | struct nfs41_exchange_id_data { |
| 7425 | struct nfs41_exchange_id_res res; |
| 7426 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7427 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7428 | int rpc_status; |
| 7429 | }; |
| 7430 | |
| 7431 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7432 | { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7433 | struct nfs41_exchange_id_data *cdata = |
| 7434 | (struct nfs41_exchange_id_data *)data; |
| 7435 | struct nfs_client *clp = cdata->args.client; |
| 7436 | int status = task->tk_status; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7437 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7438 | trace_nfs4_exchange_id(clp, status); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7439 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7440 | if (status == 0) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7441 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7442 | |
| 7443 | if (cdata->xprt && status == 0) { |
| 7444 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7445 | cdata->xprt); |
| 7446 | goto out; |
| 7447 | } |
| 7448 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7449 | if (status == 0) |
| 7450 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7451 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7452 | if (status == 0) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7453 | clp->cl_clientid = cdata->res.clientid; |
| 7454 | clp->cl_exchange_flags = cdata->res.flags; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7455 | /* Client ID is not confirmed */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7456 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7457 | clear_bit(NFS4_SESSION_ESTABLISHED, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7458 | &clp->cl_session->session_state); |
| 7459 | clp->cl_seqid = cdata->res.seqid; |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7460 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 7461 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7462 | kfree(clp->cl_serverowner); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7463 | clp->cl_serverowner = cdata->res.server_owner; |
| 7464 | cdata->res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7465 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7466 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7467 | kfree(clp->cl_implid); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7468 | clp->cl_implid = cdata->res.impl_id; |
| 7469 | cdata->res.impl_id = NULL; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7470 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7471 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7472 | !nfs41_same_server_scope(clp->cl_serverscope, |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7473 | cdata->res.server_scope)) { |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7474 | dprintk("%s: server_scope mismatch detected\n", |
| 7475 | __func__); |
| 7476 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7477 | kfree(clp->cl_serverscope); |
| 7478 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7479 | } |
| 7480 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7481 | if (clp->cl_serverscope == NULL) { |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7482 | clp->cl_serverscope = cdata->res.server_scope; |
| 7483 | cdata->res.server_scope = NULL; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7484 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7485 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7486 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7487 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7488 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7489 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7490 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7491 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7492 | } |
| 7493 | |
| 7494 | static void nfs4_exchange_id_release(void *data) |
| 7495 | { |
| 7496 | struct nfs41_exchange_id_data *cdata = |
| 7497 | (struct nfs41_exchange_id_data *)data; |
| 7498 | |
| 7499 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7500 | if (cdata->xprt) { |
| 7501 | xprt_put(cdata->xprt); |
| 7502 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7503 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7504 | kfree(cdata->res.impl_id); |
| 7505 | kfree(cdata->res.server_scope); |
| 7506 | kfree(cdata->res.server_owner); |
| 7507 | kfree(cdata); |
| 7508 | } |
| 7509 | |
| 7510 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7511 | .rpc_call_done = nfs4_exchange_id_done, |
| 7512 | .rpc_release = nfs4_exchange_id_release, |
| 7513 | }; |
| 7514 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7515 | /* |
| 7516 | * _nfs4_proc_exchange_id() |
| 7517 | * |
| 7518 | * Wrapper for EXCHANGE_ID operation. |
| 7519 | */ |
| 7520 | 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] | 7521 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7522 | { |
| 7523 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7524 | struct rpc_message msg = { |
| 7525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7526 | .rpc_cred = cred, |
| 7527 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7528 | struct rpc_task_setup task_setup_data = { |
| 7529 | .rpc_client = clp->cl_rpcclient, |
| 7530 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7531 | .rpc_message = &msg, |
| 7532 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7533 | }; |
| 7534 | struct nfs41_exchange_id_data *calldata; |
| 7535 | struct rpc_task *task; |
| 7536 | int status = -EIO; |
| 7537 | |
| 7538 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7539 | goto out; |
| 7540 | |
| 7541 | status = -ENOMEM; |
| 7542 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7543 | if (!calldata) |
| 7544 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7545 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7546 | if (!xprt) |
| 7547 | nfs4_init_boot_verifier(clp, &verifier); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7548 | |
| 7549 | status = nfs4_init_uniform_client_string(clp); |
| 7550 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7551 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7552 | |
| 7553 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
| 7554 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 7555 | clp->cl_owner_id); |
| 7556 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7557 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7558 | GFP_NOFS); |
| 7559 | status = -ENOMEM; |
| 7560 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7561 | goto out_calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7562 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7563 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7564 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7565 | if (unlikely(calldata->res.server_scope == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7566 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7567 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7568 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7569 | if (unlikely(calldata->res.impl_id == NULL)) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7570 | goto out_server_scope; |
| 7571 | |
| 7572 | switch (sp4_how) { |
| 7573 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7574 | calldata->args.state_protect.how = SP4_NONE; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7575 | break; |
| 7576 | |
| 7577 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7578 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7579 | break; |
| 7580 | |
| 7581 | default: |
| 7582 | /* unsupported! */ |
| 7583 | WARN_ON_ONCE(1); |
| 7584 | status = -EINVAL; |
| 7585 | goto out_impl_id; |
| 7586 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7587 | if (xprt) { |
| 7588 | calldata->xprt = xprt; |
| 7589 | task_setup_data.rpc_xprt = xprt; |
| 7590 | task_setup_data.flags = |
| 7591 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7592 | calldata->args.verifier = &clp->cl_confirm; |
| 7593 | } else { |
| 7594 | calldata->args.verifier = &verifier; |
| 7595 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7596 | calldata->args.client = clp; |
| 7597 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7598 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7599 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7600 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7601 | #else |
| 7602 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7603 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7604 | #endif |
| 7605 | msg.rpc_argp = &calldata->args; |
| 7606 | msg.rpc_resp = &calldata->res; |
| 7607 | task_setup_data.callback_data = calldata; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7608 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7609 | task = rpc_run_task(&task_setup_data); |
| 7610 | if (IS_ERR(task)) { |
| 7611 | status = PTR_ERR(task); |
| 7612 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7613 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7614 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7615 | if (!xprt) { |
| 7616 | status = rpc_wait_for_completion_task(task); |
| 7617 | if (!status) |
| 7618 | status = calldata->rpc_status; |
| 7619 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7620 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7621 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7622 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7623 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7624 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7625 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7626 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7627 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7628 | clp->cl_implid->date.seconds, |
| 7629 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7630 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7631 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7632 | |
| 7633 | out_impl_id: |
| 7634 | kfree(calldata->res.impl_id); |
| 7635 | out_server_scope: |
| 7636 | kfree(calldata->res.server_scope); |
| 7637 | out_server_owner: |
| 7638 | kfree(calldata->res.server_owner); |
| 7639 | out_calldata: |
| 7640 | kfree(calldata); |
| 7641 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7642 | } |
| 7643 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7644 | /* |
| 7645 | * nfs4_proc_exchange_id() |
| 7646 | * |
| 7647 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7648 | * |
| 7649 | * Since the clientid has expired, all compounds using sessions |
| 7650 | * associated with the stale clientid will be returning |
| 7651 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7652 | * be in some phase of session reset. |
| 7653 | * |
| 7654 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7655 | */ |
| 7656 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7657 | { |
| 7658 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7659 | int status; |
| 7660 | |
| 7661 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7662 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7663 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7664 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7665 | if (!status) |
| 7666 | return 0; |
| 7667 | } |
| 7668 | |
| 7669 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7670 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7671 | } |
| 7672 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7673 | /** |
| 7674 | * nfs4_test_session_trunk |
| 7675 | * |
| 7676 | * This is an add_xprt_test() test function called from |
| 7677 | * rpc_clnt_setup_test_and_add_xprt. |
| 7678 | * |
| 7679 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7680 | * and is dereferrenced in nfs4_exchange_id_release |
| 7681 | * |
| 7682 | * Upon success, add the new transport to the rpc_clnt |
| 7683 | * |
| 7684 | * @clnt: struct rpc_clnt to get new transport |
| 7685 | * @xprt: the rpc_xprt to test |
| 7686 | * @data: call data for _nfs4_proc_exchange_id. |
| 7687 | */ |
| 7688 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7689 | void *data) |
| 7690 | { |
| 7691 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7692 | u32 sp4_how; |
| 7693 | |
| 7694 | dprintk("--> %s try %s\n", __func__, |
| 7695 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7696 | |
| 7697 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7698 | |
| 7699 | /* Test connection for session trunking. Async exchange_id call */ |
| 7700 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7701 | } |
| 7702 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7703 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7704 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7705 | struct rpc_cred *cred) |
| 7706 | { |
| 7707 | struct rpc_message msg = { |
| 7708 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7709 | .rpc_argp = clp, |
| 7710 | .rpc_cred = cred, |
| 7711 | }; |
| 7712 | int status; |
| 7713 | |
| 7714 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7715 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7716 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7717 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7718 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7719 | return status; |
| 7720 | } |
| 7721 | |
| 7722 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7723 | struct rpc_cred *cred) |
| 7724 | { |
| 7725 | unsigned int loop; |
| 7726 | int ret; |
| 7727 | |
| 7728 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7729 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7730 | switch (ret) { |
| 7731 | case -NFS4ERR_DELAY: |
| 7732 | case -NFS4ERR_CLIENTID_BUSY: |
| 7733 | ssleep(1); |
| 7734 | break; |
| 7735 | default: |
| 7736 | return ret; |
| 7737 | } |
| 7738 | } |
| 7739 | return 0; |
| 7740 | } |
| 7741 | |
| 7742 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7743 | { |
| 7744 | struct rpc_cred *cred; |
| 7745 | int ret = 0; |
| 7746 | |
| 7747 | if (clp->cl_mvops->minor_version < 1) |
| 7748 | goto out; |
| 7749 | if (clp->cl_exchange_flags == 0) |
| 7750 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7751 | if (clp->cl_preserve_clid) |
| 7752 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7753 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7754 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7755 | if (cred) |
| 7756 | put_rpccred(cred); |
| 7757 | switch (ret) { |
| 7758 | case 0: |
| 7759 | case -NFS4ERR_STALE_CLIENTID: |
| 7760 | clp->cl_exchange_flags = 0; |
| 7761 | } |
| 7762 | out: |
| 7763 | return ret; |
| 7764 | } |
| 7765 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7766 | struct nfs4_get_lease_time_data { |
| 7767 | struct nfs4_get_lease_time_args *args; |
| 7768 | struct nfs4_get_lease_time_res *res; |
| 7769 | struct nfs_client *clp; |
| 7770 | }; |
| 7771 | |
| 7772 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7773 | void *calldata) |
| 7774 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7775 | struct nfs4_get_lease_time_data *data = |
| 7776 | (struct nfs4_get_lease_time_data *)calldata; |
| 7777 | |
| 7778 | dprintk("--> %s\n", __func__); |
| 7779 | /* just setup sequence, do not trigger session recovery |
| 7780 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7781 | nfs41_setup_sequence(data->clp->cl_session, |
| 7782 | &data->args->la_seq_args, |
| 7783 | &data->res->lr_seq_res, |
| 7784 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7785 | dprintk("<-- %s\n", __func__); |
| 7786 | } |
| 7787 | |
| 7788 | /* |
| 7789 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7790 | * from sequence operation or clientid errors. |
| 7791 | */ |
| 7792 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7793 | { |
| 7794 | struct nfs4_get_lease_time_data *data = |
| 7795 | (struct nfs4_get_lease_time_data *)calldata; |
| 7796 | |
| 7797 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7798 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7799 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7800 | switch (task->tk_status) { |
| 7801 | case -NFS4ERR_DELAY: |
| 7802 | case -NFS4ERR_GRACE: |
| 7803 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7804 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7805 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7806 | /* fall through */ |
| 7807 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7808 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7809 | return; |
| 7810 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7811 | dprintk("<-- %s\n", __func__); |
| 7812 | } |
| 7813 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7814 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7815 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7816 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7817 | }; |
| 7818 | |
| 7819 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7820 | { |
| 7821 | struct rpc_task *task; |
| 7822 | struct nfs4_get_lease_time_args args; |
| 7823 | struct nfs4_get_lease_time_res res = { |
| 7824 | .lr_fsinfo = fsinfo, |
| 7825 | }; |
| 7826 | struct nfs4_get_lease_time_data data = { |
| 7827 | .args = &args, |
| 7828 | .res = &res, |
| 7829 | .clp = clp, |
| 7830 | }; |
| 7831 | struct rpc_message msg = { |
| 7832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7833 | .rpc_argp = &args, |
| 7834 | .rpc_resp = &res, |
| 7835 | }; |
| 7836 | struct rpc_task_setup task_setup = { |
| 7837 | .rpc_client = clp->cl_rpcclient, |
| 7838 | .rpc_message = &msg, |
| 7839 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7840 | .callback_data = &data, |
| 7841 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7842 | }; |
| 7843 | int status; |
| 7844 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7845 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7846 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7847 | dprintk("--> %s\n", __func__); |
| 7848 | task = rpc_run_task(&task_setup); |
| 7849 | |
| 7850 | if (IS_ERR(task)) |
| 7851 | status = PTR_ERR(task); |
| 7852 | else { |
| 7853 | status = task->tk_status; |
| 7854 | rpc_put_task(task); |
| 7855 | } |
| 7856 | dprintk("<-- %s return %d\n", __func__, status); |
| 7857 | |
| 7858 | return status; |
| 7859 | } |
| 7860 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7861 | /* |
| 7862 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7863 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7864 | * use them. |
| 7865 | * |
| 7866 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7867 | * always set csa_cachethis to FALSE because the current implementation |
| 7868 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7869 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7870 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7871 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7872 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7873 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7874 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7875 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7876 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7877 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7878 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7879 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7880 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7881 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7882 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7883 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7884 | |
| 7885 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7886 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7887 | __func__, |
| 7888 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7889 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7890 | |
| 7891 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7892 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7893 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7894 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7895 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7896 | 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] | 7897 | |
| 7898 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7899 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7900 | __func__, |
| 7901 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7902 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7903 | args->bc_attrs.max_reqs); |
| 7904 | } |
| 7905 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7906 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7907 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7908 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7909 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7910 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7911 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7912 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7913 | return -EINVAL; |
| 7914 | /* |
| 7915 | * Our requested max_ops is the minimum we need; we're not |
| 7916 | * prepared to break up compounds into smaller pieces than that. |
| 7917 | * So, no point even trying to continue if the server won't |
| 7918 | * cooperate: |
| 7919 | */ |
| 7920 | if (rcvd->max_ops < sent->max_ops) |
| 7921 | return -EINVAL; |
| 7922 | if (rcvd->max_reqs == 0) |
| 7923 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7924 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7925 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7926 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7927 | } |
| 7928 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7929 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7930 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7931 | { |
| 7932 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7933 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7934 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7935 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7936 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7937 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7938 | return -EINVAL; |
| 7939 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7940 | return -EINVAL; |
| 7941 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7942 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7943 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7944 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7945 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7946 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7947 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7948 | return 0; |
| 7949 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7950 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7951 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7952 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7953 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7954 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7955 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7956 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7957 | if (ret) |
| 7958 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7959 | return nfs4_verify_back_channel_attrs(args, res); |
| 7960 | } |
| 7961 | |
| 7962 | static void nfs4_update_session(struct nfs4_session *session, |
| 7963 | struct nfs41_create_session_res *res) |
| 7964 | { |
| 7965 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7966 | /* Mark client id and session as being confirmed */ |
| 7967 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7968 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7969 | session->flags = res->flags; |
| 7970 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7971 | if (res->flags & SESSION4_BACK_CHAN) |
| 7972 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7973 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7974 | } |
| 7975 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7976 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7977 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7978 | { |
| 7979 | struct nfs4_session *session = clp->cl_session; |
| 7980 | struct nfs41_create_session_args args = { |
| 7981 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7982 | .clientid = clp->cl_clientid, |
| 7983 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7984 | .cb_program = NFS4_CALLBACK, |
| 7985 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7986 | struct nfs41_create_session_res res; |
| 7987 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7988 | struct rpc_message msg = { |
| 7989 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7990 | .rpc_argp = &args, |
| 7991 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7992 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7993 | }; |
| 7994 | int status; |
| 7995 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7996 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7997 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7998 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7999 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8000 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8001 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 8002 | switch (status) { |
| 8003 | case -NFS4ERR_STALE_CLIENTID: |
| 8004 | case -NFS4ERR_DELAY: |
| 8005 | case -ETIMEDOUT: |
| 8006 | case -EACCES: |
| 8007 | case -EAGAIN: |
| 8008 | goto out; |
| 8009 | }; |
| 8010 | |
| 8011 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 8012 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 8013 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8014 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8015 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8016 | if (status) |
| 8017 | goto out; |
| 8018 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8019 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 8020 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8021 | return status; |
| 8022 | } |
| 8023 | |
| 8024 | /* |
| 8025 | * Issues a CREATE_SESSION operation to the server. |
| 8026 | * It is the responsibility of the caller to verify the session is |
| 8027 | * expired before calling this routine. |
| 8028 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8029 | 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] | 8030 | { |
| 8031 | int status; |
| 8032 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8033 | struct nfs4_session *session = clp->cl_session; |
| 8034 | |
| 8035 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 8036 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8037 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8038 | if (status) |
| 8039 | goto out; |
| 8040 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 8041 | /* Init or reset the session slot tables */ |
| 8042 | status = nfs4_setup_session_slot_tables(session); |
| 8043 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8044 | if (status) |
| 8045 | goto out; |
| 8046 | |
| 8047 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 8048 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 8049 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 8050 | out: |
| 8051 | dprintk("<-- %s\n", __func__); |
| 8052 | return status; |
| 8053 | } |
| 8054 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8055 | /* |
| 8056 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 8057 | * The caller must serialize access to this routine. |
| 8058 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8059 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 8060 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8061 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 8062 | struct rpc_message msg = { |
| 8063 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 8064 | .rpc_argp = session, |
| 8065 | .rpc_cred = cred, |
| 8066 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8067 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8068 | |
| 8069 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 8070 | |
| 8071 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 8072 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 8073 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8074 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 8075 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8076 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8077 | |
| 8078 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 8079 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 8080 | "Session has been destroyed regardless...\n", status); |
| 8081 | |
| 8082 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 8083 | return status; |
| 8084 | } |
| 8085 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 8086 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8087 | * Renew the cl_session lease. |
| 8088 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8089 | struct nfs4_sequence_data { |
| 8090 | struct nfs_client *clp; |
| 8091 | struct nfs4_sequence_args args; |
| 8092 | struct nfs4_sequence_res res; |
| 8093 | }; |
| 8094 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8095 | static void nfs41_sequence_release(void *data) |
| 8096 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8097 | struct nfs4_sequence_data *calldata = data; |
| 8098 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8099 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8100 | if (atomic_read(&clp->cl_count) > 1) |
| 8101 | nfs4_schedule_state_renewal(clp); |
| 8102 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8103 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8104 | } |
| 8105 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8106 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8107 | { |
| 8108 | switch(task->tk_status) { |
| 8109 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8110 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8111 | return -EAGAIN; |
| 8112 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8113 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8114 | } |
| 8115 | return 0; |
| 8116 | } |
| 8117 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8118 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8119 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8120 | struct nfs4_sequence_data *calldata = data; |
| 8121 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8122 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8123 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8124 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8125 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8126 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8127 | if (task->tk_status < 0) { |
| 8128 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8129 | if (atomic_read(&clp->cl_count) == 1) |
| 8130 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8131 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8132 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8133 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8134 | return; |
| 8135 | } |
| 8136 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8137 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8138 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8139 | dprintk("<-- %s\n", __func__); |
| 8140 | } |
| 8141 | |
| 8142 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8143 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8144 | struct nfs4_sequence_data *calldata = data; |
| 8145 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8146 | struct nfs4_sequence_args *args; |
| 8147 | struct nfs4_sequence_res *res; |
| 8148 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8149 | args = task->tk_msg.rpc_argp; |
| 8150 | res = task->tk_msg.rpc_resp; |
| 8151 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8152 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8153 | } |
| 8154 | |
| 8155 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8156 | .rpc_call_done = nfs41_sequence_call_done, |
| 8157 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8158 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8159 | }; |
| 8160 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8161 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8162 | struct rpc_cred *cred, |
| 8163 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8164 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8165 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8166 | struct rpc_message msg = { |
| 8167 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8168 | .rpc_cred = cred, |
| 8169 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8170 | struct rpc_task_setup task_setup_data = { |
| 8171 | .rpc_client = clp->cl_rpcclient, |
| 8172 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8173 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8174 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8175 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8176 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8177 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8178 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8179 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8180 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8181 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8182 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8183 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8184 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8185 | if (is_privileged) |
| 8186 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8187 | msg.rpc_argp = &calldata->args; |
| 8188 | msg.rpc_resp = &calldata->res; |
| 8189 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8190 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8191 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8192 | return rpc_run_task(&task_setup_data); |
| 8193 | } |
| 8194 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8195 | 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] | 8196 | { |
| 8197 | struct rpc_task *task; |
| 8198 | int ret = 0; |
| 8199 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8200 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8201 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8202 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8203 | if (IS_ERR(task)) |
| 8204 | ret = PTR_ERR(task); |
| 8205 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8206 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8207 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8208 | return ret; |
| 8209 | } |
| 8210 | |
| 8211 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8212 | { |
| 8213 | struct rpc_task *task; |
| 8214 | int ret; |
| 8215 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8216 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8217 | if (IS_ERR(task)) { |
| 8218 | ret = PTR_ERR(task); |
| 8219 | goto out; |
| 8220 | } |
| 8221 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8222 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8223 | ret = task->tk_status; |
| 8224 | rpc_put_task(task); |
| 8225 | out: |
| 8226 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8227 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8228 | } |
| 8229 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8230 | struct nfs4_reclaim_complete_data { |
| 8231 | struct nfs_client *clp; |
| 8232 | struct nfs41_reclaim_complete_args arg; |
| 8233 | struct nfs41_reclaim_complete_res res; |
| 8234 | }; |
| 8235 | |
| 8236 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8237 | { |
| 8238 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8239 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8240 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8241 | &calldata->arg.seq_args, |
| 8242 | &calldata->res.seq_res, |
| 8243 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8244 | } |
| 8245 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8246 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8247 | { |
| 8248 | switch(task->tk_status) { |
| 8249 | case 0: |
| 8250 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8251 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8252 | break; |
| 8253 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8254 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8255 | /* fall through */ |
| 8256 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8257 | return -EAGAIN; |
| 8258 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8259 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8260 | } |
| 8261 | return 0; |
| 8262 | } |
| 8263 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8264 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8265 | { |
| 8266 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8267 | struct nfs_client *clp = calldata->clp; |
| 8268 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8269 | |
| 8270 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8271 | if (!nfs41_sequence_done(task, res)) |
| 8272 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8273 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8274 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8275 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8276 | rpc_restart_call_prepare(task); |
| 8277 | return; |
| 8278 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8279 | dprintk("<-- %s\n", __func__); |
| 8280 | } |
| 8281 | |
| 8282 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8283 | { |
| 8284 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8285 | |
| 8286 | kfree(calldata); |
| 8287 | } |
| 8288 | |
| 8289 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8290 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8291 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8292 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8293 | }; |
| 8294 | |
| 8295 | /* |
| 8296 | * Issue a global reclaim complete. |
| 8297 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8298 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8299 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8300 | { |
| 8301 | struct nfs4_reclaim_complete_data *calldata; |
| 8302 | struct rpc_task *task; |
| 8303 | struct rpc_message msg = { |
| 8304 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8305 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8306 | }; |
| 8307 | struct rpc_task_setup task_setup_data = { |
| 8308 | .rpc_client = clp->cl_rpcclient, |
| 8309 | .rpc_message = &msg, |
| 8310 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8311 | .flags = RPC_TASK_ASYNC, |
| 8312 | }; |
| 8313 | int status = -ENOMEM; |
| 8314 | |
| 8315 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8316 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8317 | if (calldata == NULL) |
| 8318 | goto out; |
| 8319 | calldata->clp = clp; |
| 8320 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8321 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8322 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8323 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8324 | msg.rpc_argp = &calldata->arg; |
| 8325 | msg.rpc_resp = &calldata->res; |
| 8326 | task_setup_data.callback_data = calldata; |
| 8327 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8328 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8329 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8330 | goto out; |
| 8331 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8332 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8333 | if (status == 0) |
| 8334 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8335 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8336 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8337 | out: |
| 8338 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8339 | return status; |
| 8340 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8341 | |
| 8342 | static void |
| 8343 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8344 | { |
| 8345 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8346 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8347 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8348 | |
| 8349 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8350 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8351 | &lgp->res.seq_res, task); |
| 8352 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8353 | } |
| 8354 | |
| 8355 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8356 | { |
| 8357 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8358 | |
| 8359 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8360 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8361 | dprintk("<-- %s\n", __func__); |
| 8362 | } |
| 8363 | |
| 8364 | static int |
| 8365 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8366 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8367 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8368 | struct inode *inode = lgp->args.inode; |
| 8369 | struct nfs_server *server = NFS_SERVER(inode); |
| 8370 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8371 | int nfs4err = task->tk_status; |
| 8372 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8373 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8374 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8375 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8376 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8377 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8378 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8379 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8380 | |
| 8381 | /* |
| 8382 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8383 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8384 | * retry go inband. |
| 8385 | */ |
| 8386 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8387 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8388 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8389 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8390 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8391 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8392 | */ |
| 8393 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8394 | status = -EOVERFLOW; |
| 8395 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8396 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8397 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8398 | * (or clients) writing to the same RAID stripe except when |
| 8399 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8400 | * |
| 8401 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8402 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8403 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8404 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8405 | if (lgp->args.minlength == 0) { |
| 8406 | status = -EOVERFLOW; |
| 8407 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8408 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8409 | status = -EBUSY; |
| 8410 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8411 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8412 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8413 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8414 | case -NFS4ERR_DELEG_REVOKED: |
| 8415 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8416 | case -NFS4ERR_EXPIRED: |
| 8417 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8418 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8419 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8420 | lo = NFS_I(inode)->layout; |
| 8421 | /* If the open stateid was bad, then recover it. */ |
| 8422 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8423 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8424 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8425 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8426 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8427 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8428 | break; |
| 8429 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8430 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8431 | /* |
| 8432 | * Mark the bad layout state as invalid, then retry |
| 8433 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8434 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8435 | spin_unlock(&inode->i_lock); |
| 8436 | pnfs_free_lseg_list(&head); |
| 8437 | status = -EAGAIN; |
| 8438 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8439 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8440 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8441 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8442 | if (!status) { |
| 8443 | if (exception->retry) |
| 8444 | status = -EAGAIN; |
| 8445 | else |
| 8446 | status = err; |
| 8447 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8448 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8449 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8450 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8451 | } |
| 8452 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8453 | static size_t max_response_pages(struct nfs_server *server) |
| 8454 | { |
| 8455 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8456 | return nfs_page_array_len(0, max_resp_sz); |
| 8457 | } |
| 8458 | |
| 8459 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8460 | { |
| 8461 | int i; |
| 8462 | |
| 8463 | if (!pages) |
| 8464 | return; |
| 8465 | |
| 8466 | for (i = 0; i < size; i++) { |
| 8467 | if (!pages[i]) |
| 8468 | break; |
| 8469 | __free_page(pages[i]); |
| 8470 | } |
| 8471 | kfree(pages); |
| 8472 | } |
| 8473 | |
| 8474 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8475 | { |
| 8476 | struct page **pages; |
| 8477 | int i; |
| 8478 | |
| 8479 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8480 | if (!pages) { |
| 8481 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8482 | return NULL; |
| 8483 | } |
| 8484 | |
| 8485 | for (i = 0; i < size; i++) { |
| 8486 | pages[i] = alloc_page(gfp_flags); |
| 8487 | if (!pages[i]) { |
| 8488 | dprintk("%s: failed to allocate page\n", __func__); |
| 8489 | nfs4_free_pages(pages, size); |
| 8490 | return NULL; |
| 8491 | } |
| 8492 | } |
| 8493 | |
| 8494 | return pages; |
| 8495 | } |
| 8496 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8497 | static void nfs4_layoutget_release(void *calldata) |
| 8498 | { |
| 8499 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8500 | struct inode *inode = lgp->args.inode; |
| 8501 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8502 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8503 | |
| 8504 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8505 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8506 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8507 | put_nfs_open_context(lgp->args.ctx); |
| 8508 | kfree(calldata); |
| 8509 | dprintk("<-- %s\n", __func__); |
| 8510 | } |
| 8511 | |
| 8512 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8513 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8514 | .rpc_call_done = nfs4_layoutget_done, |
| 8515 | .rpc_release = nfs4_layoutget_release, |
| 8516 | }; |
| 8517 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8518 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8519 | 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] | 8520 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8521 | struct inode *inode = lgp->args.inode; |
| 8522 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8523 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8524 | struct rpc_task *task; |
| 8525 | struct rpc_message msg = { |
| 8526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8527 | .rpc_argp = &lgp->args, |
| 8528 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8529 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8530 | }; |
| 8531 | struct rpc_task_setup task_setup_data = { |
| 8532 | .rpc_client = server->client, |
| 8533 | .rpc_message = &msg, |
| 8534 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8535 | .callback_data = lgp, |
| 8536 | .flags = RPC_TASK_ASYNC, |
| 8537 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8538 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8539 | struct nfs4_exception exception = { |
| 8540 | .inode = inode, |
| 8541 | .timeout = *timeout, |
| 8542 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8543 | int status = 0; |
| 8544 | |
| 8545 | dprintk("--> %s\n", __func__); |
| 8546 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8547 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8548 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8549 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8550 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8551 | if (!lgp->args.layout.pages) { |
| 8552 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8553 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8554 | } |
| 8555 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8556 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8557 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8558 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8559 | 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] | 8560 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8561 | task = rpc_run_task(&task_setup_data); |
| 8562 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8563 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8564 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8565 | if (status == 0) { |
| 8566 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8567 | *timeout = exception.timeout; |
| 8568 | } |
| 8569 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8570 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8571 | &lgp->args.range, |
| 8572 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8573 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8574 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8575 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8576 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8577 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8578 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8579 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8580 | rpc_put_task(task); |
| 8581 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8582 | if (status) |
| 8583 | return ERR_PTR(status); |
| 8584 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8585 | } |
| 8586 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8587 | static void |
| 8588 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8589 | { |
| 8590 | struct nfs4_layoutreturn *lrp = calldata; |
| 8591 | |
| 8592 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8593 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8594 | &lrp->args.seq_args, |
| 8595 | &lrp->res.seq_res, |
| 8596 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8597 | } |
| 8598 | |
| 8599 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8600 | { |
| 8601 | struct nfs4_layoutreturn *lrp = calldata; |
| 8602 | struct nfs_server *server; |
| 8603 | |
| 8604 | dprintk("--> %s\n", __func__); |
| 8605 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8606 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8607 | return; |
| 8608 | |
| 8609 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8610 | switch (task->tk_status) { |
| 8611 | default: |
| 8612 | task->tk_status = 0; |
| 8613 | case 0: |
| 8614 | break; |
| 8615 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8616 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8617 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8618 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8619 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8620 | return; |
| 8621 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8622 | dprintk("<-- %s\n", __func__); |
| 8623 | } |
| 8624 | |
| 8625 | static void nfs4_layoutreturn_release(void *calldata) |
| 8626 | { |
| 8627 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8628 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8629 | |
| 8630 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2a97442 | 2016-11-20 13:13:54 -0500 | [diff] [blame] | 8631 | pnfs_layoutreturn_free_lsegs(lo, &lrp->args.stateid, &lrp->args.range, |
Trond Myklebust | 68f7447 | 2016-10-12 19:50:54 -0400 | [diff] [blame] | 8632 | lrp->res.lrs_present ? &lrp->res.stateid : NULL); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8633 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8634 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8635 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8636 | kfree(calldata); |
| 8637 | dprintk("<-- %s\n", __func__); |
| 8638 | } |
| 8639 | |
| 8640 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8641 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8642 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8643 | .rpc_release = nfs4_layoutreturn_release, |
| 8644 | }; |
| 8645 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8646 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8647 | { |
| 8648 | struct rpc_task *task; |
| 8649 | struct rpc_message msg = { |
| 8650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8651 | .rpc_argp = &lrp->args, |
| 8652 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8653 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8654 | }; |
| 8655 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8656 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8657 | .rpc_message = &msg, |
| 8658 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8659 | .callback_data = lrp, |
| 8660 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8661 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8662 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8663 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8664 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8665 | &task_setup_data.rpc_client, &msg); |
| 8666 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8667 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8668 | if (!sync) { |
| 8669 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8670 | if (!lrp->inode) { |
| 8671 | nfs4_layoutreturn_release(lrp); |
| 8672 | return -EAGAIN; |
| 8673 | } |
| 8674 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8675 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8676 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8677 | task = rpc_run_task(&task_setup_data); |
| 8678 | if (IS_ERR(task)) |
| 8679 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8680 | if (sync) |
| 8681 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8682 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8683 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8684 | rpc_put_task(task); |
| 8685 | return status; |
| 8686 | } |
| 8687 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8688 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8689 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8690 | struct pnfs_device *pdev, |
| 8691 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8692 | { |
| 8693 | struct nfs4_getdeviceinfo_args args = { |
| 8694 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8695 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8696 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8697 | }; |
| 8698 | struct nfs4_getdeviceinfo_res res = { |
| 8699 | .pdev = pdev, |
| 8700 | }; |
| 8701 | struct rpc_message msg = { |
| 8702 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8703 | .rpc_argp = &args, |
| 8704 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8705 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8706 | }; |
| 8707 | int status; |
| 8708 | |
| 8709 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8710 | 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] | 8711 | if (res.notification & ~args.notify_types) |
| 8712 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8713 | if (res.notification != args.notify_types) |
| 8714 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8715 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8716 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8717 | |
| 8718 | return status; |
| 8719 | } |
| 8720 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8721 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8722 | struct pnfs_device *pdev, |
| 8723 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8724 | { |
| 8725 | struct nfs4_exception exception = { }; |
| 8726 | int err; |
| 8727 | |
| 8728 | do { |
| 8729 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8730 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8731 | &exception); |
| 8732 | } while (exception.retry); |
| 8733 | return err; |
| 8734 | } |
| 8735 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8736 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8737 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8738 | { |
| 8739 | struct nfs4_layoutcommit_data *data = calldata; |
| 8740 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8741 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8742 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8743 | nfs41_setup_sequence(session, |
| 8744 | &data->args.seq_args, |
| 8745 | &data->res.seq_res, |
| 8746 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8747 | } |
| 8748 | |
| 8749 | static void |
| 8750 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8751 | { |
| 8752 | struct nfs4_layoutcommit_data *data = calldata; |
| 8753 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8754 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8755 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8756 | return; |
| 8757 | |
| 8758 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8759 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8760 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8761 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8762 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8763 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8764 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8765 | break; |
| 8766 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8767 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8768 | rpc_restart_call_prepare(task); |
| 8769 | return; |
| 8770 | } |
| 8771 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8772 | } |
| 8773 | |
| 8774 | static void nfs4_layoutcommit_release(void *calldata) |
| 8775 | { |
| 8776 | struct nfs4_layoutcommit_data *data = calldata; |
| 8777 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8778 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8779 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8780 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8781 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8782 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8783 | kfree(data); |
| 8784 | } |
| 8785 | |
| 8786 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8787 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8788 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8789 | .rpc_release = nfs4_layoutcommit_release, |
| 8790 | }; |
| 8791 | |
| 8792 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8793 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8794 | { |
| 8795 | struct rpc_message msg = { |
| 8796 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8797 | .rpc_argp = &data->args, |
| 8798 | .rpc_resp = &data->res, |
| 8799 | .rpc_cred = data->cred, |
| 8800 | }; |
| 8801 | struct rpc_task_setup task_setup_data = { |
| 8802 | .task = &data->task, |
| 8803 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8804 | .rpc_message = &msg, |
| 8805 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8806 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8807 | }; |
| 8808 | struct rpc_task *task; |
| 8809 | int status = 0; |
| 8810 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8811 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8812 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8813 | data->args.lastbytewritten, |
| 8814 | data->args.inode->i_ino); |
| 8815 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8816 | if (!sync) { |
| 8817 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8818 | if (data->inode == NULL) { |
| 8819 | nfs4_layoutcommit_release(data); |
| 8820 | return -EAGAIN; |
| 8821 | } |
| 8822 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8823 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8824 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8825 | task = rpc_run_task(&task_setup_data); |
| 8826 | if (IS_ERR(task)) |
| 8827 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8828 | if (sync) |
| 8829 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8830 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8831 | dprintk("%s: status %d\n", __func__, status); |
| 8832 | rpc_put_task(task); |
| 8833 | return status; |
| 8834 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8835 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8836 | /** |
| 8837 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8838 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8839 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8840 | static int |
| 8841 | _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] | 8842 | struct nfs_fsinfo *info, |
| 8843 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8844 | { |
| 8845 | struct nfs41_secinfo_no_name_args args = { |
| 8846 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8847 | }; |
| 8848 | struct nfs4_secinfo_res res = { |
| 8849 | .flavors = flavors, |
| 8850 | }; |
| 8851 | struct rpc_message msg = { |
| 8852 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8853 | .rpc_argp = &args, |
| 8854 | .rpc_resp = &res, |
| 8855 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8856 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8857 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8858 | int status; |
| 8859 | |
| 8860 | if (use_integrity) { |
| 8861 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8862 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8863 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | dprintk("--> %s\n", __func__); |
| 8867 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8868 | &res.seq_res, 0); |
| 8869 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8870 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8871 | if (cred) |
| 8872 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8873 | |
| 8874 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8875 | } |
| 8876 | |
| 8877 | static int |
| 8878 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8879 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8880 | { |
| 8881 | struct nfs4_exception exception = { }; |
| 8882 | int err; |
| 8883 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8884 | /* first try using integrity protection */ |
| 8885 | err = -NFS4ERR_WRONGSEC; |
| 8886 | |
| 8887 | /* try to use integrity protection with machine cred */ |
| 8888 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8889 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8890 | flavors, true); |
| 8891 | |
| 8892 | /* |
| 8893 | * if unable to use integrity protection, or SECINFO with |
| 8894 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8895 | * disallowed by spec, but exists in deployed servers) use |
| 8896 | * the current filesystem's rpc_client and the user cred. |
| 8897 | */ |
| 8898 | if (err == -NFS4ERR_WRONGSEC) |
| 8899 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8900 | flavors, false); |
| 8901 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8902 | switch (err) { |
| 8903 | case 0: |
| 8904 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8905 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8906 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8907 | default: |
| 8908 | err = nfs4_handle_exception(server, err, &exception); |
| 8909 | } |
| 8910 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8911 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8912 | return err; |
| 8913 | } |
| 8914 | |
| 8915 | static int |
| 8916 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8917 | struct nfs_fsinfo *info) |
| 8918 | { |
| 8919 | int err; |
| 8920 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8921 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8922 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8923 | struct nfs4_secinfo4 *secinfo; |
| 8924 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8925 | |
| 8926 | page = alloc_page(GFP_KERNEL); |
| 8927 | if (!page) { |
| 8928 | err = -ENOMEM; |
| 8929 | goto out; |
| 8930 | } |
| 8931 | |
| 8932 | flavors = page_address(page); |
| 8933 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8934 | |
| 8935 | /* |
| 8936 | * Fall back on "guess and check" method if |
| 8937 | * the server doesn't support SECINFO_NO_NAME |
| 8938 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8939 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8940 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8941 | goto out_freepage; |
| 8942 | } |
| 8943 | if (err) |
| 8944 | goto out_freepage; |
| 8945 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8946 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8947 | secinfo = &flavors->flavors[i]; |
| 8948 | |
| 8949 | switch (secinfo->flavor) { |
| 8950 | case RPC_AUTH_NULL: |
| 8951 | case RPC_AUTH_UNIX: |
| 8952 | case RPC_AUTH_GSS: |
| 8953 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8954 | &secinfo->flavor_info); |
| 8955 | break; |
| 8956 | default: |
| 8957 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8958 | break; |
| 8959 | } |
| 8960 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8961 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8962 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8963 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8964 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8965 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8966 | info, flavor); |
| 8967 | if (!err) |
| 8968 | break; |
| 8969 | } |
| 8970 | } |
| 8971 | |
| 8972 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8973 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8974 | |
| 8975 | out_freepage: |
| 8976 | put_page(page); |
| 8977 | if (err == -EACCES) |
| 8978 | return -EPERM; |
| 8979 | out: |
| 8980 | return err; |
| 8981 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8982 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8983 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8984 | nfs4_stateid *stateid, |
| 8985 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8986 | { |
| 8987 | int status; |
| 8988 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8989 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8990 | }; |
| 8991 | struct nfs41_test_stateid_res res; |
| 8992 | struct rpc_message msg = { |
| 8993 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8994 | .rpc_argp = &args, |
| 8995 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8996 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8997 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8998 | struct rpc_clnt *rpc_client = server->client; |
| 8999 | |
| 9000 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9001 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 9002 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9003 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9004 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9005 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9006 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 9007 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9008 | if (status != NFS_OK) { |
| 9009 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9010 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9011 | } |
| 9012 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 9013 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9014 | } |
| 9015 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9016 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 9017 | int err, struct nfs4_exception *exception) |
| 9018 | { |
| 9019 | exception->retry = 0; |
| 9020 | switch(err) { |
| 9021 | case -NFS4ERR_DELAY: |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9022 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9023 | nfs4_handle_exception(server, err, exception); |
| 9024 | break; |
| 9025 | case -NFS4ERR_BADSESSION: |
| 9026 | case -NFS4ERR_BADSLOT: |
| 9027 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 9028 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 9029 | case -NFS4ERR_DEADSESSION: |
| 9030 | nfs4_do_handle_exception(server, err, exception); |
| 9031 | } |
| 9032 | } |
| 9033 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9034 | /** |
| 9035 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 9036 | * |
| 9037 | * @server: server / transport on which to perform the operation |
| 9038 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9039 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9040 | * |
| 9041 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 9042 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 9043 | * failed or the state ID is not currently valid. |
| 9044 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9045 | static int nfs41_test_stateid(struct nfs_server *server, |
| 9046 | nfs4_stateid *stateid, |
| 9047 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9048 | { |
| 9049 | struct nfs4_exception exception = { }; |
| 9050 | int err; |
| 9051 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9052 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 9053 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 9054 | } while (exception.retry); |
| 9055 | return err; |
| 9056 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9057 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9058 | struct nfs_free_stateid_data { |
| 9059 | struct nfs_server *server; |
| 9060 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9061 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9062 | }; |
| 9063 | |
| 9064 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 9065 | { |
| 9066 | struct nfs_free_stateid_data *data = calldata; |
| 9067 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 9068 | &data->args.seq_args, |
| 9069 | &data->res.seq_res, |
| 9070 | task); |
| 9071 | } |
| 9072 | |
| 9073 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 9074 | { |
| 9075 | struct nfs_free_stateid_data *data = calldata; |
| 9076 | |
| 9077 | nfs41_sequence_done(task, &data->res.seq_res); |
| 9078 | |
| 9079 | switch (task->tk_status) { |
| 9080 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 9081 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9082 | rpc_restart_call_prepare(task); |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | static void nfs41_free_stateid_release(void *calldata) |
| 9087 | { |
| 9088 | kfree(calldata); |
| 9089 | } |
| 9090 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9091 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9092 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 9093 | .rpc_call_done = nfs41_free_stateid_done, |
| 9094 | .rpc_release = nfs41_free_stateid_release, |
| 9095 | }; |
| 9096 | |
| 9097 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9098 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9099 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9100 | bool privileged) |
| 9101 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9102 | struct rpc_message msg = { |
| 9103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9104 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9105 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9106 | struct rpc_task_setup task_setup = { |
| 9107 | .rpc_client = server->client, |
| 9108 | .rpc_message = &msg, |
| 9109 | .callback_ops = &nfs41_free_stateid_ops, |
| 9110 | .flags = RPC_TASK_ASYNC, |
| 9111 | }; |
| 9112 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9113 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9114 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9115 | &task_setup.rpc_client, &msg); |
| 9116 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9117 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9118 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9119 | if (!data) |
| 9120 | return ERR_PTR(-ENOMEM); |
| 9121 | data->server = server; |
| 9122 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9123 | |
| 9124 | task_setup.callback_data = data; |
| 9125 | |
| 9126 | msg.rpc_argp = &data->args; |
| 9127 | msg.rpc_resp = &data->res; |
Trond Myklebust | 76e8a1b | 2016-09-22 13:39:19 -0400 | [diff] [blame] | 9128 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9129 | if (privileged) |
| 9130 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9131 | |
| 9132 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9133 | } |
| 9134 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9135 | /** |
| 9136 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9137 | * |
| 9138 | * @server: server / transport on which to perform the operation |
| 9139 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9140 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9141 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9142 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9143 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9144 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9145 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9146 | const nfs4_stateid *stateid, |
| 9147 | struct rpc_cred *cred, |
| 9148 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9149 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9150 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9151 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9152 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9153 | if (IS_ERR(task)) |
| 9154 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9155 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9156 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9157 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9158 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9159 | static void |
| 9160 | 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] | 9161 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9162 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9163 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9164 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9165 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9166 | } |
| 9167 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9168 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9169 | const nfs4_stateid *s2) |
| 9170 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9171 | if (s1->type != s2->type) |
| 9172 | return false; |
| 9173 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9174 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9175 | return false; |
| 9176 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9177 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9178 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9179 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9180 | return true; |
| 9181 | |
| 9182 | return false; |
| 9183 | } |
| 9184 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9185 | #endif /* CONFIG_NFS_V4_1 */ |
| 9186 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9187 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9188 | const nfs4_stateid *s2) |
| 9189 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9190 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9191 | } |
| 9192 | |
| 9193 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9194 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9195 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9196 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9197 | .recover_open = nfs4_open_reclaim, |
| 9198 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9199 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9200 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9201 | }; |
| 9202 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9203 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9204 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9205 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9206 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9207 | .recover_open = nfs4_open_reclaim, |
| 9208 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9209 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9210 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9211 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9212 | }; |
| 9213 | #endif /* CONFIG_NFS_V4_1 */ |
| 9214 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9215 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9216 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9217 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9218 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9219 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9220 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9221 | }; |
| 9222 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9223 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9224 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9225 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9226 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9227 | .recover_open = nfs41_open_expired, |
| 9228 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9229 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9230 | }; |
| 9231 | #endif /* CONFIG_NFS_V4_1 */ |
| 9232 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9233 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9234 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9235 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9236 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9237 | }; |
| 9238 | |
| 9239 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9240 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9241 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9242 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9243 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9244 | }; |
| 9245 | #endif |
| 9246 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9247 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9248 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9249 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9250 | }; |
| 9251 | |
| 9252 | #if defined(CONFIG_NFS_V4_1) |
| 9253 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9254 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9255 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9256 | }; |
| 9257 | #endif /* CONFIG_NFS_V4_1 */ |
| 9258 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9259 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9260 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9261 | .init_caps = NFS_CAP_READDIRPLUS |
| 9262 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9263 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9264 | .init_client = nfs40_init_client, |
| 9265 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9266 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9267 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9268 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9269 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9270 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9271 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9272 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9273 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9274 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9275 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9276 | }; |
| 9277 | |
| 9278 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9279 | static struct nfs_seqid * |
| 9280 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9281 | { |
| 9282 | return NULL; |
| 9283 | } |
| 9284 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9285 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9286 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9287 | .init_caps = NFS_CAP_READDIRPLUS |
| 9288 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9289 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9290 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9291 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9292 | .init_client = nfs41_init_client, |
| 9293 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9294 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9295 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9296 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9297 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9298 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9299 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9300 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9301 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9302 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9303 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9304 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9305 | }; |
| 9306 | #endif |
| 9307 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9308 | #if defined(CONFIG_NFS_V4_2) |
| 9309 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9310 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9311 | .init_caps = NFS_CAP_READDIRPLUS |
| 9312 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9313 | | NFS_CAP_POSIX_LOCK |
| 9314 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9315 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9316 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9317 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9318 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9319 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9320 | | NFS_CAP_LAYOUTSTATS |
| 9321 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9322 | .init_client = nfs41_init_client, |
| 9323 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9324 | .match_stateid = nfs41_match_stateid, |
| 9325 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9326 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9327 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9328 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9329 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9330 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9331 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9332 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9333 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9334 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9335 | }; |
| 9336 | #endif |
| 9337 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9338 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9339 | [0] = &nfs_v4_0_minor_ops, |
| 9340 | #if defined(CONFIG_NFS_V4_1) |
| 9341 | [1] = &nfs_v4_1_minor_ops, |
| 9342 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9343 | #if defined(CONFIG_NFS_V4_2) |
| 9344 | [2] = &nfs_v4_2_minor_ops, |
| 9345 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9346 | }; |
| 9347 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9348 | 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] | 9349 | { |
| 9350 | ssize_t error, error2; |
| 9351 | |
| 9352 | error = generic_listxattr(dentry, list, size); |
| 9353 | if (error < 0) |
| 9354 | return error; |
| 9355 | if (list) { |
| 9356 | list += error; |
| 9357 | size -= error; |
| 9358 | } |
| 9359 | |
| 9360 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9361 | if (error2 < 0) |
| 9362 | return error2; |
| 9363 | return error + error2; |
| 9364 | } |
| 9365 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9366 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9367 | .create = nfs_create, |
| 9368 | .lookup = nfs_lookup, |
| 9369 | .atomic_open = nfs_atomic_open, |
| 9370 | .link = nfs_link, |
| 9371 | .unlink = nfs_unlink, |
| 9372 | .symlink = nfs_symlink, |
| 9373 | .mkdir = nfs_mkdir, |
| 9374 | .rmdir = nfs_rmdir, |
| 9375 | .mknod = nfs_mknod, |
| 9376 | .rename = nfs_rename, |
| 9377 | .permission = nfs_permission, |
| 9378 | .getattr = nfs_getattr, |
| 9379 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9380 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9381 | }; |
| 9382 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9383 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9384 | .permission = nfs_permission, |
| 9385 | .getattr = nfs_getattr, |
| 9386 | .setattr = nfs_setattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9387 | .listxattr = nfs4_listxattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9388 | }; |
| 9389 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9390 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9391 | .version = 4, /* protocol version */ |
| 9392 | .dentry_ops = &nfs4_dentry_operations, |
| 9393 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9394 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9395 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9396 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9397 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9398 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9399 | .getattr = nfs4_proc_getattr, |
| 9400 | .setattr = nfs4_proc_setattr, |
| 9401 | .lookup = nfs4_proc_lookup, |
| 9402 | .access = nfs4_proc_access, |
| 9403 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9404 | .create = nfs4_proc_create, |
| 9405 | .remove = nfs4_proc_remove, |
| 9406 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9407 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9408 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9409 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9410 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9411 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9412 | .link = nfs4_proc_link, |
| 9413 | .symlink = nfs4_proc_symlink, |
| 9414 | .mkdir = nfs4_proc_mkdir, |
| 9415 | .rmdir = nfs4_proc_remove, |
| 9416 | .readdir = nfs4_proc_readdir, |
| 9417 | .mknod = nfs4_proc_mknod, |
| 9418 | .statfs = nfs4_proc_statfs, |
| 9419 | .fsinfo = nfs4_proc_fsinfo, |
| 9420 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9421 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9422 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9423 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9424 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9425 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9426 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9427 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9428 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9429 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9430 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9431 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9432 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9433 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9434 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9435 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9436 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9437 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9438 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9439 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9440 | .create_server = nfs4_create_server, |
| 9441 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9442 | }; |
| 9443 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9444 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9445 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9446 | .list = nfs4_xattr_list_nfs4_acl, |
| 9447 | .get = nfs4_xattr_get_nfs4_acl, |
| 9448 | .set = nfs4_xattr_set_nfs4_acl, |
| 9449 | }; |
| 9450 | |
| 9451 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9452 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9453 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9454 | &nfs4_xattr_nfs4_label_handler, |
| 9455 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9456 | NULL |
| 9457 | }; |
| 9458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9459 | /* |
| 9460 | * Local variables: |
| 9461 | * c-basic-offset: 8 |
| 9462 | * End: |
| 9463 | */ |