Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 41 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
| 44 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
| 47 | #include <linux/nfs.h> |
| 48 | #include <linux/nfs4.h> |
| 49 | #include <linux/nfs_fs.h> |
| 50 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 51 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 53 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 54 | #include <linux/module.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 55 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 57 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 59 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 61 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 62 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 63 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 64 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 65 | #include "netns.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 66 | #include "nfs4idmap.h" |
Trond Myklebust | 73e39aa | 2012-11-26 12:49:34 -0500 | [diff] [blame] | 67 | #include "nfs4session.h" |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 68 | #include "fscache.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 70 | #include "nfs4trace.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 73 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 74 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 76 | |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 77 | /* file attributes which can be mapped to nfs attributes */ |
| 78 | #define NFS4_VALID_ATTRS (ATTR_MODE \ |
| 79 | | ATTR_UID \ |
| 80 | | ATTR_GID \ |
| 81 | | ATTR_SIZE \ |
| 82 | | ATTR_ATIME \ |
| 83 | | ATTR_MTIME \ |
| 84 | | ATTR_CTIME \ |
| 85 | | ATTR_ATIME_SET \ |
| 86 | | ATTR_MTIME_SET) |
| 87 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 88 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 89 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 90 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 92 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 93 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label); |
| 94 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 95 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 96 | struct nfs_fattr *fattr, struct iattr *sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 97 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 98 | struct nfs4_label *olabel); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 99 | #ifdef CONFIG_NFS_V4_1 |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 100 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
| 101 | struct rpc_cred *); |
| 102 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *, |
| 103 | struct rpc_cred *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 229 | | FATTR4_WORD0_CHANGE |
| 230 | | FATTR4_WORD0_FILEID, |
| 231 | }; |
| 232 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 233 | const u32 nfs4_statfs_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | FATTR4_WORD0_FILES_AVAIL |
| 235 | | FATTR4_WORD0_FILES_FREE |
| 236 | | FATTR4_WORD0_FILES_TOTAL, |
| 237 | FATTR4_WORD1_SPACE_AVAIL |
| 238 | | FATTR4_WORD1_SPACE_FREE |
| 239 | | FATTR4_WORD1_SPACE_TOTAL |
| 240 | }; |
| 241 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 242 | const u32 nfs4_pathconf_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | FATTR4_WORD0_MAXLINK |
| 244 | | FATTR4_WORD0_MAXNAME, |
| 245 | 0 |
| 246 | }; |
| 247 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 248 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | | FATTR4_WORD0_MAXREAD |
| 250 | | FATTR4_WORD0_MAXWRITE |
| 251 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 252 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 253 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 254 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Peng Tao | 2a92ee9 | 2015-09-26 02:24:37 +0800 | [diff] [blame] | 255 | | FATTR4_WORD2_CLONE_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 258 | const u32 nfs4_fs_locations_bitmap[3] = { |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 259 | FATTR4_WORD0_TYPE |
| 260 | | FATTR4_WORD0_CHANGE |
| 261 | | FATTR4_WORD0_SIZE |
| 262 | | FATTR4_WORD0_FSID |
| 263 | | FATTR4_WORD0_FILEID |
| 264 | | FATTR4_WORD0_FS_LOCATIONS, |
| 265 | FATTR4_WORD1_MODE |
| 266 | | FATTR4_WORD1_NUMLINKS |
| 267 | | FATTR4_WORD1_OWNER |
| 268 | | FATTR4_WORD1_OWNER_GROUP |
| 269 | | FATTR4_WORD1_RAWDEV |
| 270 | | FATTR4_WORD1_SPACE_USED |
| 271 | | FATTR4_WORD1_TIME_ACCESS |
| 272 | | FATTR4_WORD1_TIME_METADATA |
| 273 | | FATTR4_WORD1_TIME_MODIFY |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 274 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 277 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct nfs4_readdir_arg *readdir) |
| 279 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 280 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 283 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | readdir->cookie = 0; |
| 289 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 290 | if (cookie == 2) |
| 291 | return; |
| 292 | |
| 293 | /* |
| 294 | * NFSv4 servers do not return entries for '.' and '..' |
| 295 | * Therefore, we fake these entries here. We let '.' |
| 296 | * have cookie 0 and '..' have cookie 1. Note that |
| 297 | * when talking to the server, we always send cookie 0 |
| 298 | * instead of 1 or 2. |
| 299 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 300 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (cookie == 0) { |
| 303 | *p++ = xdr_one; /* next */ |
| 304 | *p++ = xdr_zero; /* cookie, first word */ |
| 305 | *p++ = xdr_one; /* cookie, second word */ |
| 306 | *p++ = xdr_one; /* entry len */ |
| 307 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 308 | p++; |
| 309 | *p++ = xdr_one; /* bitmap length */ |
| 310 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 311 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | *p++ = xdr_one; /* next */ |
| 316 | *p++ = xdr_zero; /* cookie, first word */ |
| 317 | *p++ = xdr_two; /* cookie, second word */ |
| 318 | *p++ = xdr_two; /* entry len */ |
| 319 | memcpy(p, "..\0\0", 4); /* entry */ |
| 320 | p++; |
| 321 | *p++ = xdr_one; /* bitmap length */ |
| 322 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 323 | *p++ = htonl(8); /* attribute buffer length */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 324 | p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | readdir->pgbase = (char *)p - (char *)start; |
| 327 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 328 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 331 | static long nfs4_update_delay(long *timeout) |
| 332 | { |
| 333 | long ret; |
| 334 | if (!timeout) |
| 335 | return NFS4_POLL_RETRY_MAX; |
| 336 | if (*timeout <= 0) |
| 337 | *timeout = NFS4_POLL_RETRY_MIN; |
| 338 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 339 | *timeout = NFS4_POLL_RETRY_MAX; |
| 340 | ret = *timeout; |
| 341 | *timeout <<= 1; |
| 342 | return ret; |
| 343 | } |
| 344 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 346 | { |
| 347 | int res = 0; |
| 348 | |
| 349 | might_sleep(); |
| 350 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 351 | freezable_schedule_timeout_killable_unsafe( |
| 352 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | if (fatal_signal_pending(current)) |
| 354 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 355 | return res; |
| 356 | } |
| 357 | |
| 358 | /* This is the error handling routine for processes that are allowed |
| 359 | * to sleep. |
| 360 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 361 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 362 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 363 | { |
| 364 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 365 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 366 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 367 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 368 | int ret = errorcode; |
| 369 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 370 | exception->delay = 0; |
| 371 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | exception->retry = 0; |
| 373 | switch(errorcode) { |
| 374 | case 0: |
| 375 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 376 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 377 | case -NFS4ERR_DELEG_REVOKED: |
| 378 | case -NFS4ERR_ADMIN_REVOKED: |
| 379 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 380 | if (inode) { |
| 381 | int err; |
| 382 | |
| 383 | err = nfs_async_inode_return_delegation(inode, |
| 384 | stateid); |
| 385 | if (err == 0) |
| 386 | goto wait_on_recovery; |
| 387 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 388 | exception->retry = 1; |
| 389 | break; |
| 390 | } |
| 391 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 392 | if (state == NULL) |
| 393 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 394 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 395 | if (ret < 0) |
| 396 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 397 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 398 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 399 | if (state != NULL) { |
| 400 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 401 | if (ret < 0) |
| 402 | break; |
| 403 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 404 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 405 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 406 | nfs4_schedule_lease_recovery(clp); |
| 407 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 408 | case -NFS4ERR_MOVED: |
| 409 | ret = nfs4_schedule_migration_recovery(server); |
| 410 | if (ret < 0) |
| 411 | break; |
| 412 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 413 | case -NFS4ERR_LEASE_MOVED: |
| 414 | nfs4_schedule_lease_moved_recovery(clp); |
| 415 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 416 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 417 | case -NFS4ERR_BADSESSION: |
| 418 | case -NFS4ERR_BADSLOT: |
| 419 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 420 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 421 | case -NFS4ERR_DEADSESSION: |
| 422 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 423 | case -NFS4ERR_SEQ_MISORDERED: |
| 424 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 425 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 426 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 427 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 428 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 429 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 430 | if (exception->timeout > HZ) { |
| 431 | /* We have retried a decent amount, time to |
| 432 | * fail |
| 433 | */ |
| 434 | ret = -EBUSY; |
| 435 | break; |
| 436 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 437 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 438 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 439 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 440 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 441 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 442 | exception->delay = 1; |
| 443 | return 0; |
| 444 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 445 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 446 | case -NFS4ERR_OLD_STATEID: |
| 447 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 448 | break; |
| 449 | case -NFS4ERR_BADOWNER: |
| 450 | /* The following works around a Linux server bug! */ |
| 451 | case -NFS4ERR_BADNAME: |
| 452 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 453 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 454 | exception->retry = 1; |
| 455 | printk(KERN_WARNING "NFS: v4 server %s " |
| 456 | "does not accept raw " |
| 457 | "uid/gids. " |
| 458 | "Reenabling the idmapper.\n", |
| 459 | server->nfs_client->cl_hostname); |
| 460 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 461 | } |
| 462 | /* We failed to handle the error */ |
| 463 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 464 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 465 | exception->recovering = 1; |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /* This is the error handling routine for processes that are allowed |
| 470 | * to sleep. |
| 471 | */ |
| 472 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 473 | { |
| 474 | struct nfs_client *clp = server->nfs_client; |
| 475 | int ret; |
| 476 | |
| 477 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 478 | if (exception->delay) { |
| 479 | ret = nfs4_delay(server->client, &exception->timeout); |
| 480 | goto out_retry; |
| 481 | } |
| 482 | if (exception->recovering) { |
| 483 | ret = nfs4_wait_clnt_recover(clp); |
| 484 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 485 | return -EIO; |
| 486 | goto out_retry; |
| 487 | } |
| 488 | return ret; |
| 489 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 490 | if (ret == 0) |
| 491 | exception->retry = 1; |
| 492 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 495 | static int |
| 496 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 497 | int errorcode, struct nfs4_exception *exception) |
| 498 | { |
| 499 | struct nfs_client *clp = server->nfs_client; |
| 500 | int ret; |
| 501 | |
| 502 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 503 | if (exception->delay) { |
| 504 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 505 | goto out_retry; |
| 506 | } |
| 507 | if (exception->recovering) { |
| 508 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 509 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 510 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 511 | goto out_retry; |
| 512 | } |
| 513 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 514 | ret = -EIO; |
| 515 | return ret; |
| 516 | out_retry: |
| 517 | if (ret == 0) |
| 518 | exception->retry = 1; |
| 519 | return ret; |
| 520 | } |
| 521 | |
| 522 | static int |
| 523 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 524 | struct nfs4_state *state, long *timeout) |
| 525 | { |
| 526 | struct nfs4_exception exception = { |
| 527 | .state = state, |
| 528 | }; |
| 529 | |
| 530 | if (task->tk_status >= 0) |
| 531 | return 0; |
| 532 | if (timeout) |
| 533 | exception.timeout = *timeout; |
| 534 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 535 | task->tk_status, |
| 536 | &exception); |
| 537 | if (exception.delay && timeout) |
| 538 | *timeout = exception.timeout; |
| 539 | if (exception.retry) |
| 540 | return -EAGAIN; |
| 541 | return 0; |
| 542 | } |
| 543 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 544 | /* |
| 545 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 546 | * or 'false' otherwise. |
| 547 | */ |
| 548 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 549 | { |
| 550 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 551 | |
| 552 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 553 | flavor == RPC_AUTH_GSS_KRB5P) |
| 554 | return true; |
| 555 | |
| 556 | return false; |
| 557 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 558 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 559 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | spin_lock(&clp->cl_lock); |
| 562 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 563 | clp->cl_last_renewal = timestamp; |
| 564 | spin_unlock(&clp->cl_lock); |
| 565 | } |
| 566 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 567 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 568 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 569 | struct nfs_client *clp = server->nfs_client; |
| 570 | |
| 571 | if (!nfs4_has_session(clp)) |
| 572 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 575 | struct nfs4_call_sync_data { |
| 576 | const struct nfs_server *seq_server; |
| 577 | struct nfs4_sequence_args *seq_args; |
| 578 | struct nfs4_sequence_res *seq_res; |
| 579 | }; |
| 580 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 581 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 582 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 583 | { |
| 584 | args->sa_slot = NULL; |
| 585 | args->sa_cache_this = cache_reply; |
| 586 | args->sa_privileged = 0; |
| 587 | |
| 588 | res->sr_slot = NULL; |
| 589 | } |
| 590 | |
| 591 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 592 | { |
| 593 | args->sa_privileged = 1; |
| 594 | } |
| 595 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 596 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 597 | struct nfs4_sequence_args *args, |
| 598 | struct nfs4_sequence_res *res, |
| 599 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 600 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 601 | struct nfs4_slot *slot; |
| 602 | |
| 603 | /* slot already allocated? */ |
| 604 | if (res->sr_slot != NULL) |
| 605 | goto out_start; |
| 606 | |
| 607 | spin_lock(&tbl->slot_tbl_lock); |
| 608 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 609 | goto out_sleep; |
| 610 | |
| 611 | slot = nfs4_alloc_slot(tbl); |
| 612 | if (IS_ERR(slot)) { |
| 613 | if (slot == ERR_PTR(-ENOMEM)) |
| 614 | task->tk_timeout = HZ >> 2; |
| 615 | goto out_sleep; |
| 616 | } |
| 617 | spin_unlock(&tbl->slot_tbl_lock); |
| 618 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame^] | 619 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 620 | args->sa_slot = slot; |
| 621 | res->sr_slot = slot; |
| 622 | |
| 623 | out_start: |
| 624 | rpc_call_start(task); |
| 625 | return 0; |
| 626 | |
| 627 | out_sleep: |
| 628 | if (args->sa_privileged) |
| 629 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 630 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 631 | else |
| 632 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 633 | spin_unlock(&tbl->slot_tbl_lock); |
| 634 | return -EAGAIN; |
| 635 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 636 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 637 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 638 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 639 | { |
| 640 | struct nfs4_slot *slot = res->sr_slot; |
| 641 | struct nfs4_slot_table *tbl; |
| 642 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 643 | tbl = slot->table; |
| 644 | spin_lock(&tbl->slot_tbl_lock); |
| 645 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 646 | nfs4_free_slot(tbl, slot); |
| 647 | spin_unlock(&tbl->slot_tbl_lock); |
| 648 | |
| 649 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static int nfs40_sequence_done(struct rpc_task *task, |
| 653 | struct nfs4_sequence_res *res) |
| 654 | { |
| 655 | if (res->sr_slot != NULL) |
| 656 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 657 | return 1; |
| 658 | } |
| 659 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 660 | #if defined(CONFIG_NFS_V4_1) |
| 661 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 662 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 663 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 664 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 665 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 666 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 667 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 668 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 669 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 670 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 671 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 672 | /* Bump the slot sequence number */ |
| 673 | if (slot->seq_done) |
| 674 | slot->seq_nr++; |
| 675 | slot->seq_done = 0; |
| 676 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 677 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 678 | /* Be nice to the server: try to ensure that the last transmitted |
| 679 | * value for highest_user_slotid <= target_highest_slotid |
| 680 | */ |
| 681 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 682 | send_new_highest_used_slotid = true; |
| 683 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 684 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 685 | send_new_highest_used_slotid = false; |
| 686 | goto out_unlock; |
| 687 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 688 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 689 | |
| 690 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 691 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 692 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 693 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 694 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 695 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 696 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 697 | if (waitqueue_active(&tbl->slot_waitq)) |
| 698 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 701 | static int nfs41_sequence_process(struct rpc_task *task, |
| 702 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 703 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 704 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 705 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 706 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 707 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 708 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 709 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 710 | if (slot == NULL) |
| 711 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 712 | /* don't increment the sequence number if the task wasn't sent */ |
| 713 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 714 | goto out; |
| 715 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 716 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 717 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 718 | if (slot->interrupted) { |
| 719 | slot->interrupted = 0; |
| 720 | interrupted = true; |
| 721 | } |
| 722 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 723 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 724 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 725 | switch (res->sr_status) { |
| 726 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 727 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 728 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 729 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 730 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 731 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame^] | 732 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 733 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 734 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 735 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 736 | case 1: |
| 737 | /* |
| 738 | * sr_status remains 1 if an RPC level error occurred. |
| 739 | * The server may or may not have processed the sequence |
| 740 | * operation.. |
| 741 | * Mark the slot as having hosted an interrupted RPC call. |
| 742 | */ |
| 743 | slot->interrupted = 1; |
| 744 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 745 | case -NFS4ERR_DELAY: |
| 746 | /* The server detected a resend of the RPC call and |
| 747 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 748 | * of RFC5661. |
| 749 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 750 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 751 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 752 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 753 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 754 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 755 | case -NFS4ERR_BADSLOT: |
| 756 | /* |
| 757 | * The slot id we used was probably retired. Try again |
| 758 | * using a different slot id. |
| 759 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 760 | goto retry_nowait; |
| 761 | case -NFS4ERR_SEQ_MISORDERED: |
| 762 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 763 | * Was the last operation on this sequence interrupted? |
| 764 | * If so, retry after bumping the sequence number. |
| 765 | */ |
| 766 | if (interrupted) { |
| 767 | ++slot->seq_nr; |
| 768 | goto retry_nowait; |
| 769 | } |
| 770 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 771 | * Could this slot have been previously retired? |
| 772 | * If so, then the server may be expecting seq_nr = 1! |
| 773 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 774 | if (slot->seq_nr != 1) { |
| 775 | slot->seq_nr = 1; |
| 776 | goto retry_nowait; |
| 777 | } |
| 778 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 779 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 780 | ++slot->seq_nr; |
| 781 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 782 | default: |
| 783 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 784 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 785 | } |
| 786 | out: |
| 787 | /* The session may be reset by one of the error handlers. */ |
| 788 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 789 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 790 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 791 | retry_nowait: |
| 792 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 793 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 794 | task->tk_status = 0; |
| 795 | ret = 0; |
| 796 | } |
| 797 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 798 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 799 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 800 | goto out; |
| 801 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 802 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 803 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 804 | |
| 805 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 806 | { |
| 807 | if (!nfs41_sequence_process(task, res)) |
| 808 | return 0; |
| 809 | if (res->sr_slot != NULL) |
| 810 | nfs41_sequence_free_slot(res); |
| 811 | return 1; |
| 812 | |
| 813 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 814 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 815 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 816 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 817 | { |
| 818 | if (res->sr_slot == NULL) |
| 819 | return 1; |
| 820 | if (res->sr_slot->table->session != NULL) |
| 821 | return nfs41_sequence_process(task, res); |
| 822 | return nfs40_sequence_done(task, res); |
| 823 | } |
| 824 | |
| 825 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 826 | { |
| 827 | if (res->sr_slot != NULL) { |
| 828 | if (res->sr_slot->table->session != NULL) |
| 829 | nfs41_sequence_free_slot(res); |
| 830 | else |
| 831 | nfs40_sequence_free_slot(res); |
| 832 | } |
| 833 | } |
| 834 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 835 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 836 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 837 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 838 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 839 | if (!res->sr_slot->table->session) |
| 840 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 841 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 842 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 844 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 845 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 846 | struct nfs4_sequence_args *args, |
| 847 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 848 | struct rpc_task *task) |
| 849 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 850 | struct nfs4_slot *slot; |
| 851 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 852 | |
| 853 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 854 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 855 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 856 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 857 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 858 | tbl = &session->fc_slot_table; |
| 859 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 860 | task->tk_timeout = 0; |
| 861 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 862 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 863 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 864 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 865 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 866 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 867 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 870 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 871 | if (IS_ERR(slot)) { |
| 872 | /* If out of memory, try again in 1/4 second */ |
| 873 | if (slot == ERR_PTR(-ENOMEM)) |
| 874 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 875 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 876 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 877 | } |
| 878 | spin_unlock(&tbl->slot_tbl_lock); |
| 879 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame^] | 880 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 881 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 882 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 883 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 884 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 885 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 886 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 887 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 888 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | /* |
| 890 | * sr_status is only set in decode_sequence, and so will remain |
| 891 | * set to 1 if an rpc level failure occurs. |
| 892 | */ |
| 893 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 894 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 895 | out_success: |
| 896 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 897 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 898 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 899 | /* Privileged tasks are queued with top priority */ |
| 900 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 901 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 902 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 903 | else |
| 904 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 905 | spin_unlock(&tbl->slot_tbl_lock); |
| 906 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 907 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 908 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 909 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 910 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 911 | struct nfs4_sequence_args *args, |
| 912 | struct nfs4_sequence_res *res, |
| 913 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 914 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 915 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 916 | int ret = 0; |
| 917 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 918 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 919 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 920 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 921 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 922 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 923 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 924 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 925 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 926 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 927 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 928 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 929 | return ret; |
| 930 | } |
| 931 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 932 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 933 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 934 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 935 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 936 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 937 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 938 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 939 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 942 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 943 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 944 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 945 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 946 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 949 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 950 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 951 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 952 | }; |
| 953 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 954 | #else /* !CONFIG_NFS_V4_1 */ |
| 955 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 956 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 957 | struct nfs4_sequence_args *args, |
| 958 | struct nfs4_sequence_res *res, |
| 959 | struct rpc_task *task) |
| 960 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 961 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 962 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 963 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 964 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 965 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 966 | { |
| 967 | return nfs40_sequence_done(task, res); |
| 968 | } |
| 969 | |
| 970 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 971 | { |
| 972 | if (res->sr_slot != NULL) |
| 973 | nfs40_sequence_free_slot(res); |
| 974 | } |
| 975 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 976 | int nfs4_sequence_done(struct rpc_task *task, |
| 977 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 978 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 979 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 980 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 981 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 982 | |
| 983 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 984 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 985 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 986 | { |
| 987 | struct nfs4_call_sync_data *data = calldata; |
| 988 | nfs4_setup_sequence(data->seq_server, |
| 989 | data->seq_args, data->seq_res, task); |
| 990 | } |
| 991 | |
| 992 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 993 | { |
| 994 | struct nfs4_call_sync_data *data = calldata; |
| 995 | nfs4_sequence_done(task, data->seq_res); |
| 996 | } |
| 997 | |
| 998 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 999 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1000 | .rpc_call_done = nfs40_call_sync_done, |
| 1001 | }; |
| 1002 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1003 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1004 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1006 | struct nfs4_sequence_args *args, |
| 1007 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1008 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1009 | int ret; |
| 1010 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1011 | struct nfs_client *clp = server->nfs_client; |
| 1012 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1013 | .seq_server = server, |
| 1014 | .seq_args = args, |
| 1015 | .seq_res = res, |
| 1016 | }; |
| 1017 | struct rpc_task_setup task_setup = { |
| 1018 | .rpc_client = clnt, |
| 1019 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1020 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1021 | .callback_data = &data |
| 1022 | }; |
| 1023 | |
| 1024 | task = rpc_run_task(&task_setup); |
| 1025 | if (IS_ERR(task)) |
| 1026 | ret = PTR_ERR(task); |
| 1027 | else { |
| 1028 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1029 | rpc_put_task(task); |
| 1030 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1034 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1035 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1036 | struct rpc_message *msg, |
| 1037 | struct nfs4_sequence_args *args, |
| 1038 | struct nfs4_sequence_res *res, |
| 1039 | int cache_reply) |
| 1040 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1041 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1042 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
| 1045 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1046 | { |
| 1047 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1048 | |
| 1049 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1050 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1051 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1053 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1054 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1055 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | spin_unlock(&dir->i_lock); |
| 1057 | } |
| 1058 | |
| 1059 | struct nfs4_opendata { |
| 1060 | struct kref kref; |
| 1061 | struct nfs_openargs o_arg; |
| 1062 | struct nfs_openres o_res; |
| 1063 | struct nfs_open_confirmargs c_arg; |
| 1064 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1065 | struct nfs4_string owner_name; |
| 1066 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1067 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1069 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1071 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | struct nfs4_state_owner *owner; |
| 1073 | struct nfs4_state *state; |
| 1074 | struct iattr attrs; |
| 1075 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1076 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1077 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1078 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1079 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | int cancelled; |
| 1081 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1082 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1083 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1084 | int err, struct nfs4_exception *exception) |
| 1085 | { |
| 1086 | if (err != -EINVAL) |
| 1087 | return false; |
| 1088 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1089 | return false; |
| 1090 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1091 | exception->retry = 1; |
| 1092 | return true; |
| 1093 | } |
| 1094 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1095 | static u32 |
| 1096 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1097 | fmode_t fmode, int openflags) |
| 1098 | { |
| 1099 | u32 res = 0; |
| 1100 | |
| 1101 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1102 | case FMODE_READ: |
| 1103 | res = NFS4_SHARE_ACCESS_READ; |
| 1104 | break; |
| 1105 | case FMODE_WRITE: |
| 1106 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1107 | break; |
| 1108 | case FMODE_READ|FMODE_WRITE: |
| 1109 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1110 | } |
| 1111 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1112 | goto out; |
| 1113 | /* Want no delegation if we're using O_DIRECT */ |
| 1114 | if (openflags & O_DIRECT) |
| 1115 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1116 | out: |
| 1117 | return res; |
| 1118 | } |
| 1119 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1120 | static enum open_claim_type4 |
| 1121 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1122 | enum open_claim_type4 claim) |
| 1123 | { |
| 1124 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1125 | return claim; |
| 1126 | switch (claim) { |
| 1127 | default: |
| 1128 | return claim; |
| 1129 | case NFS4_OPEN_CLAIM_FH: |
| 1130 | return NFS4_OPEN_CLAIM_NULL; |
| 1131 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1132 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1133 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1134 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1135 | } |
| 1136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1139 | { |
| 1140 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1141 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1142 | p->o_res.seqid = p->o_arg.seqid; |
| 1143 | p->c_res.seqid = p->c_arg.seqid; |
| 1144 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1145 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1146 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1147 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1150 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1151 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1152 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1153 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1154 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1155 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1156 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1157 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1158 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1159 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1160 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1161 | struct nfs4_opendata *p; |
| 1162 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1163 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1164 | if (p == NULL) |
| 1165 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1166 | |
| 1167 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1168 | if (IS_ERR(p->f_label)) |
| 1169 | goto err_free_p; |
| 1170 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1171 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1172 | if (IS_ERR(p->a_label)) |
| 1173 | goto err_free_f; |
| 1174 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1175 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1176 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1177 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1178 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1179 | nfs_sb_active(dentry->d_sb); |
| 1180 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1181 | p->dir = parent; |
| 1182 | p->owner = sp; |
| 1183 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1184 | p->o_arg.open_flags = flags; |
| 1185 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1186 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1187 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1188 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1189 | * will return permission denied for all bits until close */ |
| 1190 | if (!(flags & O_EXCL)) { |
| 1191 | /* ask server to check for all possible rights as results |
| 1192 | * are cached */ |
| 1193 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1194 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1195 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1196 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1197 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1198 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1199 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1200 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1201 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1202 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1203 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1204 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1205 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1206 | case NFS4_OPEN_CLAIM_NULL: |
| 1207 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1208 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1209 | p->o_arg.fh = NFS_FH(dir); |
| 1210 | break; |
| 1211 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1212 | case NFS4_OPEN_CLAIM_FH: |
| 1213 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1214 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1215 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1216 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1217 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1218 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1219 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1220 | p->o_arg.u.attrs = &p->attrs; |
| 1221 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1222 | |
| 1223 | verf[0] = jiffies; |
| 1224 | verf[1] = current->pid; |
| 1225 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1226 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1227 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1228 | p->c_arg.fh = &p->o_res.fh; |
| 1229 | p->c_arg.stateid = &p->o_res.stateid; |
| 1230 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1231 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1232 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1233 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1234 | |
| 1235 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1236 | nfs4_label_free(p->a_label); |
| 1237 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1238 | nfs4_label_free(p->f_label); |
| 1239 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1240 | kfree(p); |
| 1241 | err: |
| 1242 | dput(parent); |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1246 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1247 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1248 | struct nfs4_opendata *p = container_of(kref, |
| 1249 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1250 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1251 | |
| 1252 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1253 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1254 | if (p->state != NULL) |
| 1255 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1256 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1257 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1258 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1259 | nfs4_label_free(p->f_label); |
| 1260 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1261 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1262 | dput(p->dentry); |
| 1263 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1264 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1265 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1266 | kfree(p); |
| 1267 | } |
| 1268 | |
| 1269 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1270 | { |
| 1271 | if (p != NULL) |
| 1272 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1275 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1276 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1277 | int ret; |
| 1278 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1279 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1283 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1284 | fmode_t fmode) |
| 1285 | { |
| 1286 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1287 | case FMODE_READ|FMODE_WRITE: |
| 1288 | return state->n_rdwr != 0; |
| 1289 | case FMODE_WRITE: |
| 1290 | return state->n_wronly != 0; |
| 1291 | case FMODE_READ: |
| 1292 | return state->n_rdonly != 0; |
| 1293 | } |
| 1294 | WARN_ON_ONCE(1); |
| 1295 | return false; |
| 1296 | } |
| 1297 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1298 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1299 | { |
| 1300 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1301 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1302 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1303 | goto out; |
| 1304 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1305 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1306 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1307 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1308 | break; |
| 1309 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1310 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1311 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1312 | break; |
| 1313 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1314 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1315 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1316 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1317 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1318 | return ret; |
| 1319 | } |
| 1320 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1321 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1322 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1323 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1324 | if (delegation == NULL) |
| 1325 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1326 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1327 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1328 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1329 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1330 | switch (claim) { |
| 1331 | case NFS4_OPEN_CLAIM_NULL: |
| 1332 | case NFS4_OPEN_CLAIM_FH: |
| 1333 | break; |
| 1334 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1335 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1336 | break; |
| 1337 | default: |
| 1338 | return 0; |
| 1339 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1340 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1341 | return 1; |
| 1342 | } |
| 1343 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1345 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1346 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1347 | case FMODE_WRITE: |
| 1348 | state->n_wronly++; |
| 1349 | break; |
| 1350 | case FMODE_READ: |
| 1351 | state->n_rdonly++; |
| 1352 | break; |
| 1353 | case FMODE_READ|FMODE_WRITE: |
| 1354 | state->n_rdwr++; |
| 1355 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1356 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1359 | static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1360 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1361 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1362 | bool need_recover = false; |
| 1363 | |
| 1364 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1365 | need_recover = true; |
| 1366 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1367 | need_recover = true; |
| 1368 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1369 | need_recover = true; |
| 1370 | if (need_recover) |
| 1371 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1372 | } |
| 1373 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1374 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1375 | nfs4_stateid *stateid) |
| 1376 | { |
| 1377 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1378 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1379 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1380 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1381 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1382 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1383 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1384 | return true; |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1388 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1389 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1390 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1391 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1392 | if (state->n_wronly) |
| 1393 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1394 | if (state->n_rdonly) |
| 1395 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1396 | if (state->n_rdwr) |
| 1397 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1398 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1399 | } |
| 1400 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1401 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1402 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1403 | nfs4_stateid *stateid, fmode_t fmode) |
| 1404 | { |
| 1405 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1406 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1407 | case FMODE_WRITE: |
| 1408 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1409 | break; |
| 1410 | case FMODE_READ: |
| 1411 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1412 | break; |
| 1413 | case 0: |
| 1414 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1415 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1416 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1417 | } |
| 1418 | if (stateid == NULL) |
| 1419 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1420 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1421 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1422 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1423 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1424 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1425 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1426 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1427 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1428 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1429 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1430 | } |
| 1431 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1432 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1433 | nfs4_stateid *arg_stateid, |
| 1434 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1435 | { |
| 1436 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1437 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1438 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1439 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1440 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1441 | } |
| 1442 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1443 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1444 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1445 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1446 | case FMODE_READ: |
| 1447 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1448 | break; |
| 1449 | case FMODE_WRITE: |
| 1450 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1451 | break; |
| 1452 | case FMODE_READ|FMODE_WRITE: |
| 1453 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1454 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1455 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1456 | return; |
| 1457 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1458 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1459 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1462 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1464 | /* |
| 1465 | * Protect the call to nfs4_state_set_mode_locked and |
| 1466 | * serialise the stateid update |
| 1467 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1468 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1469 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1470 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1471 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1472 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1473 | } |
| 1474 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1476 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1477 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1478 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1481 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1482 | { |
| 1483 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1484 | struct nfs_delegation *deleg_cur; |
| 1485 | int ret = 0; |
| 1486 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1487 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1488 | |
| 1489 | rcu_read_lock(); |
| 1490 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1491 | if (deleg_cur == NULL) |
| 1492 | goto no_delegation; |
| 1493 | |
| 1494 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1495 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1496 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1497 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1498 | goto no_delegation_unlock; |
| 1499 | |
| 1500 | if (delegation == NULL) |
| 1501 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1502 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1503 | goto no_delegation_unlock; |
| 1504 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1505 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1506 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1507 | ret = 1; |
| 1508 | no_delegation_unlock: |
| 1509 | spin_unlock(&deleg_cur->lock); |
| 1510 | no_delegation: |
| 1511 | rcu_read_unlock(); |
| 1512 | |
| 1513 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1514 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1515 | ret = 1; |
| 1516 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1517 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1518 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1523 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1524 | const nfs4_stateid *stateid) |
| 1525 | { |
| 1526 | struct nfs4_state *state = lsp->ls_state; |
| 1527 | bool ret = false; |
| 1528 | |
| 1529 | spin_lock(&state->state_lock); |
| 1530 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1531 | goto out_noupdate; |
| 1532 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1533 | goto out_noupdate; |
| 1534 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1535 | ret = true; |
| 1536 | out_noupdate: |
| 1537 | spin_unlock(&state->state_lock); |
| 1538 | return ret; |
| 1539 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1540 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1542 | { |
| 1543 | struct nfs_delegation *delegation; |
| 1544 | |
| 1545 | rcu_read_lock(); |
| 1546 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1547 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1548 | rcu_read_unlock(); |
| 1549 | return; |
| 1550 | } |
| 1551 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1552 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1555 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1556 | { |
| 1557 | struct nfs4_state *state = opendata->state; |
| 1558 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1559 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1560 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1561 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1562 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1563 | nfs4_stateid stateid; |
| 1564 | int ret = -EAGAIN; |
| 1565 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1566 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1567 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1568 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1569 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1570 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1571 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1572 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1573 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1574 | rcu_read_lock(); |
| 1575 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1576 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1577 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1578 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1579 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1580 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1581 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1582 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1583 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1584 | if (!opendata->is_recover) { |
| 1585 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1586 | if (ret != 0) |
| 1587 | goto out; |
| 1588 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1589 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1590 | |
| 1591 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1592 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1593 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1594 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1595 | out: |
| 1596 | return ERR_PTR(ret); |
| 1597 | out_return_state: |
| 1598 | atomic_inc(&state->count); |
| 1599 | return state; |
| 1600 | } |
| 1601 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1602 | static void |
| 1603 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1604 | { |
| 1605 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1606 | struct nfs_delegation *delegation; |
| 1607 | int delegation_flags = 0; |
| 1608 | |
| 1609 | rcu_read_lock(); |
| 1610 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1611 | if (delegation) |
| 1612 | delegation_flags = delegation->flags; |
| 1613 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1614 | switch (data->o_arg.claim) { |
| 1615 | default: |
| 1616 | break; |
| 1617 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1618 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1619 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1620 | "returning a delegation for " |
| 1621 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1622 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1623 | return; |
| 1624 | } |
| 1625 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1626 | nfs_inode_set_delegation(state->inode, |
| 1627 | data->owner->so_cred, |
| 1628 | &data->o_res); |
| 1629 | else |
| 1630 | nfs_inode_reclaim_delegation(state->inode, |
| 1631 | data->owner->so_cred, |
| 1632 | &data->o_res); |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1637 | * and update the nfs4_state. |
| 1638 | */ |
| 1639 | static struct nfs4_state * |
| 1640 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1641 | { |
| 1642 | struct inode *inode = data->state->inode; |
| 1643 | struct nfs4_state *state = data->state; |
| 1644 | int ret; |
| 1645 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1646 | if (!data->rpc_done) { |
| 1647 | if (data->rpc_status) { |
| 1648 | ret = data->rpc_status; |
| 1649 | goto err; |
| 1650 | } |
| 1651 | /* cached opens have already been processed */ |
| 1652 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1655 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1656 | if (ret) |
| 1657 | goto err; |
| 1658 | |
| 1659 | if (data->o_res.delegation_type != 0) |
| 1660 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1661 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1662 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1663 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1664 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1665 | |
| 1666 | return state; |
| 1667 | err: |
| 1668 | return ERR_PTR(ret); |
| 1669 | |
| 1670 | } |
| 1671 | |
| 1672 | static struct nfs4_state * |
| 1673 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1674 | { |
| 1675 | struct inode *inode; |
| 1676 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1677 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1678 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1680 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1681 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1682 | goto out; |
| 1683 | } |
| 1684 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1685 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1687 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1688 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr, data->f_label); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1689 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1690 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1691 | goto err; |
| 1692 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1693 | state = nfs4_get_open_state(inode, data->owner); |
| 1694 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1695 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1696 | if (data->o_res.delegation_type != 0) |
| 1697 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1698 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1699 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1701 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1702 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | err_put_inode: |
| 1705 | iput(inode); |
| 1706 | err: |
| 1707 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1710 | static struct nfs4_state * |
| 1711 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1712 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1713 | struct nfs4_state *ret; |
| 1714 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1715 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1716 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1717 | else |
| 1718 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1719 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1720 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1721 | } |
| 1722 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1723 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1724 | { |
| 1725 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1726 | struct nfs_open_context *ctx; |
| 1727 | |
| 1728 | spin_lock(&state->inode->i_lock); |
| 1729 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1730 | if (ctx->state != state) |
| 1731 | continue; |
| 1732 | get_nfs_open_context(ctx); |
| 1733 | spin_unlock(&state->inode->i_lock); |
| 1734 | return ctx; |
| 1735 | } |
| 1736 | spin_unlock(&state->inode->i_lock); |
| 1737 | return ERR_PTR(-ENOENT); |
| 1738 | } |
| 1739 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1740 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1741 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1742 | { |
| 1743 | struct nfs4_opendata *opendata; |
| 1744 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1745 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1746 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1747 | if (opendata == NULL) |
| 1748 | return ERR_PTR(-ENOMEM); |
| 1749 | opendata->state = state; |
| 1750 | atomic_inc(&state->count); |
| 1751 | return opendata; |
| 1752 | } |
| 1753 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1754 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1755 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1756 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1757 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1758 | int ret; |
| 1759 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1760 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1761 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1762 | opendata->o_arg.open_flags = 0; |
| 1763 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1764 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1765 | NFS_SB(opendata->dentry->d_sb), |
| 1766 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1767 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1768 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1769 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1770 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1771 | if (ret != 0) |
| 1772 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1773 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1774 | if (IS_ERR(newstate)) |
| 1775 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1776 | if (newstate != opendata->state) |
| 1777 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1778 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1779 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1783 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1784 | int ret; |
| 1785 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1786 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1787 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1788 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1789 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1791 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1792 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1793 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1794 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1795 | if (ret != 0) |
| 1796 | return ret; |
| 1797 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1798 | if (ret != 0) |
| 1799 | return ret; |
| 1800 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1801 | if (ret != 0) |
| 1802 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1803 | /* |
| 1804 | * We may have performed cached opens for all three recoveries. |
| 1805 | * Check if we need to update the current stateid. |
| 1806 | */ |
| 1807 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1808 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1809 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1810 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1811 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1812 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1813 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * OPEN_RECLAIM: |
| 1819 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1821 | static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1823 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1825 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | int status; |
| 1827 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1828 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1829 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1830 | if (IS_ERR(opendata)) |
| 1831 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1832 | rcu_read_lock(); |
| 1833 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1834 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1835 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1836 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1837 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1838 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1839 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | return status; |
| 1841 | } |
| 1842 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1843 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | { |
| 1845 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1846 | struct nfs4_exception exception = { }; |
| 1847 | int err; |
| 1848 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1849 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1850 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1851 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1852 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1853 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } while (exception.retry); |
| 1857 | return err; |
| 1858 | } |
| 1859 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1861 | { |
| 1862 | struct nfs_open_context *ctx; |
| 1863 | int ret; |
| 1864 | |
| 1865 | ctx = nfs4_state_find_open_context(state); |
| 1866 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1867 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1868 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1869 | put_nfs_open_context(ctx); |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1873 | static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1875 | switch (err) { |
| 1876 | default: |
| 1877 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1878 | "%d.\n", __func__, err); |
| 1879 | case 0: |
| 1880 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1881 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1882 | case -ESTALE: |
| 1883 | break; |
| 1884 | case -NFS4ERR_BADSESSION: |
| 1885 | case -NFS4ERR_BADSLOT: |
| 1886 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1887 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1888 | case -NFS4ERR_DEADSESSION: |
| 1889 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1890 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1891 | return -EAGAIN; |
| 1892 | case -NFS4ERR_STALE_CLIENTID: |
| 1893 | case -NFS4ERR_STALE_STATEID: |
| 1894 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1895 | case -NFS4ERR_EXPIRED: |
| 1896 | /* Don't recall a delegation if it was lost */ |
| 1897 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1898 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1899 | case -NFS4ERR_MOVED: |
| 1900 | nfs4_schedule_migration_recovery(server); |
| 1901 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1902 | case -NFS4ERR_LEASE_MOVED: |
| 1903 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1904 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1905 | case -NFS4ERR_DELEG_REVOKED: |
| 1906 | case -NFS4ERR_ADMIN_REVOKED: |
| 1907 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1908 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1909 | nfs_inode_find_state_and_recover(state->inode, |
| 1910 | stateid); |
| 1911 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1912 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1913 | case -NFS4ERR_DELAY: |
| 1914 | case -NFS4ERR_GRACE: |
| 1915 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1916 | ssleep(1); |
| 1917 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1918 | case -ENOMEM: |
| 1919 | case -NFS4ERR_DENIED: |
| 1920 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1921 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | return err; |
| 1924 | } |
| 1925 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1926 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1927 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1928 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1929 | { |
| 1930 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1931 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1932 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1933 | |
| 1934 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1935 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1936 | if (IS_ERR(opendata)) |
| 1937 | return PTR_ERR(opendata); |
| 1938 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1939 | write_seqlock(&state->seqlock); |
| 1940 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1942 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1943 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1944 | case FMODE_READ|FMODE_WRITE: |
| 1945 | case FMODE_WRITE: |
| 1946 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1947 | if (err) |
| 1948 | break; |
| 1949 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1950 | if (err) |
| 1951 | break; |
| 1952 | case FMODE_READ: |
| 1953 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1954 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1955 | nfs4_opendata_put(opendata); |
| 1956 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1957 | } |
| 1958 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1959 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1960 | { |
| 1961 | struct nfs4_opendata *data = calldata; |
| 1962 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1963 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1964 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1967 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1968 | { |
| 1969 | struct nfs4_opendata *data = calldata; |
| 1970 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1971 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1972 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1973 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1974 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1975 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1976 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1977 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1978 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1979 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static void nfs4_open_confirm_release(void *calldata) |
| 1983 | { |
| 1984 | struct nfs4_opendata *data = calldata; |
| 1985 | struct nfs4_state *state = NULL; |
| 1986 | |
| 1987 | /* If this request hasn't been cancelled, do nothing */ |
| 1988 | if (data->cancelled == 0) |
| 1989 | goto out_free; |
| 1990 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1991 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1992 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1993 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1994 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1995 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1996 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1997 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2001 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2002 | .rpc_call_done = nfs4_open_confirm_done, |
| 2003 | .rpc_release = nfs4_open_confirm_release, |
| 2004 | }; |
| 2005 | |
| 2006 | /* |
| 2007 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2008 | */ |
| 2009 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2010 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2011 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2012 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2013 | struct rpc_message msg = { |
| 2014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2015 | .rpc_argp = &data->c_arg, |
| 2016 | .rpc_resp = &data->c_res, |
| 2017 | .rpc_cred = data->owner->so_cred, |
| 2018 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2019 | struct rpc_task_setup task_setup_data = { |
| 2020 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2021 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | .callback_ops = &nfs4_open_confirm_ops, |
| 2023 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2024 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .flags = RPC_TASK_ASYNC, |
| 2026 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | int status; |
| 2028 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2029 | nfs4_init_sequence(&data->c_arg.seq_args, &data->c_res.seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2030 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2031 | data->rpc_done = 0; |
| 2032 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2033 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2034 | if (data->is_recover) |
| 2035 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2036 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2037 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2038 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2039 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2040 | if (status != 0) { |
| 2041 | data->cancelled = 1; |
| 2042 | smp_wmb(); |
| 2043 | } else |
| 2044 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2045 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | return status; |
| 2047 | } |
| 2048 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2049 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2051 | struct nfs4_opendata *data = calldata; |
| 2052 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2053 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2054 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2055 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2056 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2057 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2058 | /* |
| 2059 | * Check if we still need to send an OPEN call, or if we can use |
| 2060 | * a delegation instead. |
| 2061 | */ |
| 2062 | if (data->state != NULL) { |
| 2063 | struct nfs_delegation *delegation; |
| 2064 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2065 | if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2066 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2067 | rcu_read_lock(); |
| 2068 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2069 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2070 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2071 | rcu_read_unlock(); |
| 2072 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2073 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2074 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2075 | switch (claim) { |
| 2076 | default: |
| 2077 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2078 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2079 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2080 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2081 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2082 | case NFS4_OPEN_CLAIM_FH: |
| 2083 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2084 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2085 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2086 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2087 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2088 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2089 | &data->o_res.seq_res, |
| 2090 | task) != 0) |
| 2091 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2092 | |
| 2093 | /* Set the create mode (note dependency on the session type) */ |
| 2094 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2095 | if (data->o_arg.open_flags & O_EXCL) { |
| 2096 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2097 | if (nfs4_has_persistent_session(clp)) |
| 2098 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2099 | else if (clp->cl_mvops->minor_version > 0) |
| 2100 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2101 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2102 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2103 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2104 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2105 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2106 | out_no_action: |
| 2107 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2108 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2109 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2112 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2113 | { |
| 2114 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2116 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2117 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2118 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2119 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2120 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2121 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2122 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2123 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2124 | case S_IFREG: |
| 2125 | break; |
| 2126 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2127 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2128 | break; |
| 2129 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2130 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2133 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2134 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2135 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2136 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2137 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2138 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2139 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2140 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2141 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | static void nfs4_open_release(void *calldata) |
| 2144 | { |
| 2145 | struct nfs4_opendata *data = calldata; |
| 2146 | struct nfs4_state *state = NULL; |
| 2147 | |
| 2148 | /* If this request hasn't been cancelled, do nothing */ |
| 2149 | if (data->cancelled == 0) |
| 2150 | goto out_free; |
| 2151 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2152 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2153 | goto out_free; |
| 2154 | /* In case we need an open_confirm, no cleanup! */ |
| 2155 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2156 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2157 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2158 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2159 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2161 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2165 | .rpc_call_prepare = nfs4_open_prepare, |
| 2166 | .rpc_call_done = nfs4_open_done, |
| 2167 | .rpc_release = nfs4_open_release, |
| 2168 | }; |
| 2169 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2170 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2171 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2172 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2173 | struct nfs_server *server = NFS_SERVER(dir); |
| 2174 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2175 | struct nfs_openres *o_res = &data->o_res; |
| 2176 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2177 | struct rpc_message msg = { |
| 2178 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2179 | .rpc_argp = o_arg, |
| 2180 | .rpc_resp = o_res, |
| 2181 | .rpc_cred = data->owner->so_cred, |
| 2182 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2183 | struct rpc_task_setup task_setup_data = { |
| 2184 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2185 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2186 | .callback_ops = &nfs4_open_ops, |
| 2187 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2188 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2189 | .flags = RPC_TASK_ASYNC, |
| 2190 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2191 | int status; |
| 2192 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2193 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2194 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2195 | data->rpc_done = 0; |
| 2196 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2197 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2198 | data->is_recover = 0; |
| 2199 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2200 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2201 | data->is_recover = 1; |
| 2202 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2203 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2204 | if (IS_ERR(task)) |
| 2205 | return PTR_ERR(task); |
| 2206 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2207 | if (status != 0) { |
| 2208 | data->cancelled = 1; |
| 2209 | smp_wmb(); |
| 2210 | } else |
| 2211 | status = data->rpc_status; |
| 2212 | rpc_put_task(task); |
| 2213 | |
| 2214 | return status; |
| 2215 | } |
| 2216 | |
| 2217 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2218 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2219 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2220 | struct nfs_openres *o_res = &data->o_res; |
| 2221 | int status; |
| 2222 | |
| 2223 | status = nfs4_run_open_task(data, 1); |
| 2224 | if (status != 0 || !data->rpc_done) |
| 2225 | return status; |
| 2226 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2227 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2228 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2229 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2230 | status = _nfs4_proc_open_confirm(data); |
| 2231 | if (status != 0) |
| 2232 | return status; |
| 2233 | } |
| 2234 | |
| 2235 | return status; |
| 2236 | } |
| 2237 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2238 | /* |
| 2239 | * Additional permission checks in order to distinguish between an |
| 2240 | * open for read, and an open for execute. This works around the |
| 2241 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2242 | * the same. |
| 2243 | * Note that in the non-execute case, we want to turn off permission |
| 2244 | * checking if we just created a new file (POSIX open() semantics). |
| 2245 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2246 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2247 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2248 | struct nfs4_state *state, fmode_t fmode, |
| 2249 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2250 | { |
| 2251 | struct nfs_access_entry cache; |
| 2252 | u32 mask; |
| 2253 | |
| 2254 | /* access call failed or for some reason the server doesn't |
| 2255 | * support any access modes -- defer access call until later */ |
| 2256 | if (opendata->o_res.access_supported == 0) |
| 2257 | return 0; |
| 2258 | |
| 2259 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2260 | /* |
| 2261 | * Use openflags to check for exec, because fmode won't |
| 2262 | * always have FMODE_EXEC set when file open for exec. |
| 2263 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2264 | if (openflags & __FMODE_EXEC) { |
| 2265 | /* ONLY check for exec rights */ |
| 2266 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2267 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2268 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2269 | |
| 2270 | cache.cred = cred; |
| 2271 | cache.jiffies = jiffies; |
| 2272 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2273 | nfs_access_add_cache(state->inode, &cache); |
| 2274 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2275 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2276 | return 0; |
| 2277 | |
| 2278 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2279 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2280 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2283 | /* |
| 2284 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2285 | */ |
| 2286 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2287 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2288 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2289 | struct nfs_server *server = NFS_SERVER(dir); |
| 2290 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2291 | struct nfs_openres *o_res = &data->o_res; |
| 2292 | int status; |
| 2293 | |
| 2294 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2295 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2296 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2297 | if (status != 0) { |
| 2298 | if (status == -NFS4ERR_BADNAME && |
| 2299 | !(o_arg->open_flags & O_CREAT)) |
| 2300 | return -ENOENT; |
| 2301 | return status; |
| 2302 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2303 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2304 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2305 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2306 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2307 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2308 | if (o_arg->open_flags & O_EXCL) |
| 2309 | data->file_created = 1; |
| 2310 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2311 | data->file_created = 1; |
| 2312 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2313 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2314 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2316 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2318 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | } |
| 2320 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2321 | nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2325 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2326 | { |
| 2327 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2328 | } |
| 2329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | /* |
| 2331 | * OPEN_EXPIRED: |
| 2332 | * reclaim state on the server after a network partition. |
| 2333 | * Assumes caller holds the appropriate lock |
| 2334 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2335 | static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2337 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2338 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2340 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2341 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2342 | if (IS_ERR(opendata)) |
| 2343 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2344 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2345 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2346 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2347 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2351 | static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2352 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2353 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2354 | struct nfs4_exception exception = { }; |
| 2355 | int err; |
| 2356 | |
| 2357 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2358 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2359 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2360 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2361 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2362 | switch (err) { |
| 2363 | default: |
| 2364 | goto out; |
| 2365 | case -NFS4ERR_GRACE: |
| 2366 | case -NFS4ERR_DELAY: |
| 2367 | nfs4_handle_exception(server, err, &exception); |
| 2368 | err = 0; |
| 2369 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2370 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2371 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2372 | return err; |
| 2373 | } |
| 2374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2378 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2380 | ctx = nfs4_state_find_open_context(state); |
| 2381 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2382 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2383 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2384 | put_nfs_open_context(ctx); |
| 2385 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2388 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) |
| 2389 | { |
| 2390 | nfs_remove_bad_delegation(state->inode); |
| 2391 | write_seqlock(&state->seqlock); |
| 2392 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2393 | write_sequnlock(&state->seqlock); |
| 2394 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2395 | } |
| 2396 | |
| 2397 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2398 | { |
| 2399 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
| 2400 | nfs_finish_clear_delegation_stateid(state); |
| 2401 | } |
| 2402 | |
| 2403 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2404 | { |
| 2405 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2406 | nfs40_clear_delegation_stateid(state); |
| 2407 | return nfs4_open_expired(sp, state); |
| 2408 | } |
| 2409 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2410 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2411 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2412 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2413 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2414 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2415 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2416 | struct rpc_cred *cred; |
| 2417 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2418 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2419 | /* Get the delegation credential for use by test/free_stateid */ |
| 2420 | rcu_read_lock(); |
| 2421 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2422 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2423 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2424 | return; |
| 2425 | } |
| 2426 | |
| 2427 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2428 | cred = get_rpccred(delegation->cred); |
| 2429 | rcu_read_unlock(); |
| 2430 | status = nfs41_test_stateid(server, &stateid, cred); |
| 2431 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2432 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2433 | if (status != NFS_OK) { |
| 2434 | /* Free the stateid unless the server explicitly |
| 2435 | * informs us the stateid is unrecognized. */ |
| 2436 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2437 | nfs41_free_stateid(server, &stateid, cred); |
| 2438 | nfs_finish_clear_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2439 | } |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2440 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2441 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | /** |
| 2445 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2446 | * |
| 2447 | * @state: NFSv4 state for an inode |
| 2448 | * |
| 2449 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2450 | * Otherwise a negative NFS4ERR value is returned. |
| 2451 | */ |
| 2452 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2453 | { |
| 2454 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2455 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2456 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2457 | int status; |
| 2458 | |
| 2459 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2460 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2461 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2462 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2463 | return -NFS4ERR_BAD_STATEID; |
| 2464 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2465 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2466 | trace_nfs4_test_open_stateid(state, NULL, status); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2467 | if (status != NFS_OK) { |
| 2468 | /* Free the stateid unless the server explicitly |
| 2469 | * informs us the stateid is unrecognized. */ |
| 2470 | if (status != -NFS4ERR_BAD_STATEID) |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2471 | nfs41_free_stateid(server, stateid, cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2472 | |
| 2473 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2474 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2475 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2476 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2477 | } |
| 2478 | return status; |
| 2479 | } |
| 2480 | |
| 2481 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2482 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2483 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2484 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2485 | nfs41_check_delegation_stateid(state); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2486 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2487 | if (status != NFS_OK) |
| 2488 | status = nfs4_open_expired(sp, state); |
| 2489 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2490 | } |
| 2491 | #endif |
| 2492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2494 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2495 | * fields corresponding to attributes that were used to store the verifier. |
| 2496 | * Make sure we clobber those fields in the later setattr call |
| 2497 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2498 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2499 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2500 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2501 | const u32 *attrset = opendata->o_res.attrset; |
| 2502 | |
| 2503 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2504 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2505 | sattr->ia_valid |= ATTR_ATIME; |
| 2506 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2507 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2508 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2509 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2510 | |
| 2511 | /* Except MODE, it seems harmless of setting twice. */ |
| 2512 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2513 | sattr->ia_valid &= ~ATTR_MODE; |
| 2514 | |
| 2515 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2516 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2517 | } |
| 2518 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2519 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2520 | fmode_t fmode, |
| 2521 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2522 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2523 | { |
| 2524 | struct nfs4_state_owner *sp = opendata->owner; |
| 2525 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2526 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2527 | struct nfs4_state *state; |
| 2528 | unsigned int seq; |
| 2529 | int ret; |
| 2530 | |
| 2531 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2532 | |
| 2533 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2534 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2535 | goto out; |
| 2536 | |
| 2537 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2538 | ret = PTR_ERR(state); |
| 2539 | if (IS_ERR(state)) |
| 2540 | goto out; |
| 2541 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2542 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2543 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2544 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2545 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2546 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2547 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2548 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2549 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2550 | alias = d_exact_alias(dentry, state->inode); |
| 2551 | if (!alias) |
| 2552 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2553 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2554 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2555 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2556 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2557 | } |
| 2558 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2559 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2560 | } |
| 2561 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2562 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2563 | if (ret != 0) |
| 2564 | goto out; |
| 2565 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2566 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2567 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2568 | nfs_inode_attach_open_context(ctx); |
| 2569 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2570 | nfs4_schedule_stateid_recovery(server, state); |
| 2571 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2572 | out: |
| 2573 | return ret; |
| 2574 | } |
| 2575 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2576 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2577 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2579 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2580 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2581 | int flags, |
| 2582 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2583 | struct nfs4_label *label, |
| 2584 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | { |
| 2586 | struct nfs4_state_owner *sp; |
| 2587 | struct nfs4_state *state = NULL; |
| 2588 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2589 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2590 | struct dentry *dentry = ctx->dentry; |
| 2591 | struct rpc_cred *cred = ctx->cred; |
| 2592 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2593 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2594 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2595 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2596 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | |
| 2598 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2600 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2601 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2603 | goto out_err; |
| 2604 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2605 | status = nfs4_recover_expired_lease(server); |
| 2606 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2607 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2608 | if (d_really_is_positive(dentry)) |
| 2609 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2610 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2611 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2612 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2613 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2614 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2615 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2616 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2618 | if (label) { |
| 2619 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2620 | if (IS_ERR(olabel)) { |
| 2621 | status = PTR_ERR(olabel); |
| 2622 | goto err_opendata_put; |
| 2623 | } |
| 2624 | } |
| 2625 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2626 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2627 | if (!opendata->f_attr.mdsthreshold) { |
| 2628 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2629 | if (!opendata->f_attr.mdsthreshold) |
| 2630 | goto err_free_label; |
| 2631 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2632 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2633 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2634 | if (d_really_is_positive(dentry)) |
| 2635 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2636 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2637 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2638 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2639 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2640 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2641 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2642 | 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] | 2643 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2644 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2645 | /* |
| 2646 | * send create attributes which was not set by open |
| 2647 | * with an extra setattr. |
| 2648 | */ |
| 2649 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2650 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2651 | status = nfs4_do_setattr(state->inode, cred, |
| 2652 | opendata->o_res.f_attr, sattr, |
| 2653 | state, label, olabel); |
| 2654 | if (status == 0) { |
| 2655 | nfs_setattr_update_inode(state->inode, sattr, |
| 2656 | opendata->o_res.f_attr); |
| 2657 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2658 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2659 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2660 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2661 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2662 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2663 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2664 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2665 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2666 | opendata->f_attr.mdsthreshold = NULL; |
| 2667 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2668 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2669 | nfs4_label_free(olabel); |
| 2670 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2671 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2674 | err_free_label: |
| 2675 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2676 | err_opendata_put: |
| 2677 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2678 | err_put_state_owner: |
| 2679 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | return status; |
| 2682 | } |
| 2683 | |
| 2684 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2685 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2686 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2687 | int flags, |
| 2688 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2689 | struct nfs4_label *label, |
| 2690 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2692 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | struct nfs4_exception exception = { }; |
| 2694 | struct nfs4_state *res; |
| 2695 | int status; |
| 2696 | |
| 2697 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2698 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2699 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2700 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | if (status == 0) |
| 2702 | break; |
| 2703 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2704 | * book-keeping w.r.t. state-changing operations |
| 2705 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2706 | * It is actually a sign of a bug on the client or on the server. |
| 2707 | * |
| 2708 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2709 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | * have unhashed the old state_owner for us, and that we can |
| 2711 | * therefore safely retry using a new one. We should still warn |
| 2712 | * the user though... |
| 2713 | */ |
| 2714 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2715 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2716 | " returned a bad sequence-id error!\n", |
| 2717 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | exception.retry = 1; |
| 2719 | continue; |
| 2720 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2721 | /* |
| 2722 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2723 | * state before it received the OPEN_CONFIRM. |
| 2724 | * Recover by retrying the request as per the discussion |
| 2725 | * on Page 181 of RFC3530. |
| 2726 | */ |
| 2727 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2728 | exception.retry = 1; |
| 2729 | continue; |
| 2730 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2731 | if (status == -EAGAIN) { |
| 2732 | /* We must have found a delegation */ |
| 2733 | exception.retry = 1; |
| 2734 | continue; |
| 2735 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2736 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2737 | continue; |
| 2738 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | status, &exception)); |
| 2740 | } while (exception.retry); |
| 2741 | return res; |
| 2742 | } |
| 2743 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2744 | static int _nfs4_do_setattr(struct inode *inode, |
| 2745 | struct nfs_setattrargs *arg, |
| 2746 | struct nfs_setattrres *res, |
| 2747 | struct rpc_cred *cred, |
| 2748 | struct nfs4_state *state) |
| 2749 | { |
| 2750 | struct nfs_server *server = NFS_SERVER(inode); |
| 2751 | struct rpc_message msg = { |
| 2752 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2753 | .rpc_argp = arg, |
| 2754 | .rpc_resp = res, |
| 2755 | .rpc_cred = cred, |
| 2756 | }; |
| 2757 | struct rpc_cred *delegation_cred = NULL; |
| 2758 | unsigned long timestamp = jiffies; |
| 2759 | fmode_t fmode; |
| 2760 | bool truncate; |
| 2761 | int status; |
| 2762 | |
| 2763 | nfs_fattr_init(res->fattr); |
| 2764 | |
| 2765 | /* Servers should only apply open mode checks for file size changes */ |
| 2766 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2767 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2768 | |
| 2769 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2770 | /* Use that stateid */ |
| 2771 | } else if (truncate && state != NULL) { |
| 2772 | struct nfs_lockowner lockowner = { |
| 2773 | .l_owner = current->files, |
| 2774 | .l_pid = current->tgid, |
| 2775 | }; |
| 2776 | if (!nfs4_valid_open_stateid(state)) |
| 2777 | return -EBADF; |
| 2778 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2779 | &arg->stateid, &delegation_cred) == -EIO) |
| 2780 | return -EBADF; |
| 2781 | } else |
| 2782 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2783 | if (delegation_cred) |
| 2784 | msg.rpc_cred = delegation_cred; |
| 2785 | |
| 2786 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2787 | |
| 2788 | put_rpccred(delegation_cred); |
| 2789 | if (status == 0 && state != NULL) |
| 2790 | renew_lease(server, timestamp); |
| 2791 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2792 | return status; |
| 2793 | } |
| 2794 | |
| 2795 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2796 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2797 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2798 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2800 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2802 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | .iap = sattr, |
| 2804 | .server = server, |
| 2805 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2806 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | }; |
| 2808 | struct nfs_setattrres res = { |
| 2809 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2810 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | .server = server, |
| 2812 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2813 | struct nfs4_exception exception = { |
| 2814 | .state = state, |
| 2815 | .inode = inode, |
| 2816 | .stateid = &arg.stateid, |
| 2817 | }; |
| 2818 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2820 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2821 | if (ilabel) |
| 2822 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2825 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2826 | switch (err) { |
| 2827 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2828 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2829 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2830 | "applying open mode checks to " |
| 2831 | "a SETATTR that is not " |
| 2832 | "changing file size.\n", |
| 2833 | server->nfs_client->cl_hostname); |
| 2834 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2835 | if (state && !(state->state & FMODE_WRITE)) { |
| 2836 | err = -EBADF; |
| 2837 | if (sattr->ia_valid & ATTR_OPEN) |
| 2838 | err = -EACCES; |
| 2839 | goto out; |
| 2840 | } |
| 2841 | } |
| 2842 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2844 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | return err; |
| 2846 | } |
| 2847 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2848 | static bool |
| 2849 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2850 | { |
| 2851 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2852 | return false; |
| 2853 | |
| 2854 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2855 | } |
| 2856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | struct nfs4_closedata { |
| 2858 | struct inode *inode; |
| 2859 | struct nfs4_state *state; |
| 2860 | struct nfs_closeargs arg; |
| 2861 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2862 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2863 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2864 | bool roc; |
| 2865 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | }; |
| 2867 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2868 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2869 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2870 | struct nfs4_closedata *calldata = data; |
| 2871 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2872 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2873 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2874 | if (calldata->roc) |
| 2875 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2876 | nfs4_put_open_state(calldata->state); |
| 2877 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2878 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2879 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2880 | kfree(calldata); |
| 2881 | } |
| 2882 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2883 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2885 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2888 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2890 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2891 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2892 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2893 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | /* hmm. we are done with the inode, and in the process of freeing |
| 2895 | * the state_owner. we keep this around to process errors |
| 2896 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | switch (task->tk_status) { |
| 2898 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2899 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2900 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2901 | pnfs_roc_set_barrier(state->inode, |
| 2902 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2903 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2904 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2905 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2907 | case -NFS4ERR_OLD_STATEID: |
| 2908 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2910 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2911 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 2912 | rpc_restart_call_prepare(task); |
| 2913 | goto out_release; |
| 2914 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2915 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2916 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 2918 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2919 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2920 | goto out_release; |
| 2921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 2923 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 2924 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 2925 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2926 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2927 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2928 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2931 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2933 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2934 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2935 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2936 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2937 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2938 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2939 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2940 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2941 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2942 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2943 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2944 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 2945 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2946 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2947 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 2948 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2949 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2950 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2951 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2952 | if (state->n_rdonly == 0) |
| 2953 | call_close |= is_rdonly; |
| 2954 | else if (is_rdonly) |
| 2955 | calldata->arg.fmode |= FMODE_READ; |
| 2956 | if (state->n_wronly == 0) |
| 2957 | call_close |= is_wronly; |
| 2958 | else if (is_wronly) |
| 2959 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 2960 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 2961 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 2962 | } else if (is_rdwr) |
| 2963 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 2964 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 2965 | if (!nfs4_valid_open_stateid(state)) |
| 2966 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2967 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2968 | |
| 2969 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2970 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2971 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2972 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2973 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2974 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 2975 | nfs_release_seqid(calldata->arg.seqid); |
| 2976 | goto out_wait; |
| 2977 | } |
| 2978 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2979 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2980 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 2981 | if (calldata->roc) |
| 2982 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 2983 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 2984 | calldata->arg.share_access = |
| 2985 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 2986 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2987 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2988 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2989 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2990 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2991 | &calldata->arg.seq_args, |
| 2992 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2993 | task) != 0) |
| 2994 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2995 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2996 | return; |
| 2997 | out_no_action: |
| 2998 | task->tk_action = NULL; |
| 2999 | out_wait: |
| 3000 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3003 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3004 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3005 | .rpc_call_done = nfs4_close_done, |
| 3006 | .rpc_release = nfs4_free_closedata, |
| 3007 | }; |
| 3008 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3009 | static bool nfs4_roc(struct inode *inode) |
| 3010 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3011 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3012 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3013 | return pnfs_roc(inode); |
| 3014 | } |
| 3015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | /* |
| 3017 | * It is possible for data to be read/written from a mem-mapped file |
| 3018 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3019 | * This means that we can't safely call nfsv4 close on a file until |
| 3020 | * the inode is cleared. This in turn means that we are not good |
| 3021 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3022 | * share state even when we are done with one of the three share |
| 3023 | * stateid's in the inode. |
| 3024 | * |
| 3025 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3026 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3027 | 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] | 3028 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3029 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3030 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3032 | struct nfs4_state_owner *sp = state->owner; |
| 3033 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3034 | struct rpc_message msg = { |
| 3035 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3036 | .rpc_cred = state->owner->so_cred, |
| 3037 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3038 | struct rpc_task_setup task_setup_data = { |
| 3039 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3040 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3041 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3042 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3043 | .flags = RPC_TASK_ASYNC, |
| 3044 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3045 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3047 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3048 | &task_setup_data.rpc_client, &msg); |
| 3049 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3050 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3052 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3053 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3054 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3056 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3058 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3059 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3060 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3061 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3062 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3063 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3064 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3065 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3066 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3067 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3068 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3069 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3070 | msg.rpc_argp = &calldata->arg; |
| 3071 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3072 | task_setup_data.callback_data = calldata; |
| 3073 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3074 | if (IS_ERR(task)) |
| 3075 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3076 | status = 0; |
| 3077 | if (wait) |
| 3078 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3079 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3080 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3081 | out_free_calldata: |
| 3082 | kfree(calldata); |
| 3083 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3084 | nfs4_put_open_state(state); |
| 3085 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3086 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3089 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3090 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3091 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3094 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3095 | |
| 3096 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3098 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3099 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3100 | |
| 3101 | nfs4_label_release_security(label); |
| 3102 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3103 | if (IS_ERR(state)) |
| 3104 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3105 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3108 | 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] | 3109 | { |
| 3110 | if (ctx->state == NULL) |
| 3111 | return; |
| 3112 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3113 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3114 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3115 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3118 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3119 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3120 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3123 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3124 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3125 | struct nfs4_server_caps_arg args = { |
| 3126 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3127 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3128 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | struct nfs4_server_caps_res res = {}; |
| 3130 | struct rpc_message msg = { |
| 3131 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3132 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | .rpc_resp = &res, |
| 3134 | }; |
| 3135 | int status; |
| 3136 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3137 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3138 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3139 | FATTR4_WORD0_LINK_SUPPORT | |
| 3140 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3141 | FATTR4_WORD0_ACLSUPPORT; |
| 3142 | if (minorversion) |
| 3143 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3144 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3145 | 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] | 3146 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3147 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3148 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3149 | case 0: |
| 3150 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3151 | res.attr_bitmask[2] = 0; |
| 3152 | break; |
| 3153 | case 1: |
| 3154 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3155 | break; |
| 3156 | case 2: |
| 3157 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3160 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3161 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3162 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3163 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3164 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3165 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3166 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3167 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | server->caps |= NFS_CAP_ACLS; |
| 3169 | if (res.has_links != 0) |
| 3170 | server->caps |= NFS_CAP_HARDLINKS; |
| 3171 | if (res.has_symlinks != 0) |
| 3172 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3173 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3174 | server->caps |= NFS_CAP_FILEID; |
| 3175 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3176 | server->caps |= NFS_CAP_MODE; |
| 3177 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3178 | server->caps |= NFS_CAP_NLINK; |
| 3179 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3180 | server->caps |= NFS_CAP_OWNER; |
| 3181 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3182 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3183 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3184 | server->caps |= NFS_CAP_ATIME; |
| 3185 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3186 | server->caps |= NFS_CAP_CTIME; |
| 3187 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3188 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3189 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3190 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3191 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3192 | #endif |
| 3193 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3194 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3195 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3196 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3197 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3198 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3199 | 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] | 3200 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3201 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3202 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3204 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | return status; |
| 3208 | } |
| 3209 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3210 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | { |
| 3212 | struct nfs4_exception exception = { }; |
| 3213 | int err; |
| 3214 | do { |
| 3215 | err = nfs4_handle_exception(server, |
| 3216 | _nfs4_server_capabilities(server, fhandle), |
| 3217 | &exception); |
| 3218 | } while (exception.retry); |
| 3219 | return err; |
| 3220 | } |
| 3221 | |
| 3222 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3223 | struct nfs_fsinfo *info) |
| 3224 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3225 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3227 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | }; |
| 3229 | struct nfs4_lookup_res res = { |
| 3230 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3231 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | .fh = fhandle, |
| 3233 | }; |
| 3234 | struct rpc_message msg = { |
| 3235 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3236 | .rpc_argp = &args, |
| 3237 | .rpc_resp = &res, |
| 3238 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3239 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3240 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3241 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3242 | /* |
| 3243 | * Process the label in the upcoming getfattr |
| 3244 | */ |
| 3245 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3246 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3247 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3248 | 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] | 3249 | } |
| 3250 | |
| 3251 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3252 | struct nfs_fsinfo *info) |
| 3253 | { |
| 3254 | struct nfs4_exception exception = { }; |
| 3255 | int err; |
| 3256 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3257 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3258 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3259 | switch (err) { |
| 3260 | case 0: |
| 3261 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3262 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3263 | default: |
| 3264 | err = nfs4_handle_exception(server, err, &exception); |
| 3265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3267 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | return err; |
| 3269 | } |
| 3270 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3271 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3272 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3273 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3274 | struct rpc_auth_create_args auth_args = { |
| 3275 | .pseudoflavor = flavor, |
| 3276 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3277 | struct rpc_auth *auth; |
| 3278 | int ret; |
| 3279 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3280 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3281 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3282 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3283 | goto out; |
| 3284 | } |
| 3285 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3286 | out: |
| 3287 | return ret; |
| 3288 | } |
| 3289 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3290 | /* |
| 3291 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3292 | * |
| 3293 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3294 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3295 | * |
| 3296 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3297 | * negative errno value. |
| 3298 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3299 | 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] | 3300 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3302 | /* Per 3530bis 15.33.5 */ |
| 3303 | static const rpc_authflavor_t flav_array[] = { |
| 3304 | RPC_AUTH_GSS_KRB5P, |
| 3305 | RPC_AUTH_GSS_KRB5I, |
| 3306 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3307 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3308 | RPC_AUTH_NULL, |
| 3309 | }; |
| 3310 | int status = -EPERM; |
| 3311 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3313 | if (server->auth_info.flavor_len > 0) { |
| 3314 | /* try each flavor specified by user */ |
| 3315 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3316 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3317 | server->auth_info.flavors[i]); |
| 3318 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3319 | continue; |
| 3320 | break; |
| 3321 | } |
| 3322 | } else { |
| 3323 | /* no flavors specified by user, try default list */ |
| 3324 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3325 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3326 | flav_array[i]); |
| 3327 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3328 | continue; |
| 3329 | break; |
| 3330 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3331 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3332 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3333 | /* |
| 3334 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3335 | * to access the mount. It could also mean that we tried to mount |
| 3336 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3337 | * existing mount programs don't handle -EACCES very well so it should |
| 3338 | * be mapped to -EPERM instead. |
| 3339 | */ |
| 3340 | if (status == -EACCES) |
| 3341 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3342 | return status; |
| 3343 | } |
| 3344 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3345 | /** |
| 3346 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3347 | * @server: initialized nfs_server handle |
| 3348 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3349 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3350 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3351 | * |
| 3352 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3353 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3354 | 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] | 3355 | struct nfs_fsinfo *info, |
| 3356 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3357 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3358 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3359 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3360 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3361 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3362 | |
| 3363 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3364 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3365 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | if (status == 0) |
| 3368 | status = nfs4_server_capabilities(server, fhandle); |
| 3369 | if (status == 0) |
| 3370 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3371 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3372 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3375 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3376 | struct nfs_fsinfo *info) |
| 3377 | { |
| 3378 | int error; |
| 3379 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3380 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3381 | |
| 3382 | error = nfs4_server_capabilities(server, mntfh); |
| 3383 | if (error < 0) { |
| 3384 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3385 | return error; |
| 3386 | } |
| 3387 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3388 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3389 | if (IS_ERR(label)) |
| 3390 | return PTR_ERR(label); |
| 3391 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3392 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3393 | if (error < 0) { |
| 3394 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3395 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3399 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3400 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3401 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3402 | err_free_label: |
| 3403 | nfs4_label_free(label); |
| 3404 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3405 | return error; |
| 3406 | } |
| 3407 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3408 | /* |
| 3409 | * Get locations and (maybe) other attributes of a referral. |
| 3410 | * Note that we'll actually follow the referral later when |
| 3411 | * we detect fsid mismatch in inode revalidation |
| 3412 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3413 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3414 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3415 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3416 | { |
| 3417 | int status = -ENOMEM; |
| 3418 | struct page *page = NULL; |
| 3419 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3420 | |
| 3421 | page = alloc_page(GFP_KERNEL); |
| 3422 | if (page == NULL) |
| 3423 | goto out; |
| 3424 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3425 | if (locations == NULL) |
| 3426 | goto out; |
| 3427 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3428 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3429 | if (status != 0) |
| 3430 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3431 | |
| 3432 | /* |
| 3433 | * If the fsid didn't change, this is a migration event, not a |
| 3434 | * referral. Cause us to drop into the exception handler, which |
| 3435 | * will kick off migration recovery. |
| 3436 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3437 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3438 | dprintk("%s: server did not return a different fsid for" |
| 3439 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3440 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3441 | goto out; |
| 3442 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3443 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3444 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3445 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3446 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3447 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3448 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3449 | out: |
| 3450 | if (page) |
| 3451 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3452 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3453 | return status; |
| 3454 | } |
| 3455 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3456 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3457 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | { |
| 3459 | struct nfs4_getattr_arg args = { |
| 3460 | .fh = fhandle, |
| 3461 | .bitmask = server->attr_bitmask, |
| 3462 | }; |
| 3463 | struct nfs4_getattr_res res = { |
| 3464 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3465 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | .server = server, |
| 3467 | }; |
| 3468 | struct rpc_message msg = { |
| 3469 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3470 | .rpc_argp = &args, |
| 3471 | .rpc_resp = &res, |
| 3472 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3473 | |
| 3474 | args.bitmask = nfs4_bitmask(server, label); |
| 3475 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3476 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3477 | 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] | 3478 | } |
| 3479 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3480 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3481 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | { |
| 3483 | struct nfs4_exception exception = { }; |
| 3484 | int err; |
| 3485 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3486 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3487 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3488 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | &exception); |
| 3490 | } while (exception.retry); |
| 3491 | return err; |
| 3492 | } |
| 3493 | |
| 3494 | /* |
| 3495 | * The file is not closed if it is opened due to the a request to change |
| 3496 | * the size of the file. The open call will not be needed once the |
| 3497 | * VFS layer lookup-intents are implemented. |
| 3498 | * |
| 3499 | * Close is called when the inode is destroyed. |
| 3500 | * If we haven't opened the file for O_WRONLY, we |
| 3501 | * need to in the size_change case to obtain a stateid. |
| 3502 | * |
| 3503 | * Got race? |
| 3504 | * Because OPEN is always done by name in nfsv4, it is |
| 3505 | * possible that we opened a different file by the same |
| 3506 | * name. We can recognize this race condition, but we |
| 3507 | * can't do anything about it besides returning an error. |
| 3508 | * |
| 3509 | * This will be fixed with VFS changes (lookup-intent). |
| 3510 | */ |
| 3511 | static int |
| 3512 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3513 | struct iattr *sattr) |
| 3514 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3515 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3516 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3517 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3518 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | int status; |
| 3520 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3521 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3522 | sattr->ia_valid & ATTR_SIZE && |
| 3523 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3524 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3525 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3526 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3528 | /* Deal with open(O_TRUNC) */ |
| 3529 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3530 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3531 | |
| 3532 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3533 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3534 | return 0; |
| 3535 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3536 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3537 | if (sattr->ia_valid & ATTR_FILE) { |
| 3538 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3539 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3540 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3541 | if (ctx) { |
| 3542 | cred = ctx->cred; |
| 3543 | state = ctx->state; |
| 3544 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3545 | } |
| 3546 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3547 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3548 | if (IS_ERR(label)) |
| 3549 | return PTR_ERR(label); |
| 3550 | |
| 3551 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3552 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3553 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3554 | nfs_setsecurity(inode, fattr, label); |
| 3555 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3556 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return status; |
| 3558 | } |
| 3559 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3560 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3561 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3562 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3563 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3564 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3565 | int status; |
| 3566 | struct nfs4_lookup_arg args = { |
| 3567 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3568 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3569 | .name = name, |
| 3570 | }; |
| 3571 | struct nfs4_lookup_res res = { |
| 3572 | .server = server, |
| 3573 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3574 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3575 | .fh = fhandle, |
| 3576 | }; |
| 3577 | struct rpc_message msg = { |
| 3578 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3579 | .rpc_argp = &args, |
| 3580 | .rpc_resp = &res, |
| 3581 | }; |
| 3582 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3583 | args.bitmask = nfs4_bitmask(server, label); |
| 3584 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3585 | nfs_fattr_init(fattr); |
| 3586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3588 | 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] | 3589 | dprintk("NFS reply lookup: %d\n", status); |
| 3590 | return status; |
| 3591 | } |
| 3592 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3593 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3594 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3595 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3596 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3597 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3598 | fattr->nlink = 2; |
| 3599 | } |
| 3600 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3601 | 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] | 3602 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3603 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3604 | { |
| 3605 | struct nfs4_exception exception = { }; |
| 3606 | struct rpc_clnt *client = *clnt; |
| 3607 | int err; |
| 3608 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3609 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3610 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3611 | switch (err) { |
| 3612 | case -NFS4ERR_BADNAME: |
| 3613 | err = -ENOENT; |
| 3614 | goto out; |
| 3615 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3616 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3617 | if (err == -NFS4ERR_MOVED) |
| 3618 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3619 | goto out; |
| 3620 | case -NFS4ERR_WRONGSEC: |
| 3621 | err = -EPERM; |
| 3622 | if (client != *clnt) |
| 3623 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3624 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3625 | if (IS_ERR(client)) |
| 3626 | return PTR_ERR(client); |
| 3627 | |
| 3628 | exception.retry = 1; |
| 3629 | break; |
| 3630 | default: |
| 3631 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3632 | } |
| 3633 | } while (exception.retry); |
| 3634 | |
| 3635 | out: |
| 3636 | if (err == 0) |
| 3637 | *clnt = client; |
| 3638 | else if (client != *clnt) |
| 3639 | rpc_shutdown_client(client); |
| 3640 | |
| 3641 | return err; |
| 3642 | } |
| 3643 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3644 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3645 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3646 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3648 | int status; |
| 3649 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3650 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3651 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3652 | if (client != NFS_CLIENT(dir)) { |
| 3653 | rpc_shutdown_client(client); |
| 3654 | nfs_fixup_secinfo_attributes(fattr); |
| 3655 | } |
| 3656 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3659 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3660 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3661 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3662 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3663 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3664 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3665 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3666 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3667 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3668 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3669 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3670 | } |
| 3671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3673 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3674 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | struct nfs4_accessargs args = { |
| 3676 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3677 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3679 | struct nfs4_accessres res = { |
| 3680 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3681 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | struct rpc_message msg = { |
| 3683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3684 | .rpc_argp = &args, |
| 3685 | .rpc_resp = &res, |
| 3686 | .rpc_cred = entry->cred, |
| 3687 | }; |
| 3688 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3689 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | |
| 3691 | /* |
| 3692 | * Determine which access bits we want to ask for... |
| 3693 | */ |
| 3694 | if (mode & MAY_READ) |
| 3695 | args.access |= NFS4_ACCESS_READ; |
| 3696 | if (S_ISDIR(inode->i_mode)) { |
| 3697 | if (mode & MAY_WRITE) |
| 3698 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3699 | if (mode & MAY_EXEC) |
| 3700 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3701 | } else { |
| 3702 | if (mode & MAY_WRITE) |
| 3703 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3704 | if (mode & MAY_EXEC) |
| 3705 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3706 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3707 | |
| 3708 | res.fattr = nfs_alloc_fattr(); |
| 3709 | if (res.fattr == NULL) |
| 3710 | return -ENOMEM; |
| 3711 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3712 | 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] | 3713 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3714 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3715 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3717 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | return status; |
| 3719 | } |
| 3720 | |
| 3721 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3722 | { |
| 3723 | struct nfs4_exception exception = { }; |
| 3724 | int err; |
| 3725 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3726 | err = _nfs4_proc_access(inode, entry); |
| 3727 | trace_nfs4_access(inode, err); |
| 3728 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | &exception); |
| 3730 | } while (exception.retry); |
| 3731 | return err; |
| 3732 | } |
| 3733 | |
| 3734 | /* |
| 3735 | * TODO: For the time being, we don't try to get any attributes |
| 3736 | * along with any of the zero-copy operations READ, READDIR, |
| 3737 | * READLINK, WRITE. |
| 3738 | * |
| 3739 | * In the case of the first three, we want to put the GETATTR |
| 3740 | * after the read-type operation -- this is because it is hard |
| 3741 | * to predict the length of a GETATTR response in v4, and thus |
| 3742 | * align the READ data correctly. This means that the GETATTR |
| 3743 | * may end up partially falling into the page cache, and we should |
| 3744 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3745 | * To do this efficiently, we need to know the total length |
| 3746 | * of data received, which doesn't seem to be available outside |
| 3747 | * of the RPC layer. |
| 3748 | * |
| 3749 | * In the case of WRITE, we also want to put the GETATTR after |
| 3750 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3751 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | * |
| 3753 | * Both of these changes to the XDR layer would in fact be quite |
| 3754 | * minor, but I decided to leave them for a subsequent patch. |
| 3755 | */ |
| 3756 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3757 | unsigned int pgbase, unsigned int pglen) |
| 3758 | { |
| 3759 | struct nfs4_readlink args = { |
| 3760 | .fh = NFS_FH(inode), |
| 3761 | .pgbase = pgbase, |
| 3762 | .pglen = pglen, |
| 3763 | .pages = &page, |
| 3764 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3765 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | struct rpc_message msg = { |
| 3767 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3768 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3769 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | }; |
| 3771 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3772 | 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] | 3773 | } |
| 3774 | |
| 3775 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3776 | unsigned int pgbase, unsigned int pglen) |
| 3777 | { |
| 3778 | struct nfs4_exception exception = { }; |
| 3779 | int err; |
| 3780 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3781 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3782 | trace_nfs4_readlink(inode, err); |
| 3783 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | &exception); |
| 3785 | } while (exception.retry); |
| 3786 | return err; |
| 3787 | } |
| 3788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3790 | * 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] | 3791 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | static int |
| 3793 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3794 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3796 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3797 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | int status = 0; |
| 3800 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3801 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3802 | if (IS_ERR(ctx)) |
| 3803 | return PTR_ERR(ctx); |
| 3804 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3805 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3806 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3807 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3808 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | if (IS_ERR(state)) { |
| 3810 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3811 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3814 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3815 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | return status; |
| 3817 | } |
| 3818 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3819 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3821 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3822 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3824 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3826 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3827 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3828 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3831 | .rpc_argp = &args, |
| 3832 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3834 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3835 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3836 | 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] | 3837 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3838 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | return status; |
| 3840 | } |
| 3841 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3842 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | { |
| 3844 | struct nfs4_exception exception = { }; |
| 3845 | int err; |
| 3846 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3847 | err = _nfs4_proc_remove(dir, name); |
| 3848 | trace_nfs4_remove(dir, name, err); |
| 3849 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | &exception); |
| 3851 | } while (exception.retry); |
| 3852 | return err; |
| 3853 | } |
| 3854 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3855 | 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] | 3856 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3857 | struct nfs_server *server = NFS_SERVER(dir); |
| 3858 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3859 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3861 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3863 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3864 | |
| 3865 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3868 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3869 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3870 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3871 | &data->args.seq_args, |
| 3872 | &data->res.seq_res, |
| 3873 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3876 | 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] | 3877 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3878 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3879 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3880 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3881 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3882 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3883 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3884 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3885 | return 0; |
| 3886 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3887 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3890 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3891 | { |
| 3892 | struct nfs_server *server = NFS_SERVER(dir); |
| 3893 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3894 | struct nfs_renameres *res = msg->rpc_resp; |
| 3895 | |
| 3896 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3897 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3898 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3899 | } |
| 3900 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3901 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3902 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3903 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3904 | &data->args.seq_args, |
| 3905 | &data->res.seq_res, |
| 3906 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3910 | struct inode *new_dir) |
| 3911 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 3912 | struct nfs_renamedata *data = task->tk_calldata; |
| 3913 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3914 | |
| 3915 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3916 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3917 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3918 | return 0; |
| 3919 | |
| 3920 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3921 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3922 | return 1; |
| 3923 | } |
| 3924 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3925 | 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] | 3926 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3927 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | struct nfs4_link_arg arg = { |
| 3929 | .fh = NFS_FH(inode), |
| 3930 | .dir_fh = NFS_FH(dir), |
| 3931 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3932 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3934 | struct nfs4_link_res res = { |
| 3935 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3936 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3937 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | struct rpc_message msg = { |
| 3939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3940 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3941 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3943 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3945 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3946 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3947 | goto out; |
| 3948 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3949 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3950 | if (IS_ERR(res.label)) { |
| 3951 | status = PTR_ERR(res.label); |
| 3952 | goto out; |
| 3953 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3954 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3955 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3956 | 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] | 3957 | if (!status) { |
| 3958 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3959 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 3960 | if (!status) |
| 3961 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3962 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3963 | |
| 3964 | |
| 3965 | nfs4_label_free(res.label); |
| 3966 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3967 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3968 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | return status; |
| 3970 | } |
| 3971 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3972 | 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] | 3973 | { |
| 3974 | struct nfs4_exception exception = { }; |
| 3975 | int err; |
| 3976 | do { |
| 3977 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3978 | _nfs4_proc_link(inode, dir, name), |
| 3979 | &exception); |
| 3980 | } while (exception.retry); |
| 3981 | return err; |
| 3982 | } |
| 3983 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3984 | struct nfs4_createdata { |
| 3985 | struct rpc_message msg; |
| 3986 | struct nfs4_create_arg arg; |
| 3987 | struct nfs4_create_res res; |
| 3988 | struct nfs_fh fh; |
| 3989 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3990 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3991 | }; |
| 3992 | |
| 3993 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3994 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3995 | { |
| 3996 | struct nfs4_createdata *data; |
| 3997 | |
| 3998 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3999 | if (data != NULL) { |
| 4000 | struct nfs_server *server = NFS_SERVER(dir); |
| 4001 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4002 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4003 | if (IS_ERR(data->label)) |
| 4004 | goto out_free; |
| 4005 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4006 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4007 | data->msg.rpc_argp = &data->arg; |
| 4008 | data->msg.rpc_resp = &data->res; |
| 4009 | data->arg.dir_fh = NFS_FH(dir); |
| 4010 | data->arg.server = server; |
| 4011 | data->arg.name = name; |
| 4012 | data->arg.attrs = sattr; |
| 4013 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4014 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4015 | data->res.server = server; |
| 4016 | data->res.fh = &data->fh; |
| 4017 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4018 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4019 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4020 | } |
| 4021 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4022 | out_free: |
| 4023 | kfree(data); |
| 4024 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4028 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4029 | 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] | 4030 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4031 | if (status == 0) { |
| 4032 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4033 | 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] | 4034 | } |
| 4035 | return status; |
| 4036 | } |
| 4037 | |
| 4038 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4039 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4040 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4041 | kfree(data); |
| 4042 | } |
| 4043 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4044 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4045 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4046 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4048 | struct nfs4_createdata *data; |
| 4049 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4051 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4052 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4053 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4054 | status = -ENOMEM; |
| 4055 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4056 | if (data == NULL) |
| 4057 | goto out; |
| 4058 | |
| 4059 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4060 | data->arg.u.symlink.pages = &page; |
| 4061 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4062 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4064 | status = nfs4_do_create(dir, dentry, data); |
| 4065 | |
| 4066 | nfs4_free_createdata(data); |
| 4067 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | return status; |
| 4069 | } |
| 4070 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4071 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4072 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | { |
| 4074 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4075 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4077 | |
| 4078 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4081 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4082 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4083 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | &exception); |
| 4085 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4086 | |
| 4087 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | return err; |
| 4089 | } |
| 4090 | |
| 4091 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4092 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4094 | struct nfs4_createdata *data; |
| 4095 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4097 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4098 | if (data == NULL) |
| 4099 | goto out; |
| 4100 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4101 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4102 | status = nfs4_do_create(dir, dentry, data); |
| 4103 | |
| 4104 | nfs4_free_createdata(data); |
| 4105 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | return status; |
| 4107 | } |
| 4108 | |
| 4109 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4110 | struct iattr *sattr) |
| 4111 | { |
| 4112 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4113 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4115 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4116 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4117 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4118 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4120 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4121 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4122 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | &exception); |
| 4124 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4125 | nfs4_label_release_security(label); |
| 4126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | return err; |
| 4128 | } |
| 4129 | |
| 4130 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4131 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4133 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | struct nfs4_readdir_arg args = { |
| 4135 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4136 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | .pgbase = 0, |
| 4138 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4139 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4140 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | }; |
| 4142 | struct nfs4_readdir_res res; |
| 4143 | struct rpc_message msg = { |
| 4144 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4145 | .rpc_argp = &args, |
| 4146 | .rpc_resp = &res, |
| 4147 | .rpc_cred = cred, |
| 4148 | }; |
| 4149 | int status; |
| 4150 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4151 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4152 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4153 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4154 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4156 | 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] | 4157 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4158 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4159 | status += args.pgbase; |
| 4160 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4161 | |
| 4162 | nfs_invalidate_atime(dir); |
| 4163 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4164 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | return status; |
| 4166 | } |
| 4167 | |
| 4168 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4169 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | { |
| 4171 | struct nfs4_exception exception = { }; |
| 4172 | int err; |
| 4173 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4174 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4175 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4176 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4177 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | &exception); |
| 4179 | } while (exception.retry); |
| 4180 | return err; |
| 4181 | } |
| 4182 | |
| 4183 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4184 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4186 | struct nfs4_createdata *data; |
| 4187 | int mode = sattr->ia_mode; |
| 4188 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4190 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4191 | if (data == NULL) |
| 4192 | goto out; |
| 4193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4195 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4197 | data->arg.ftype = NF4BLK; |
| 4198 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4199 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | } |
| 4201 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4202 | data->arg.ftype = NF4CHR; |
| 4203 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4204 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4205 | } else if (!S_ISSOCK(mode)) { |
| 4206 | status = -EINVAL; |
| 4207 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4209 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4210 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4211 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4212 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4213 | nfs4_free_createdata(data); |
| 4214 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | return status; |
| 4216 | } |
| 4217 | |
| 4218 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4219 | struct iattr *sattr, dev_t rdev) |
| 4220 | { |
| 4221 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4222 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4224 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4225 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4226 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4227 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4229 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4230 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4231 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | &exception); |
| 4233 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4234 | |
| 4235 | nfs4_label_release_security(label); |
| 4236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | return err; |
| 4238 | } |
| 4239 | |
| 4240 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4241 | struct nfs_fsstat *fsstat) |
| 4242 | { |
| 4243 | struct nfs4_statfs_arg args = { |
| 4244 | .fh = fhandle, |
| 4245 | .bitmask = server->attr_bitmask, |
| 4246 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4247 | struct nfs4_statfs_res res = { |
| 4248 | .fsstat = fsstat, |
| 4249 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | struct rpc_message msg = { |
| 4251 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4252 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4253 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | }; |
| 4255 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4256 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4257 | 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] | 4258 | } |
| 4259 | |
| 4260 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4261 | { |
| 4262 | struct nfs4_exception exception = { }; |
| 4263 | int err; |
| 4264 | do { |
| 4265 | err = nfs4_handle_exception(server, |
| 4266 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4267 | &exception); |
| 4268 | } while (exception.retry); |
| 4269 | return err; |
| 4270 | } |
| 4271 | |
| 4272 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4273 | struct nfs_fsinfo *fsinfo) |
| 4274 | { |
| 4275 | struct nfs4_fsinfo_arg args = { |
| 4276 | .fh = fhandle, |
| 4277 | .bitmask = server->attr_bitmask, |
| 4278 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4279 | struct nfs4_fsinfo_res res = { |
| 4280 | .fsinfo = fsinfo, |
| 4281 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | struct rpc_message msg = { |
| 4283 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4284 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4285 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | }; |
| 4287 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4288 | 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] | 4289 | } |
| 4290 | |
| 4291 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4292 | { |
| 4293 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4294 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | int err; |
| 4296 | |
| 4297 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4298 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4299 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4300 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4301 | nfs4_set_lease_period(server->nfs_client, |
| 4302 | fsinfo->lease_time * HZ, |
| 4303 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4304 | break; |
| 4305 | } |
| 4306 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | } while (exception.retry); |
| 4308 | return err; |
| 4309 | } |
| 4310 | |
| 4311 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4312 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4313 | int error; |
| 4314 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4315 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4316 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4317 | if (error == 0) { |
| 4318 | /* block layout checks this! */ |
| 4319 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4320 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4321 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4322 | |
| 4323 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4327 | struct nfs_pathconf *pathconf) |
| 4328 | { |
| 4329 | struct nfs4_pathconf_arg args = { |
| 4330 | .fh = fhandle, |
| 4331 | .bitmask = server->attr_bitmask, |
| 4332 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4333 | struct nfs4_pathconf_res res = { |
| 4334 | .pathconf = pathconf, |
| 4335 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | struct rpc_message msg = { |
| 4337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4338 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4339 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | }; |
| 4341 | |
| 4342 | /* None of the pathconf attributes are mandatory to implement */ |
| 4343 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4344 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4345 | return 0; |
| 4346 | } |
| 4347 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4348 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4349 | 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] | 4350 | } |
| 4351 | |
| 4352 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4353 | struct nfs_pathconf *pathconf) |
| 4354 | { |
| 4355 | struct nfs4_exception exception = { }; |
| 4356 | int err; |
| 4357 | |
| 4358 | do { |
| 4359 | err = nfs4_handle_exception(server, |
| 4360 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4361 | &exception); |
| 4362 | } while (exception.retry); |
| 4363 | return err; |
| 4364 | } |
| 4365 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4366 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4367 | const struct nfs_open_context *ctx, |
| 4368 | const struct nfs_lock_context *l_ctx, |
| 4369 | fmode_t fmode) |
| 4370 | { |
| 4371 | const struct nfs_lockowner *lockowner = NULL; |
| 4372 | |
| 4373 | if (l_ctx != NULL) |
| 4374 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4375 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4376 | } |
| 4377 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4378 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4379 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4380 | const struct nfs_open_context *ctx, |
| 4381 | const struct nfs_lock_context *l_ctx, |
| 4382 | fmode_t fmode) |
| 4383 | { |
| 4384 | nfs4_stateid current_stateid; |
| 4385 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4386 | /* If the current stateid represents a lost lock, then exit */ |
| 4387 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4388 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4389 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4390 | } |
| 4391 | |
| 4392 | static bool nfs4_error_stateid_expired(int err) |
| 4393 | { |
| 4394 | switch (err) { |
| 4395 | case -NFS4ERR_DELEG_REVOKED: |
| 4396 | case -NFS4ERR_ADMIN_REVOKED: |
| 4397 | case -NFS4ERR_BAD_STATEID: |
| 4398 | case -NFS4ERR_STALE_STATEID: |
| 4399 | case -NFS4ERR_OLD_STATEID: |
| 4400 | case -NFS4ERR_OPENMODE: |
| 4401 | case -NFS4ERR_EXPIRED: |
| 4402 | return true; |
| 4403 | } |
| 4404 | return false; |
| 4405 | } |
| 4406 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4407 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4408 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4409 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4410 | } |
| 4411 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4412 | 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] | 4413 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4414 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4416 | trace_nfs4_read(hdr, task->tk_status); |
| 4417 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4418 | hdr->args.context->state, |
| 4419 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4420 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4421 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4423 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4424 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4426 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4427 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | } |
| 4429 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4430 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4431 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4432 | { |
| 4433 | |
| 4434 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4435 | nfs4_stateid_is_current(&args->stateid, |
| 4436 | args->context, |
| 4437 | args->lock_context, |
| 4438 | FMODE_READ)) |
| 4439 | return false; |
| 4440 | rpc_restart_call_prepare(task); |
| 4441 | return true; |
| 4442 | } |
| 4443 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4444 | 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] | 4445 | { |
| 4446 | |
| 4447 | dprintk("--> %s\n", __func__); |
| 4448 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4449 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4450 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4451 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4452 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4453 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4454 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4457 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4458 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4460 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4461 | if (!hdr->pgio_done_cb) |
| 4462 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4463 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4464 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4467 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4468 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4469 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4470 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4471 | &hdr->args.seq_args, |
| 4472 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4473 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4474 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4475 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4476 | hdr->args.lock_context, |
| 4477 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4478 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4479 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4480 | return -EIO; |
| 4481 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | } |
| 4483 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4484 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4485 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4487 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4488 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4489 | trace_nfs4_write(hdr, task->tk_status); |
| 4490 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4491 | hdr->args.context->state, |
| 4492 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4493 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4494 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4496 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4497 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4498 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4499 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4500 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | } |
| 4502 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4503 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4504 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4505 | { |
| 4506 | |
| 4507 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4508 | nfs4_stateid_is_current(&args->stateid, |
| 4509 | args->context, |
| 4510 | args->lock_context, |
| 4511 | FMODE_WRITE)) |
| 4512 | return false; |
| 4513 | rpc_restart_call_prepare(task); |
| 4514 | return true; |
| 4515 | } |
| 4516 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4517 | 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] | 4518 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4519 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4520 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4521 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4522 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4523 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4524 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4525 | } |
| 4526 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4527 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4528 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4529 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4530 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4531 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4532 | return false; |
| 4533 | /* Otherwise, request attributes if and only if we don't hold |
| 4534 | * a delegation |
| 4535 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4536 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4537 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4538 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4539 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4540 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4542 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4543 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4544 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4545 | hdr->args.bitmask = NULL; |
| 4546 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4547 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4548 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4549 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4550 | if (!hdr->pgio_done_cb) |
| 4551 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4552 | hdr->res.server = server; |
| 4553 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4555 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4556 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } |
| 4558 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4559 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4560 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4561 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4562 | &data->args.seq_args, |
| 4563 | &data->res.seq_res, |
| 4564 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | } |
| 4566 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4567 | 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] | 4568 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4570 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4571 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4572 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4573 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4574 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4575 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4577 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4580 | 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] | 4581 | { |
| 4582 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4583 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4584 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4585 | } |
| 4586 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4587 | 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] | 4588 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4589 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4590 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4591 | if (data->commit_done_cb == NULL) |
| 4592 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4593 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4594 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4595 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | } |
| 4597 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4598 | struct nfs4_renewdata { |
| 4599 | struct nfs_client *client; |
| 4600 | unsigned long timestamp; |
| 4601 | }; |
| 4602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | /* |
| 4604 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4605 | * standalone procedure for queueing an asynchronous RENEW. |
| 4606 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4607 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4608 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4609 | struct nfs4_renewdata *data = calldata; |
| 4610 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4611 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4612 | if (atomic_read(&clp->cl_count) > 1) |
| 4613 | nfs4_schedule_state_renewal(clp); |
| 4614 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4615 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4616 | } |
| 4617 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4618 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4620 | struct nfs4_renewdata *data = calldata; |
| 4621 | struct nfs_client *clp = data->client; |
| 4622 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4624 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4625 | switch (task->tk_status) { |
| 4626 | case 0: |
| 4627 | break; |
| 4628 | case -NFS4ERR_LEASE_MOVED: |
| 4629 | nfs4_schedule_lease_moved_recovery(clp); |
| 4630 | break; |
| 4631 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4632 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4633 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4634 | return; |
| 4635 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4636 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4637 | return; |
| 4638 | } |
| 4639 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4641 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4644 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4645 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4646 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4647 | }; |
| 4648 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4649 | 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] | 4650 | { |
| 4651 | struct rpc_message msg = { |
| 4652 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4653 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4654 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4656 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4658 | if (renew_flags == 0) |
| 4659 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4660 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4661 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4662 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4663 | if (data == NULL) |
| 4664 | return -ENOMEM; |
| 4665 | data->client = clp; |
| 4666 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4667 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4668 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4671 | 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] | 4672 | { |
| 4673 | struct rpc_message msg = { |
| 4674 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4675 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4676 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | }; |
| 4678 | unsigned long now = jiffies; |
| 4679 | int status; |
| 4680 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4681 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | if (status < 0) |
| 4683 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4684 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | return 0; |
| 4686 | } |
| 4687 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4688 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4689 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4690 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4693 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4694 | * 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] | 4695 | * the stack. |
| 4696 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4697 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4698 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4699 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4700 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4701 | { |
| 4702 | struct page *newpage, **spages; |
| 4703 | int rc = 0; |
| 4704 | size_t len; |
| 4705 | spages = pages; |
| 4706 | |
| 4707 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4708 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4709 | newpage = alloc_page(GFP_KERNEL); |
| 4710 | |
| 4711 | if (newpage == NULL) |
| 4712 | goto unwind; |
| 4713 | memcpy(page_address(newpage), buf, len); |
| 4714 | buf += len; |
| 4715 | buflen -= len; |
| 4716 | *pages++ = newpage; |
| 4717 | rc++; |
| 4718 | } while (buflen != 0); |
| 4719 | |
| 4720 | return rc; |
| 4721 | |
| 4722 | unwind: |
| 4723 | for(; rc > 0; rc--) |
| 4724 | __free_page(spages[rc-1]); |
| 4725 | return -ENOMEM; |
| 4726 | } |
| 4727 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4728 | struct nfs4_cached_acl { |
| 4729 | int cached; |
| 4730 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4731 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4732 | }; |
| 4733 | |
| 4734 | 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] | 4735 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4736 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4737 | |
| 4738 | spin_lock(&inode->i_lock); |
| 4739 | kfree(nfsi->nfs4_acl); |
| 4740 | nfsi->nfs4_acl = acl; |
| 4741 | spin_unlock(&inode->i_lock); |
| 4742 | } |
| 4743 | |
| 4744 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4745 | { |
| 4746 | nfs4_set_cached_acl(inode, NULL); |
| 4747 | } |
| 4748 | |
| 4749 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4750 | { |
| 4751 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4752 | struct nfs4_cached_acl *acl; |
| 4753 | int ret = -ENOENT; |
| 4754 | |
| 4755 | spin_lock(&inode->i_lock); |
| 4756 | acl = nfsi->nfs4_acl; |
| 4757 | if (acl == NULL) |
| 4758 | goto out; |
| 4759 | if (buf == NULL) /* user is just asking for length */ |
| 4760 | goto out_len; |
| 4761 | if (acl->cached == 0) |
| 4762 | goto out; |
| 4763 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4764 | if (acl->len > buflen) |
| 4765 | goto out; |
| 4766 | memcpy(buf, acl->data, acl->len); |
| 4767 | out_len: |
| 4768 | ret = acl->len; |
| 4769 | out: |
| 4770 | spin_unlock(&inode->i_lock); |
| 4771 | return ret; |
| 4772 | } |
| 4773 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4774 | 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] | 4775 | { |
| 4776 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4777 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4778 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4779 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4780 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4781 | if (acl == NULL) |
| 4782 | goto out; |
| 4783 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4784 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4785 | } else { |
| 4786 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4787 | if (acl == NULL) |
| 4788 | goto out; |
| 4789 | acl->cached = 0; |
| 4790 | } |
| 4791 | acl->len = acl_len; |
| 4792 | out: |
| 4793 | nfs4_set_cached_acl(inode, acl); |
| 4794 | } |
| 4795 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4796 | /* |
| 4797 | * The getxattr API returns the required buffer length when called with a |
| 4798 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4799 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4800 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4801 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4802 | * the cache. If not so, we throw away the page, and cache the required |
| 4803 | * length. The next getxattr call will then produce another round trip to |
| 4804 | * the server, this time with the input buf of the required size. |
| 4805 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4806 | 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] | 4807 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4808 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4809 | struct nfs_getaclargs args = { |
| 4810 | .fh = NFS_FH(inode), |
| 4811 | .acl_pages = pages, |
| 4812 | .acl_len = buflen, |
| 4813 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4814 | struct nfs_getaclres res = { |
| 4815 | .acl_len = buflen, |
| 4816 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4817 | struct rpc_message msg = { |
| 4818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4819 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4820 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4821 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4822 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4823 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4824 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4825 | /* As long as we're doing a round trip to the server anyway, |
| 4826 | * let's be prepared for a page of acl data. */ |
| 4827 | if (npages == 0) |
| 4828 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4829 | if (npages > ARRAY_SIZE(pages)) |
| 4830 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4831 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4832 | for (i = 0; i < npages; i++) { |
| 4833 | pages[i] = alloc_page(GFP_KERNEL); |
| 4834 | if (!pages[i]) |
| 4835 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4836 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4837 | |
| 4838 | /* for decoding across pages */ |
| 4839 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4840 | if (!res.acl_scratch) |
| 4841 | goto out_free; |
| 4842 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4843 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4844 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4845 | 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] | 4846 | __func__, buf, buflen, npages, args.acl_len); |
| 4847 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4848 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4849 | if (ret) |
| 4850 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4851 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4852 | /* Handle the case where the passed-in buffer is too short */ |
| 4853 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4854 | /* Did the user only issue a request for the acl length? */ |
| 4855 | if (buf == NULL) |
| 4856 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4857 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4858 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4859 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4860 | 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] | 4861 | if (buf) { |
| 4862 | if (res.acl_len > buflen) { |
| 4863 | ret = -ERANGE; |
| 4864 | goto out_free; |
| 4865 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4866 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4867 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4868 | out_ok: |
| 4869 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4870 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4871 | for (i = 0; i < npages; i++) |
| 4872 | if (pages[i]) |
| 4873 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4874 | if (res.acl_scratch) |
| 4875 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4876 | return ret; |
| 4877 | } |
| 4878 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4879 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4880 | { |
| 4881 | struct nfs4_exception exception = { }; |
| 4882 | ssize_t ret; |
| 4883 | do { |
| 4884 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4885 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4886 | if (ret >= 0) |
| 4887 | break; |
| 4888 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 4889 | } while (exception.retry); |
| 4890 | return ret; |
| 4891 | } |
| 4892 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4893 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 4894 | { |
| 4895 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4896 | int ret; |
| 4897 | |
| 4898 | if (!nfs4_server_supports_acls(server)) |
| 4899 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4900 | ret = nfs_revalidate_inode(server, inode); |
| 4901 | if (ret < 0) |
| 4902 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4903 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 4904 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4905 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 4906 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4907 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 4908 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4909 | return ret; |
| 4910 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4913 | 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] | 4914 | { |
| 4915 | struct nfs_server *server = NFS_SERVER(inode); |
| 4916 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 4917 | struct nfs_setaclargs arg = { |
| 4918 | .fh = NFS_FH(inode), |
| 4919 | .acl_pages = pages, |
| 4920 | .acl_len = buflen, |
| 4921 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4922 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4923 | struct rpc_message msg = { |
| 4924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 4925 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 4926 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4927 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4928 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4929 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4930 | |
| 4931 | if (!nfs4_server_supports_acls(server)) |
| 4932 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4933 | if (npages > ARRAY_SIZE(pages)) |
| 4934 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4935 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4936 | if (i < 0) |
| 4937 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4938 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4939 | 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] | 4940 | |
| 4941 | /* |
| 4942 | * Free each page after tx, so the only ref left is |
| 4943 | * held by the network stack |
| 4944 | */ |
| 4945 | for (; i > 0; i--) |
| 4946 | put_page(pages[i-1]); |
| 4947 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4948 | /* |
| 4949 | * Acl update can result in inode attribute update. |
| 4950 | * so mark the attribute cache invalid. |
| 4951 | */ |
| 4952 | spin_lock(&inode->i_lock); |
| 4953 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4954 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4955 | nfs_access_zap_cache(inode); |
| 4956 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4957 | return ret; |
| 4958 | } |
| 4959 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4960 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4961 | { |
| 4962 | struct nfs4_exception exception = { }; |
| 4963 | int err; |
| 4964 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4965 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 4966 | trace_nfs4_set_acl(inode, err); |
| 4967 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4968 | &exception); |
| 4969 | } while (exception.retry); |
| 4970 | return err; |
| 4971 | } |
| 4972 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4973 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 4974 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 4975 | size_t buflen) |
| 4976 | { |
| 4977 | struct nfs_server *server = NFS_SERVER(inode); |
| 4978 | struct nfs_fattr fattr; |
| 4979 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 4980 | |
| 4981 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4982 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4983 | .fh = NFS_FH(inode), |
| 4984 | .bitmask = bitmask, |
| 4985 | }; |
| 4986 | struct nfs4_getattr_res res = { |
| 4987 | .fattr = &fattr, |
| 4988 | .label = &label, |
| 4989 | .server = server, |
| 4990 | }; |
| 4991 | struct rpc_message msg = { |
| 4992 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 4993 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4994 | .rpc_resp = &res, |
| 4995 | }; |
| 4996 | int ret; |
| 4997 | |
| 4998 | nfs_fattr_init(&fattr); |
| 4999 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5000 | 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] | 5001 | if (ret) |
| 5002 | return ret; |
| 5003 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5004 | return -ENOENT; |
| 5005 | if (buflen < label.len) |
| 5006 | return -ERANGE; |
| 5007 | return 0; |
| 5008 | } |
| 5009 | |
| 5010 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5011 | size_t buflen) |
| 5012 | { |
| 5013 | struct nfs4_exception exception = { }; |
| 5014 | int err; |
| 5015 | |
| 5016 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5017 | return -EOPNOTSUPP; |
| 5018 | |
| 5019 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5020 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5021 | trace_nfs4_get_security_label(inode, err); |
| 5022 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5023 | &exception); |
| 5024 | } while (exception.retry); |
| 5025 | return err; |
| 5026 | } |
| 5027 | |
| 5028 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5029 | struct nfs4_label *ilabel, |
| 5030 | struct nfs_fattr *fattr, |
| 5031 | struct nfs4_label *olabel) |
| 5032 | { |
| 5033 | |
| 5034 | struct iattr sattr = {0}; |
| 5035 | struct nfs_server *server = NFS_SERVER(inode); |
| 5036 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5037 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5038 | .fh = NFS_FH(inode), |
| 5039 | .iap = &sattr, |
| 5040 | .server = server, |
| 5041 | .bitmask = bitmask, |
| 5042 | .label = ilabel, |
| 5043 | }; |
| 5044 | struct nfs_setattrres res = { |
| 5045 | .fattr = fattr, |
| 5046 | .label = olabel, |
| 5047 | .server = server, |
| 5048 | }; |
| 5049 | struct rpc_message msg = { |
| 5050 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5051 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5052 | .rpc_resp = &res, |
| 5053 | }; |
| 5054 | int status; |
| 5055 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5056 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5057 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5058 | 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] | 5059 | if (status) |
| 5060 | dprintk("%s failed: %d\n", __func__, status); |
| 5061 | |
| 5062 | return status; |
| 5063 | } |
| 5064 | |
| 5065 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5066 | struct nfs4_label *ilabel, |
| 5067 | struct nfs_fattr *fattr, |
| 5068 | struct nfs4_label *olabel) |
| 5069 | { |
| 5070 | struct nfs4_exception exception = { }; |
| 5071 | int err; |
| 5072 | |
| 5073 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5074 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5075 | fattr, olabel); |
| 5076 | trace_nfs4_set_security_label(inode, err); |
| 5077 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5078 | &exception); |
| 5079 | } while (exception.retry); |
| 5080 | return err; |
| 5081 | } |
| 5082 | |
| 5083 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5084 | 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] | 5085 | { |
| 5086 | struct nfs4_label ilabel, *olabel = NULL; |
| 5087 | struct nfs_fattr fattr; |
| 5088 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5089 | int status; |
| 5090 | |
| 5091 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5092 | return -EOPNOTSUPP; |
| 5093 | |
| 5094 | nfs_fattr_init(&fattr); |
| 5095 | |
| 5096 | ilabel.pi = 0; |
| 5097 | ilabel.lfs = 0; |
| 5098 | ilabel.label = (char *)buf; |
| 5099 | ilabel.len = buflen; |
| 5100 | |
| 5101 | cred = rpc_lookup_cred(); |
| 5102 | if (IS_ERR(cred)) |
| 5103 | return PTR_ERR(cred); |
| 5104 | |
| 5105 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5106 | if (IS_ERR(olabel)) { |
| 5107 | status = -PTR_ERR(olabel); |
| 5108 | goto out; |
| 5109 | } |
| 5110 | |
| 5111 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5112 | if (status == 0) |
| 5113 | nfs_setsecurity(inode, &fattr, olabel); |
| 5114 | |
| 5115 | nfs4_label_free(olabel); |
| 5116 | out: |
| 5117 | put_rpccred(cred); |
| 5118 | return status; |
| 5119 | } |
| 5120 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5121 | |
| 5122 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5123 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5124 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5125 | { |
| 5126 | __be32 verf[2]; |
| 5127 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5128 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5129 | /* An impossible timestamp guarantees this value |
| 5130 | * will never match a generated boot time. */ |
| 5131 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5132 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5133 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5134 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5135 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5136 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5137 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5138 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5139 | } |
| 5140 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5141 | static int |
| 5142 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5143 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5144 | size_t len; |
| 5145 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5146 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5147 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5148 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5149 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5150 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5151 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5152 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5153 | 1 + |
| 5154 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5155 | 1; |
| 5156 | rcu_read_unlock(); |
| 5157 | |
| 5158 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5159 | return -EINVAL; |
| 5160 | |
| 5161 | /* |
| 5162 | * Since this string is allocated at mount time, and held until the |
| 5163 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5164 | * about a memory-reclaim deadlock. |
| 5165 | */ |
| 5166 | str = kmalloc(len, GFP_KERNEL); |
| 5167 | if (!str) |
| 5168 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5169 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5170 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5171 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5172 | clp->cl_ipaddr, |
| 5173 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5174 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5175 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5176 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5177 | clp->cl_owner_id = str; |
| 5178 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5179 | } |
| 5180 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5181 | static int |
| 5182 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5183 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5184 | size_t len; |
| 5185 | char *str; |
| 5186 | |
| 5187 | len = 10 + 10 + 1 + 10 + 1 + |
| 5188 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5189 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5190 | |
| 5191 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5192 | return -EINVAL; |
| 5193 | |
| 5194 | /* |
| 5195 | * Since this string is allocated at mount time, and held until the |
| 5196 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5197 | * about a memory-reclaim deadlock. |
| 5198 | */ |
| 5199 | str = kmalloc(len, GFP_KERNEL); |
| 5200 | if (!str) |
| 5201 | return -ENOMEM; |
| 5202 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5203 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5204 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5205 | nfs4_client_id_uniquifier, |
| 5206 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5207 | clp->cl_owner_id = str; |
| 5208 | return 0; |
| 5209 | } |
| 5210 | |
| 5211 | static int |
| 5212 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5213 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5214 | size_t len; |
| 5215 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5216 | |
| 5217 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5218 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5219 | |
| 5220 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5221 | return nfs4_init_uniquifier_client_string(clp); |
| 5222 | |
| 5223 | len = 10 + 10 + 1 + 10 + 1 + |
| 5224 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5225 | |
| 5226 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5227 | return -EINVAL; |
| 5228 | |
| 5229 | /* |
| 5230 | * Since this string is allocated at mount time, and held until the |
| 5231 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5232 | * about a memory-reclaim deadlock. |
| 5233 | */ |
| 5234 | str = kmalloc(len, GFP_KERNEL); |
| 5235 | if (!str) |
| 5236 | return -ENOMEM; |
| 5237 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5238 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5239 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5240 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5241 | clp->cl_owner_id = str; |
| 5242 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5243 | } |
| 5244 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5245 | /* |
| 5246 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5247 | * services. Advertise one based on the address family of the |
| 5248 | * clientaddr. |
| 5249 | */ |
| 5250 | static unsigned int |
| 5251 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5252 | { |
| 5253 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5254 | return scnprintf(buf, len, "tcp6"); |
| 5255 | else |
| 5256 | return scnprintf(buf, len, "tcp"); |
| 5257 | } |
| 5258 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5259 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5260 | { |
| 5261 | struct nfs4_setclientid *sc = calldata; |
| 5262 | |
| 5263 | if (task->tk_status == 0) |
| 5264 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5265 | } |
| 5266 | |
| 5267 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5268 | .rpc_call_done = nfs4_setclientid_done, |
| 5269 | }; |
| 5270 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5271 | /** |
| 5272 | * nfs4_proc_setclientid - Negotiate client ID |
| 5273 | * @clp: state data structure |
| 5274 | * @program: RPC program for NFSv4 callback service |
| 5275 | * @port: IP port number for NFS4 callback service |
| 5276 | * @cred: RPC credential to use for this call |
| 5277 | * @res: where to place the result |
| 5278 | * |
| 5279 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5280 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5281 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5282 | unsigned short port, struct rpc_cred *cred, |
| 5283 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5284 | { |
| 5285 | nfs4_verifier sc_verifier; |
| 5286 | struct nfs4_setclientid setclientid = { |
| 5287 | .sc_verifier = &sc_verifier, |
| 5288 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5289 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | }; |
| 5291 | struct rpc_message msg = { |
| 5292 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5293 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5294 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5295 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5297 | struct rpc_task *task; |
| 5298 | struct rpc_task_setup task_setup_data = { |
| 5299 | .rpc_client = clp->cl_rpcclient, |
| 5300 | .rpc_message = &msg, |
| 5301 | .callback_ops = &nfs4_setclientid_ops, |
| 5302 | .callback_data = &setclientid, |
| 5303 | .flags = RPC_TASK_TIMEOUT, |
| 5304 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5305 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5307 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5308 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5309 | |
| 5310 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5311 | status = nfs4_init_uniform_client_string(clp); |
| 5312 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5313 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5314 | |
| 5315 | if (status) |
| 5316 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5317 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5318 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5319 | setclientid.sc_netid_len = |
| 5320 | nfs4_init_callback_netid(clp, |
| 5321 | setclientid.sc_netid, |
| 5322 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5323 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5324 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5326 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5327 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5328 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5329 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5330 | task = rpc_run_task(&task_setup_data); |
| 5331 | if (IS_ERR(task)) { |
| 5332 | status = PTR_ERR(task); |
| 5333 | goto out; |
| 5334 | } |
| 5335 | status = task->tk_status; |
| 5336 | if (setclientid.sc_cred) { |
| 5337 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5338 | put_rpccred(setclientid.sc_cred); |
| 5339 | } |
| 5340 | rpc_put_task(task); |
| 5341 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5342 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5343 | dprintk("NFS reply setclientid: %d\n", status); |
| 5344 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | } |
| 5346 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5347 | /** |
| 5348 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5349 | * @clp: state data structure |
| 5350 | * @res: result of a previous SETCLIENTID |
| 5351 | * @cred: RPC credential to use for this call |
| 5352 | * |
| 5353 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5354 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5355 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5356 | struct nfs4_setclientid_res *arg, |
| 5357 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | struct rpc_message msg = { |
| 5360 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5361 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5362 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | int status; |
| 5365 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5366 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5367 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5368 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5369 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5370 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5371 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | return status; |
| 5373 | } |
| 5374 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5375 | struct nfs4_delegreturndata { |
| 5376 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5377 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5378 | struct nfs_fh fh; |
| 5379 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5380 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5381 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5382 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5383 | struct inode *inode; |
| 5384 | bool roc; |
| 5385 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5386 | }; |
| 5387 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5388 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5389 | { |
| 5390 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5391 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5392 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5393 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5394 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5395 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5396 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5397 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5398 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5399 | case -NFS4ERR_ADMIN_REVOKED: |
| 5400 | case -NFS4ERR_DELEG_REVOKED: |
| 5401 | case -NFS4ERR_BAD_STATEID: |
| 5402 | case -NFS4ERR_OLD_STATEID: |
| 5403 | case -NFS4ERR_STALE_STATEID: |
| 5404 | case -NFS4ERR_EXPIRED: |
| 5405 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5406 | if (data->roc) |
| 5407 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5408 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5409 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5410 | if (nfs4_async_handle_error(task, data->res.server, |
| 5411 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5412 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5413 | return; |
| 5414 | } |
| 5415 | } |
| 5416 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | static void nfs4_delegreturn_release(void *calldata) |
| 5420 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5421 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5422 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5423 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5424 | if (inode) { |
| 5425 | if (data->roc) |
| 5426 | pnfs_roc_release(inode); |
| 5427 | nfs_iput_and_deactive(inode); |
| 5428 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5429 | kfree(calldata); |
| 5430 | } |
| 5431 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5432 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5433 | { |
| 5434 | struct nfs4_delegreturndata *d_data; |
| 5435 | |
| 5436 | d_data = (struct nfs4_delegreturndata *)data; |
| 5437 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5438 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5439 | return; |
| 5440 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5441 | if (d_data->roc) |
| 5442 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5443 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5444 | nfs4_setup_sequence(d_data->res.server, |
| 5445 | &d_data->args.seq_args, |
| 5446 | &d_data->res.seq_res, |
| 5447 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5448 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5449 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5450 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5451 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5452 | .rpc_call_done = nfs4_delegreturn_done, |
| 5453 | .rpc_release = nfs4_delegreturn_release, |
| 5454 | }; |
| 5455 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5456 | 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] | 5457 | { |
| 5458 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5459 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5460 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5461 | struct rpc_message msg = { |
| 5462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5463 | .rpc_cred = cred, |
| 5464 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5465 | struct rpc_task_setup task_setup_data = { |
| 5466 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5467 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5468 | .callback_ops = &nfs4_delegreturn_ops, |
| 5469 | .flags = RPC_TASK_ASYNC, |
| 5470 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5471 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5472 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5473 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5474 | if (data == NULL) |
| 5475 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5476 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5477 | |
| 5478 | nfs4_state_protect(server->nfs_client, |
| 5479 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5480 | &task_setup_data.rpc_client, &msg); |
| 5481 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5482 | data->args.fhandle = &data->fh; |
| 5483 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5484 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5485 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5486 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5487 | data->res.fattr = &data->fattr; |
| 5488 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5489 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5490 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5491 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5492 | data->inode = nfs_igrab_and_active(inode); |
| 5493 | if (data->inode) |
| 5494 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5495 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5496 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5497 | msg.rpc_argp = &data->args; |
| 5498 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5499 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5500 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5501 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5502 | if (!issync) |
| 5503 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5504 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5505 | if (status != 0) |
| 5506 | goto out; |
| 5507 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5508 | if (status == 0) |
| 5509 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5510 | else |
| 5511 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5512 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5513 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5514 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5517 | 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] | 5518 | { |
| 5519 | struct nfs_server *server = NFS_SERVER(inode); |
| 5520 | struct nfs4_exception exception = { }; |
| 5521 | int err; |
| 5522 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5523 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5524 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | switch (err) { |
| 5526 | case -NFS4ERR_STALE_STATEID: |
| 5527 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | case 0: |
| 5529 | return 0; |
| 5530 | } |
| 5531 | err = nfs4_handle_exception(server, err, &exception); |
| 5532 | } while (exception.retry); |
| 5533 | return err; |
| 5534 | } |
| 5535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5537 | { |
| 5538 | struct inode *inode = state->inode; |
| 5539 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5540 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5541 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5543 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5545 | struct nfs_lockt_res res = { |
| 5546 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | }; |
| 5548 | struct rpc_message msg = { |
| 5549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5550 | .rpc_argp = &arg, |
| 5551 | .rpc_resp = &res, |
| 5552 | .rpc_cred = state->owner->so_cred, |
| 5553 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | struct nfs4_lock_state *lsp; |
| 5555 | int status; |
| 5556 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5557 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5558 | status = nfs4_set_lock_state(state, request); |
| 5559 | if (status != 0) |
| 5560 | goto out; |
| 5561 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5562 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5563 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5564 | 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] | 5565 | switch (status) { |
| 5566 | case 0: |
| 5567 | request->fl_type = F_UNLCK; |
| 5568 | break; |
| 5569 | case -NFS4ERR_DENIED: |
| 5570 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5572 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5573 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5574 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | return status; |
| 5576 | } |
| 5577 | |
| 5578 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5579 | { |
| 5580 | struct nfs4_exception exception = { }; |
| 5581 | int err; |
| 5582 | |
| 5583 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5584 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5585 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5586 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | &exception); |
| 5588 | } while (exception.retry); |
| 5589 | return err; |
| 5590 | } |
| 5591 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5592 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5593 | struct nfs_locku_args arg; |
| 5594 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5595 | struct nfs4_lock_state *lsp; |
| 5596 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5597 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5598 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5599 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5600 | }; |
| 5601 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5602 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5603 | struct nfs_open_context *ctx, |
| 5604 | struct nfs4_lock_state *lsp, |
| 5605 | struct nfs_seqid *seqid) |
| 5606 | { |
| 5607 | struct nfs4_unlockdata *p; |
| 5608 | struct inode *inode = lsp->ls_state->inode; |
| 5609 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5610 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5611 | if (p == NULL) |
| 5612 | return NULL; |
| 5613 | p->arg.fh = NFS_FH(inode); |
| 5614 | p->arg.fl = &p->fl; |
| 5615 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5616 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5617 | p->lsp = lsp; |
| 5618 | atomic_inc(&lsp->ls_count); |
| 5619 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5620 | p->ctx = get_nfs_open_context(ctx); |
| 5621 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5622 | p->server = NFS_SERVER(inode); |
| 5623 | return p; |
| 5624 | } |
| 5625 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5626 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5627 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5628 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5629 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5630 | nfs4_put_lock_state(calldata->lsp); |
| 5631 | put_nfs_open_context(calldata->ctx); |
| 5632 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5635 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5636 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5637 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5638 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5639 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5640 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5641 | switch (task->tk_status) { |
| 5642 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5643 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5644 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5645 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5646 | &calldata->res.stateid)) |
| 5647 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5648 | case -NFS4ERR_BAD_STATEID: |
| 5649 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5650 | case -NFS4ERR_STALE_STATEID: |
| 5651 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5652 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5653 | &calldata->lsp->ls_stateid)) |
| 5654 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5655 | break; |
| 5656 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5657 | if (nfs4_async_handle_error(task, calldata->server, |
| 5658 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5659 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5660 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5661 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5662 | } |
| 5663 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5664 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5665 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5666 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5668 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5669 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5670 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5671 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5672 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5673 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5674 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5675 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5676 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5677 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5678 | &calldata->res.seq_res, |
| 5679 | task) != 0) |
| 5680 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5681 | return; |
| 5682 | out_no_action: |
| 5683 | task->tk_action = NULL; |
| 5684 | out_wait: |
| 5685 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5688 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5689 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5690 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5691 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5692 | }; |
| 5693 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5694 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5695 | struct nfs_open_context *ctx, |
| 5696 | struct nfs4_lock_state *lsp, |
| 5697 | struct nfs_seqid *seqid) |
| 5698 | { |
| 5699 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5700 | struct rpc_message msg = { |
| 5701 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5702 | .rpc_cred = ctx->cred, |
| 5703 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5704 | struct rpc_task_setup task_setup_data = { |
| 5705 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5706 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5707 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5708 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5709 | .flags = RPC_TASK_ASYNC, |
| 5710 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5711 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5712 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5713 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5714 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5715 | /* Ensure this is an unlock - when canceling a lock, the |
| 5716 | * canceled lock is passed in, and it won't be an unlock. |
| 5717 | */ |
| 5718 | fl->fl_type = F_UNLCK; |
| 5719 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5720 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5721 | if (data == NULL) { |
| 5722 | nfs_free_seqid(seqid); |
| 5723 | return ERR_PTR(-ENOMEM); |
| 5724 | } |
| 5725 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5726 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5727 | msg.rpc_argp = &data->arg; |
| 5728 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5729 | task_setup_data.callback_data = data; |
| 5730 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5731 | } |
| 5732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5734 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5735 | struct inode *inode = state->inode; |
| 5736 | struct nfs4_state_owner *sp = state->owner; |
| 5737 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5738 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5739 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5740 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5741 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5742 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5743 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5745 | status = nfs4_set_lock_state(state, request); |
| 5746 | /* Unlock _before_ we do the RPC call */ |
| 5747 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5748 | /* Exclude nfs_delegation_claim_locks() */ |
| 5749 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5750 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5751 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5752 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5753 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5754 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5755 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5756 | } |
| 5757 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5758 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5759 | if (status != 0) |
| 5760 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5761 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5762 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5763 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5764 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5765 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5766 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5767 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5768 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5769 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5770 | 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] | 5771 | status = PTR_ERR(task); |
| 5772 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5773 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5774 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5775 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5776 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5777 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5778 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5779 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5782 | struct nfs4_lockdata { |
| 5783 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5784 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5785 | struct nfs4_lock_state *lsp; |
| 5786 | struct nfs_open_context *ctx; |
| 5787 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5788 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5789 | int rpc_status; |
| 5790 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5791 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5792 | }; |
| 5793 | |
| 5794 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5795 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5796 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5797 | { |
| 5798 | struct nfs4_lockdata *p; |
| 5799 | struct inode *inode = lsp->ls_state->inode; |
| 5800 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5801 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5802 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5803 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5804 | if (p == NULL) |
| 5805 | return NULL; |
| 5806 | |
| 5807 | p->arg.fh = NFS_FH(inode); |
| 5808 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5809 | 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] | 5810 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5811 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5812 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5813 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5814 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5815 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5816 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5817 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5818 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5819 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5820 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5821 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5822 | atomic_inc(&lsp->ls_count); |
| 5823 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5824 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5825 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5826 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5827 | out_free_seqid: |
| 5828 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5829 | out_free: |
| 5830 | kfree(p); |
| 5831 | return NULL; |
| 5832 | } |
| 5833 | |
| 5834 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5835 | { |
| 5836 | struct nfs4_lockdata *data = calldata; |
| 5837 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5838 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5839 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5840 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5841 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5842 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5843 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5844 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5845 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5846 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5847 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5848 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5849 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5850 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5851 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5852 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5853 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5854 | &data->lsp->ls_stateid); |
| 5855 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5856 | if (!nfs4_valid_open_stateid(state)) { |
| 5857 | data->rpc_status = -EBADF; |
| 5858 | task->tk_action = NULL; |
| 5859 | goto out_release_open_seqid; |
| 5860 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5861 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5862 | if (nfs4_setup_sequence(data->server, |
| 5863 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5864 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5865 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5866 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5867 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5868 | nfs_release_seqid(data->arg.open_seqid); |
| 5869 | out_release_lock_seqid: |
| 5870 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5871 | out_wait: |
| 5872 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5873 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5874 | } |
| 5875 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5876 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5877 | { |
| 5878 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5879 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5880 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5881 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5882 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5883 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5884 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5885 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5886 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5887 | switch (task->tk_status) { |
| 5888 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 5889 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5890 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5891 | if (data->arg.new_lock) { |
| 5892 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5893 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5894 | rpc_restart_call_prepare(task); |
| 5895 | break; |
| 5896 | } |
| 5897 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5898 | if (data->arg.new_lock_owner != 0) { |
| 5899 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 5900 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 5901 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 5902 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 5903 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5904 | break; |
| 5905 | case -NFS4ERR_BAD_STATEID: |
| 5906 | case -NFS4ERR_OLD_STATEID: |
| 5907 | case -NFS4ERR_STALE_STATEID: |
| 5908 | case -NFS4ERR_EXPIRED: |
| 5909 | if (data->arg.new_lock_owner != 0) { |
| 5910 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 5911 | &lsp->ls_state->open_stateid)) |
| 5912 | rpc_restart_call_prepare(task); |
| 5913 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 5914 | &lsp->ls_stateid)) |
| 5915 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5916 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5917 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | static void nfs4_lock_release(void *calldata) |
| 5921 | { |
| 5922 | struct nfs4_lockdata *data = calldata; |
| 5923 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5924 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5925 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5926 | if (data->cancelled != 0) { |
| 5927 | struct rpc_task *task; |
| 5928 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 5929 | data->arg.lock_seqid); |
| 5930 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5931 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5932 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5933 | } else |
| 5934 | nfs_free_seqid(data->arg.lock_seqid); |
| 5935 | nfs4_put_lock_state(data->lsp); |
| 5936 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5937 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5938 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5939 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 5943 | .rpc_call_prepare = nfs4_lock_prepare, |
| 5944 | .rpc_call_done = nfs4_lock_done, |
| 5945 | .rpc_release = nfs4_lock_release, |
| 5946 | }; |
| 5947 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5948 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 5949 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5950 | switch (error) { |
| 5951 | case -NFS4ERR_ADMIN_REVOKED: |
| 5952 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5953 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5954 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5955 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5956 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5957 | break; |
| 5958 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 5959 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 5960 | case -NFS4ERR_EXPIRED: |
| 5961 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 5962 | }; |
| 5963 | } |
| 5964 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5965 | 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] | 5966 | { |
| 5967 | struct nfs4_lockdata *data; |
| 5968 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5969 | struct rpc_message msg = { |
| 5970 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 5971 | .rpc_cred = state->owner->so_cred, |
| 5972 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5973 | struct rpc_task_setup task_setup_data = { |
| 5974 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5975 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5976 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5977 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5978 | .flags = RPC_TASK_ASYNC, |
| 5979 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5980 | int ret; |
| 5981 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5982 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5983 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5984 | fl->fl_u.nfs4_fl.owner, |
| 5985 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5986 | if (data == NULL) |
| 5987 | return -ENOMEM; |
| 5988 | if (IS_SETLKW(cmd)) |
| 5989 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5990 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5991 | msg.rpc_argp = &data->arg; |
| 5992 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5993 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5994 | if (recovery_type > NFS_LOCK_NEW) { |
| 5995 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5996 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5997 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5998 | } else |
| 5999 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6000 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6001 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6002 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6003 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6004 | if (ret == 0) { |
| 6005 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6006 | if (ret) |
| 6007 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6008 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6009 | } else |
| 6010 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6011 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6012 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6013 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6014 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6018 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6019 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6020 | struct nfs4_exception exception = { |
| 6021 | .inode = state->inode, |
| 6022 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6023 | int err; |
| 6024 | |
| 6025 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6026 | /* Cache the lock if possible... */ |
| 6027 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6028 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6029 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6030 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6031 | break; |
| 6032 | nfs4_handle_exception(server, err, &exception); |
| 6033 | } while (exception.retry); |
| 6034 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6038 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6039 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6040 | struct nfs4_exception exception = { |
| 6041 | .inode = state->inode, |
| 6042 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6043 | int err; |
| 6044 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6045 | err = nfs4_set_lock_state(state, request); |
| 6046 | if (err != 0) |
| 6047 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6048 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6049 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6050 | return 0; |
| 6051 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6052 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6053 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6054 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6055 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6056 | switch (err) { |
| 6057 | default: |
| 6058 | goto out; |
| 6059 | case -NFS4ERR_GRACE: |
| 6060 | case -NFS4ERR_DELAY: |
| 6061 | nfs4_handle_exception(server, err, &exception); |
| 6062 | err = 0; |
| 6063 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6064 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6065 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6066 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | } |
| 6068 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6069 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6070 | /** |
| 6071 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 6072 | * |
| 6073 | * @state: NFSv4 state for an inode |
| 6074 | * |
| 6075 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 6076 | * Otherwise a negative NFS4ERR value is returned. |
| 6077 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6078 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6079 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6080 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6081 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6082 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6083 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6084 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6085 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6086 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 6087 | |
| 6088 | status = nfs41_test_stateid(server, |
| 6089 | &lsp->ls_stateid, |
| 6090 | cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 6091 | trace_nfs4_test_lock_stateid(state, lsp, status); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6092 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 6093 | /* Free the stateid unless the server |
| 6094 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 6095 | if (status != -NFS4ERR_BAD_STATEID) |
| 6096 | nfs41_free_stateid(server, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 6097 | &lsp->ls_stateid, |
| 6098 | cred); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6099 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6100 | ret = status; |
| 6101 | } |
| 6102 | } |
| 6103 | }; |
| 6104 | |
| 6105 | return ret; |
| 6106 | } |
| 6107 | |
| 6108 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6109 | { |
| 6110 | int status = NFS_OK; |
| 6111 | |
| 6112 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 6113 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6114 | if (status != NFS_OK) |
| 6115 | status = nfs4_lock_expired(state, request); |
| 6116 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6117 | } |
| 6118 | #endif |
| 6119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6120 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6121 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6122 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6123 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6124 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6125 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6127 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6128 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6129 | if (status < 0) |
| 6130 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6131 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6132 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6133 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6134 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6135 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6136 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6137 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6138 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6139 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6140 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6141 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6142 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6143 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6144 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6145 | out: |
| 6146 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6147 | return status; |
| 6148 | } |
| 6149 | |
| 6150 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6151 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6152 | struct nfs4_exception exception = { |
| 6153 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6154 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6155 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | int err; |
| 6157 | |
| 6158 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6159 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6160 | if (err == -NFS4ERR_DENIED) |
| 6161 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6162 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6163 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6164 | } while (exception.retry); |
| 6165 | return err; |
| 6166 | } |
| 6167 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6168 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6169 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6170 | |
| 6171 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6172 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6173 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6174 | { |
| 6175 | int status = -ERESTARTSYS; |
| 6176 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6177 | |
| 6178 | while(!signalled()) { |
| 6179 | status = nfs4_proc_setlk(state, cmd, request); |
| 6180 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6181 | break; |
| 6182 | freezable_schedule_timeout_interruptible(timeout); |
| 6183 | timeout *= 2; |
| 6184 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6185 | status = -ERESTARTSYS; |
| 6186 | } |
| 6187 | return status; |
| 6188 | } |
| 6189 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6190 | #ifdef CONFIG_NFS_V4_1 |
| 6191 | struct nfs4_lock_waiter { |
| 6192 | struct task_struct *task; |
| 6193 | struct inode *inode; |
| 6194 | struct nfs_lowner *owner; |
| 6195 | bool notified; |
| 6196 | }; |
| 6197 | |
| 6198 | static int |
| 6199 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6200 | { |
| 6201 | int ret; |
| 6202 | struct cb_notify_lock_args *cbnl = key; |
| 6203 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6204 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6205 | *wowner = waiter->owner; |
| 6206 | |
| 6207 | /* Only wake if the callback was for the same owner */ |
| 6208 | if (lowner->clientid != wowner->clientid || |
| 6209 | lowner->id != wowner->id || |
| 6210 | lowner->s_dev != wowner->s_dev) |
| 6211 | return 0; |
| 6212 | |
| 6213 | /* Make sure it's for the right inode */ |
| 6214 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6215 | return 0; |
| 6216 | |
| 6217 | waiter->notified = true; |
| 6218 | |
| 6219 | /* override "private" so we can use default_wake_function */ |
| 6220 | wait->private = waiter->task; |
| 6221 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6222 | wait->private = waiter; |
| 6223 | return ret; |
| 6224 | } |
| 6225 | |
| 6226 | static int |
| 6227 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6228 | { |
| 6229 | int status = -ERESTARTSYS; |
| 6230 | unsigned long flags; |
| 6231 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6232 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6233 | struct nfs_client *clp = server->nfs_client; |
| 6234 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6235 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6236 | .id = lsp->ls_seqid.owner_id, |
| 6237 | .s_dev = server->s_dev }; |
| 6238 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6239 | .inode = state->inode, |
| 6240 | .owner = &owner, |
| 6241 | .notified = false }; |
| 6242 | wait_queue_t wait; |
| 6243 | |
| 6244 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6245 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6246 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6247 | |
| 6248 | init_wait(&wait); |
| 6249 | wait.private = &waiter; |
| 6250 | wait.func = nfs4_wake_lock_waiter; |
| 6251 | add_wait_queue(q, &wait); |
| 6252 | |
| 6253 | while(!signalled()) { |
| 6254 | status = nfs4_proc_setlk(state, cmd, request); |
| 6255 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6256 | break; |
| 6257 | |
| 6258 | status = -ERESTARTSYS; |
| 6259 | spin_lock_irqsave(&q->lock, flags); |
| 6260 | if (waiter.notified) { |
| 6261 | spin_unlock_irqrestore(&q->lock, flags); |
| 6262 | continue; |
| 6263 | } |
| 6264 | set_current_state(TASK_INTERRUPTIBLE); |
| 6265 | spin_unlock_irqrestore(&q->lock, flags); |
| 6266 | |
| 6267 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6268 | } |
| 6269 | |
| 6270 | finish_wait(q, &wait); |
| 6271 | return status; |
| 6272 | } |
| 6273 | #else /* !CONFIG_NFS_V4_1 */ |
| 6274 | static inline int |
| 6275 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6276 | { |
| 6277 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6278 | } |
| 6279 | #endif |
| 6280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | static int |
| 6282 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6283 | { |
| 6284 | struct nfs_open_context *ctx; |
| 6285 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | int status; |
| 6287 | |
| 6288 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6289 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | state = ctx->state; |
| 6291 | |
| 6292 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6293 | return -EINVAL; |
| 6294 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6295 | if (IS_GETLK(cmd)) { |
| 6296 | if (state != NULL) |
| 6297 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6298 | return 0; |
| 6299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | |
| 6301 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6302 | return -EINVAL; |
| 6303 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6304 | if (request->fl_type == F_UNLCK) { |
| 6305 | if (state != NULL) |
| 6306 | return nfs4_proc_unlck(state, cmd, request); |
| 6307 | return 0; |
| 6308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6310 | if (state == NULL) |
| 6311 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6312 | |
| 6313 | if ((request->fl_flags & FL_POSIX) && |
| 6314 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6315 | return -ENOLCK; |
| 6316 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6317 | /* |
| 6318 | * Don't rely on the VFS having checked the file open mode, |
| 6319 | * since it won't do this for flock() locks. |
| 6320 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6321 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6322 | case F_RDLCK: |
| 6323 | if (!(filp->f_mode & FMODE_READ)) |
| 6324 | return -EBADF; |
| 6325 | break; |
| 6326 | case F_WRLCK: |
| 6327 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6328 | return -EBADF; |
| 6329 | } |
| 6330 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6331 | status = nfs4_set_lock_state(state, request); |
| 6332 | if (status != 0) |
| 6333 | return status; |
| 6334 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6335 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6338 | 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] | 6339 | { |
| 6340 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6341 | int err; |
| 6342 | |
| 6343 | err = nfs4_set_lock_state(state, fl); |
| 6344 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6345 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6346 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6347 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6348 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6349 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6350 | struct nfs_release_lockowner_data { |
| 6351 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6352 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6353 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6354 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6355 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6356 | }; |
| 6357 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6358 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6359 | { |
| 6360 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6361 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6362 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6363 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6364 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6365 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6369 | { |
| 6370 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6371 | struct nfs_server *server = data->server; |
| 6372 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6373 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6374 | |
| 6375 | switch (task->tk_status) { |
| 6376 | case 0: |
| 6377 | renew_lease(server, data->timestamp); |
| 6378 | break; |
| 6379 | case -NFS4ERR_STALE_CLIENTID: |
| 6380 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6381 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6382 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6383 | case -NFS4ERR_LEASE_MOVED: |
| 6384 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6385 | if (nfs4_async_handle_error(task, server, |
| 6386 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6387 | rpc_restart_call_prepare(task); |
| 6388 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6389 | } |
| 6390 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6391 | static void nfs4_release_lockowner_release(void *calldata) |
| 6392 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6393 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6394 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6395 | kfree(calldata); |
| 6396 | } |
| 6397 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6398 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6399 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6400 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6401 | .rpc_release = nfs4_release_lockowner_release, |
| 6402 | }; |
| 6403 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6404 | static void |
| 6405 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6406 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6407 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6408 | struct rpc_message msg = { |
| 6409 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6410 | }; |
| 6411 | |
| 6412 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6413 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6414 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6415 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6416 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6417 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6418 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6419 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6420 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6421 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6422 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6423 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6424 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6425 | msg.rpc_resp = &data->res; |
| 6426 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6427 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6428 | } |
| 6429 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6430 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6431 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6432 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6433 | struct dentry *unused, struct inode *inode, |
| 6434 | const char *key, const void *buf, |
| 6435 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6436 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6437 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6438 | } |
| 6439 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6440 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6441 | struct dentry *unused, struct inode *inode, |
| 6442 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6443 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6444 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6447 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6448 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6449 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6450 | } |
| 6451 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6452 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6453 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6454 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6455 | struct dentry *unused, struct inode *inode, |
| 6456 | const char *key, const void *buf, |
| 6457 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6458 | { |
| 6459 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6460 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6461 | |
| 6462 | return -EOPNOTSUPP; |
| 6463 | } |
| 6464 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6465 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6466 | struct dentry *unused, struct inode *inode, |
| 6467 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6468 | { |
| 6469 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6470 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6471 | return -EOPNOTSUPP; |
| 6472 | } |
| 6473 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6474 | static ssize_t |
| 6475 | 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] | 6476 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6477 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6478 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6479 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6480 | len = security_inode_listsecurity(inode, list, list_len); |
| 6481 | if (list_len && len > list_len) |
| 6482 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6483 | } |
| 6484 | return len; |
| 6485 | } |
| 6486 | |
| 6487 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6488 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6489 | .get = nfs4_xattr_get_nfs4_label, |
| 6490 | .set = nfs4_xattr_set_nfs4_label, |
| 6491 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6492 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6493 | #else |
| 6494 | |
| 6495 | static ssize_t |
| 6496 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6497 | { |
| 6498 | return 0; |
| 6499 | } |
| 6500 | |
| 6501 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6502 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6503 | /* |
| 6504 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6505 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6506 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6507 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6508 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6509 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6510 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6511 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6512 | return; |
| 6513 | |
| 6514 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6515 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6516 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6517 | fattr->nlink = 2; |
| 6518 | } |
| 6519 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6520 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6521 | const struct qstr *name, |
| 6522 | struct nfs4_fs_locations *fs_locations, |
| 6523 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6524 | { |
| 6525 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6526 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6527 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6528 | }; |
| 6529 | struct nfs4_fs_locations_arg args = { |
| 6530 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6531 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6532 | .page = page, |
| 6533 | .bitmask = bitmask, |
| 6534 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6535 | struct nfs4_fs_locations_res res = { |
| 6536 | .fs_locations = fs_locations, |
| 6537 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6538 | struct rpc_message msg = { |
| 6539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6540 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6541 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6542 | }; |
| 6543 | int status; |
| 6544 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6545 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6546 | |
| 6547 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6548 | * is not supported */ |
| 6549 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6550 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6551 | else |
| 6552 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6553 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6554 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6555 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6556 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6557 | 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] | 6558 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6559 | return status; |
| 6560 | } |
| 6561 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6562 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6563 | const struct qstr *name, |
| 6564 | struct nfs4_fs_locations *fs_locations, |
| 6565 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6566 | { |
| 6567 | struct nfs4_exception exception = { }; |
| 6568 | int err; |
| 6569 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6570 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6571 | fs_locations, page); |
| 6572 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6573 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6574 | &exception); |
| 6575 | } while (exception.retry); |
| 6576 | return err; |
| 6577 | } |
| 6578 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6579 | /* |
| 6580 | * This operation also signals the server that this client is |
| 6581 | * performing migration recovery. The server can stop returning |
| 6582 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6583 | * appended to this compound to identify the client ID which is |
| 6584 | * performing recovery. |
| 6585 | */ |
| 6586 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6587 | struct nfs4_fs_locations *locations, |
| 6588 | struct page *page, struct rpc_cred *cred) |
| 6589 | { |
| 6590 | struct nfs_server *server = NFS_SERVER(inode); |
| 6591 | struct rpc_clnt *clnt = server->client; |
| 6592 | u32 bitmask[2] = { |
| 6593 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6594 | }; |
| 6595 | struct nfs4_fs_locations_arg args = { |
| 6596 | .clientid = server->nfs_client->cl_clientid, |
| 6597 | .fh = NFS_FH(inode), |
| 6598 | .page = page, |
| 6599 | .bitmask = bitmask, |
| 6600 | .migration = 1, /* skip LOOKUP */ |
| 6601 | .renew = 1, /* append RENEW */ |
| 6602 | }; |
| 6603 | struct nfs4_fs_locations_res res = { |
| 6604 | .fs_locations = locations, |
| 6605 | .migration = 1, |
| 6606 | .renew = 1, |
| 6607 | }; |
| 6608 | struct rpc_message msg = { |
| 6609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6610 | .rpc_argp = &args, |
| 6611 | .rpc_resp = &res, |
| 6612 | .rpc_cred = cred, |
| 6613 | }; |
| 6614 | unsigned long now = jiffies; |
| 6615 | int status; |
| 6616 | |
| 6617 | nfs_fattr_init(&locations->fattr); |
| 6618 | locations->server = server; |
| 6619 | locations->nlocations = 0; |
| 6620 | |
| 6621 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6622 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6623 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6624 | &args.seq_args, &res.seq_res); |
| 6625 | if (status) |
| 6626 | return status; |
| 6627 | |
| 6628 | renew_lease(server, now); |
| 6629 | return 0; |
| 6630 | } |
| 6631 | |
| 6632 | #ifdef CONFIG_NFS_V4_1 |
| 6633 | |
| 6634 | /* |
| 6635 | * This operation also signals the server that this client is |
| 6636 | * performing migration recovery. The server can stop asserting |
| 6637 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6638 | * performing this operation is identified in the SEQUENCE |
| 6639 | * operation in this compound. |
| 6640 | * |
| 6641 | * When the client supports GETATTR(fs_locations_info), it can |
| 6642 | * be plumbed in here. |
| 6643 | */ |
| 6644 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6645 | struct nfs4_fs_locations *locations, |
| 6646 | struct page *page, struct rpc_cred *cred) |
| 6647 | { |
| 6648 | struct nfs_server *server = NFS_SERVER(inode); |
| 6649 | struct rpc_clnt *clnt = server->client; |
| 6650 | u32 bitmask[2] = { |
| 6651 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6652 | }; |
| 6653 | struct nfs4_fs_locations_arg args = { |
| 6654 | .fh = NFS_FH(inode), |
| 6655 | .page = page, |
| 6656 | .bitmask = bitmask, |
| 6657 | .migration = 1, /* skip LOOKUP */ |
| 6658 | }; |
| 6659 | struct nfs4_fs_locations_res res = { |
| 6660 | .fs_locations = locations, |
| 6661 | .migration = 1, |
| 6662 | }; |
| 6663 | struct rpc_message msg = { |
| 6664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6665 | .rpc_argp = &args, |
| 6666 | .rpc_resp = &res, |
| 6667 | .rpc_cred = cred, |
| 6668 | }; |
| 6669 | int status; |
| 6670 | |
| 6671 | nfs_fattr_init(&locations->fattr); |
| 6672 | locations->server = server; |
| 6673 | locations->nlocations = 0; |
| 6674 | |
| 6675 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6676 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6677 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6678 | &args.seq_args, &res.seq_res); |
| 6679 | if (status == NFS4_OK && |
| 6680 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6681 | status = -NFS4ERR_LEASE_MOVED; |
| 6682 | return status; |
| 6683 | } |
| 6684 | |
| 6685 | #endif /* CONFIG_NFS_V4_1 */ |
| 6686 | |
| 6687 | /** |
| 6688 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6689 | * @inode: inode on FSID that is migrating |
| 6690 | * @locations: result of query |
| 6691 | * @page: buffer |
| 6692 | * @cred: credential to use for this operation |
| 6693 | * |
| 6694 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6695 | * operation failed, or a negative errno if a local error occurred. |
| 6696 | * |
| 6697 | * On success, "locations" is filled in, but if the server has |
| 6698 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6699 | * asserted. |
| 6700 | * |
| 6701 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6702 | * from this client that require migration recovery. |
| 6703 | */ |
| 6704 | int nfs4_proc_get_locations(struct inode *inode, |
| 6705 | struct nfs4_fs_locations *locations, |
| 6706 | struct page *page, struct rpc_cred *cred) |
| 6707 | { |
| 6708 | struct nfs_server *server = NFS_SERVER(inode); |
| 6709 | struct nfs_client *clp = server->nfs_client; |
| 6710 | const struct nfs4_mig_recovery_ops *ops = |
| 6711 | clp->cl_mvops->mig_recovery_ops; |
| 6712 | struct nfs4_exception exception = { }; |
| 6713 | int status; |
| 6714 | |
| 6715 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6716 | (unsigned long long)server->fsid.major, |
| 6717 | (unsigned long long)server->fsid.minor, |
| 6718 | clp->cl_hostname); |
| 6719 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6720 | |
| 6721 | do { |
| 6722 | status = ops->get_locations(inode, locations, page, cred); |
| 6723 | if (status != -NFS4ERR_DELAY) |
| 6724 | break; |
| 6725 | nfs4_handle_exception(server, status, &exception); |
| 6726 | } while (exception.retry); |
| 6727 | return status; |
| 6728 | } |
| 6729 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6730 | /* |
| 6731 | * This operation also signals the server that this client is |
| 6732 | * performing "lease moved" recovery. The server can stop |
| 6733 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6734 | * is appended to this compound to identify the client ID which is |
| 6735 | * performing recovery. |
| 6736 | */ |
| 6737 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6738 | { |
| 6739 | struct nfs_server *server = NFS_SERVER(inode); |
| 6740 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6741 | struct rpc_clnt *clnt = server->client; |
| 6742 | struct nfs4_fsid_present_arg args = { |
| 6743 | .fh = NFS_FH(inode), |
| 6744 | .clientid = clp->cl_clientid, |
| 6745 | .renew = 1, /* append RENEW */ |
| 6746 | }; |
| 6747 | struct nfs4_fsid_present_res res = { |
| 6748 | .renew = 1, |
| 6749 | }; |
| 6750 | struct rpc_message msg = { |
| 6751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6752 | .rpc_argp = &args, |
| 6753 | .rpc_resp = &res, |
| 6754 | .rpc_cred = cred, |
| 6755 | }; |
| 6756 | unsigned long now = jiffies; |
| 6757 | int status; |
| 6758 | |
| 6759 | res.fh = nfs_alloc_fhandle(); |
| 6760 | if (res.fh == NULL) |
| 6761 | return -ENOMEM; |
| 6762 | |
| 6763 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6764 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6765 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6766 | &args.seq_args, &res.seq_res); |
| 6767 | nfs_free_fhandle(res.fh); |
| 6768 | if (status) |
| 6769 | return status; |
| 6770 | |
| 6771 | do_renew_lease(clp, now); |
| 6772 | return 0; |
| 6773 | } |
| 6774 | |
| 6775 | #ifdef CONFIG_NFS_V4_1 |
| 6776 | |
| 6777 | /* |
| 6778 | * This operation also signals the server that this client is |
| 6779 | * performing "lease moved" recovery. The server can stop asserting |
| 6780 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6781 | * this operation is identified in the SEQUENCE operation in this |
| 6782 | * compound. |
| 6783 | */ |
| 6784 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6785 | { |
| 6786 | struct nfs_server *server = NFS_SERVER(inode); |
| 6787 | struct rpc_clnt *clnt = server->client; |
| 6788 | struct nfs4_fsid_present_arg args = { |
| 6789 | .fh = NFS_FH(inode), |
| 6790 | }; |
| 6791 | struct nfs4_fsid_present_res res = { |
| 6792 | }; |
| 6793 | struct rpc_message msg = { |
| 6794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6795 | .rpc_argp = &args, |
| 6796 | .rpc_resp = &res, |
| 6797 | .rpc_cred = cred, |
| 6798 | }; |
| 6799 | int status; |
| 6800 | |
| 6801 | res.fh = nfs_alloc_fhandle(); |
| 6802 | if (res.fh == NULL) |
| 6803 | return -ENOMEM; |
| 6804 | |
| 6805 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6806 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6807 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6808 | &args.seq_args, &res.seq_res); |
| 6809 | nfs_free_fhandle(res.fh); |
| 6810 | if (status == NFS4_OK && |
| 6811 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6812 | status = -NFS4ERR_LEASE_MOVED; |
| 6813 | return status; |
| 6814 | } |
| 6815 | |
| 6816 | #endif /* CONFIG_NFS_V4_1 */ |
| 6817 | |
| 6818 | /** |
| 6819 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6820 | * @inode: inode on FSID to check |
| 6821 | * @cred: credential to use for this operation |
| 6822 | * |
| 6823 | * Server indicates whether the FSID is present, moved, or not |
| 6824 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6825 | * condition for this client ID. |
| 6826 | * |
| 6827 | * Returns NFS4_OK if the FSID is present on this server, |
| 6828 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6829 | * NFS4ERR code if some error occurred on the server, or a |
| 6830 | * negative errno if a local failure occurred. |
| 6831 | */ |
| 6832 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6833 | { |
| 6834 | struct nfs_server *server = NFS_SERVER(inode); |
| 6835 | struct nfs_client *clp = server->nfs_client; |
| 6836 | const struct nfs4_mig_recovery_ops *ops = |
| 6837 | clp->cl_mvops->mig_recovery_ops; |
| 6838 | struct nfs4_exception exception = { }; |
| 6839 | int status; |
| 6840 | |
| 6841 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6842 | (unsigned long long)server->fsid.major, |
| 6843 | (unsigned long long)server->fsid.minor, |
| 6844 | clp->cl_hostname); |
| 6845 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6846 | |
| 6847 | do { |
| 6848 | status = ops->fsid_present(inode, cred); |
| 6849 | if (status != -NFS4ERR_DELAY) |
| 6850 | break; |
| 6851 | nfs4_handle_exception(server, status, &exception); |
| 6852 | } while (exception.retry); |
| 6853 | return status; |
| 6854 | } |
| 6855 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6856 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6857 | * If 'use_integrity' is true and the state managment nfs_client |
| 6858 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6859 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6860 | * Considerations sections. Otherwise, just use the user cred with the |
| 6861 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6862 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6863 | 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] | 6864 | { |
| 6865 | int status; |
| 6866 | struct nfs4_secinfo_arg args = { |
| 6867 | .dir_fh = NFS_FH(dir), |
| 6868 | .name = name, |
| 6869 | }; |
| 6870 | struct nfs4_secinfo_res res = { |
| 6871 | .flavors = flavors, |
| 6872 | }; |
| 6873 | struct rpc_message msg = { |
| 6874 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6875 | .rpc_argp = &args, |
| 6876 | .rpc_resp = &res, |
| 6877 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6878 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6879 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6880 | |
| 6881 | if (use_integrity) { |
| 6882 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6883 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6884 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6885 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6886 | |
| 6887 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6888 | |
| 6889 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6890 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6891 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6892 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6893 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6894 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6895 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6896 | if (cred) |
| 6897 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6898 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6899 | return status; |
| 6900 | } |
| 6901 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6902 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6903 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6904 | { |
| 6905 | struct nfs4_exception exception = { }; |
| 6906 | int err; |
| 6907 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6908 | err = -NFS4ERR_WRONGSEC; |
| 6909 | |
| 6910 | /* try to use integrity protection with machine cred */ |
| 6911 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6912 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6913 | |
| 6914 | /* |
| 6915 | * if unable to use integrity protection, or SECINFO with |
| 6916 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 6917 | * disallowed by spec, but exists in deployed servers) use |
| 6918 | * the current filesystem's rpc_client and the user cred. |
| 6919 | */ |
| 6920 | if (err == -NFS4ERR_WRONGSEC) |
| 6921 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 6922 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6923 | trace_nfs4_secinfo(dir, name, err); |
| 6924 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6925 | &exception); |
| 6926 | } while (exception.retry); |
| 6927 | return err; |
| 6928 | } |
| 6929 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6930 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 6931 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6932 | * Check the exchange flags returned by the server for invalid flags, having |
| 6933 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 6934 | * DS flags set. |
| 6935 | */ |
| 6936 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 6937 | { |
| 6938 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 6939 | goto out_inval; |
| 6940 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 6941 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 6942 | goto out_inval; |
| 6943 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 6944 | goto out_inval; |
| 6945 | return NFS_OK; |
| 6946 | out_inval: |
| 6947 | return -NFS4ERR_INVAL; |
| 6948 | } |
| 6949 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6950 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 6951 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 6952 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 6953 | { |
| 6954 | if (a->server_scope_sz == b->server_scope_sz && |
| 6955 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 6956 | return true; |
| 6957 | |
| 6958 | return false; |
| 6959 | } |
| 6960 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6961 | static void |
| 6962 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 6963 | { |
| 6964 | } |
| 6965 | |
| 6966 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 6967 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 6968 | }; |
| 6969 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 6970 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6971 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6972 | * |
| 6973 | * The 4.1 client currently uses the same TCP connection for the |
| 6974 | * fore and backchannel. |
| 6975 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6976 | static |
| 6977 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 6978 | struct rpc_xprt *xprt, |
| 6979 | struct nfs_client *clp, |
| 6980 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6981 | { |
| 6982 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6983 | struct nfs41_bind_conn_to_session_args args = { |
| 6984 | .client = clp, |
| 6985 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 6986 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6987 | struct nfs41_bind_conn_to_session_res res; |
| 6988 | struct rpc_message msg = { |
| 6989 | .rpc_proc = |
| 6990 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 6991 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6992 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 6993 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 6994 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6995 | struct rpc_task_setup task_setup_data = { |
| 6996 | .rpc_client = clnt, |
| 6997 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 6998 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 6999 | .rpc_message = &msg, |
| 7000 | .flags = RPC_TASK_TIMEOUT, |
| 7001 | }; |
| 7002 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7003 | |
| 7004 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7005 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7006 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7007 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7008 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7009 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7010 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7011 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7012 | args.dir = NFS4_CDFC4_FORE; |
| 7013 | |
| 7014 | task = rpc_run_task(&task_setup_data); |
| 7015 | if (!IS_ERR(task)) { |
| 7016 | status = task->tk_status; |
| 7017 | rpc_put_task(task); |
| 7018 | } else |
| 7019 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7020 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7021 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7022 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7023 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7024 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7025 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7026 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7027 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7028 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7029 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7030 | __func__); |
| 7031 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7032 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7033 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7034 | 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] | 7035 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7036 | __func__); |
| 7037 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7038 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7039 | } |
| 7040 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7041 | out: |
| 7042 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7043 | return status; |
| 7044 | } |
| 7045 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7046 | struct rpc_bind_conn_calldata { |
| 7047 | struct nfs_client *clp; |
| 7048 | struct rpc_cred *cred; |
| 7049 | }; |
| 7050 | |
| 7051 | static int |
| 7052 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7053 | struct rpc_xprt *xprt, |
| 7054 | void *calldata) |
| 7055 | { |
| 7056 | struct rpc_bind_conn_calldata *p = calldata; |
| 7057 | |
| 7058 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7059 | } |
| 7060 | |
| 7061 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7062 | { |
| 7063 | struct rpc_bind_conn_calldata data = { |
| 7064 | .clp = clp, |
| 7065 | .cred = cred, |
| 7066 | }; |
| 7067 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7068 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7069 | } |
| 7070 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7071 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7072 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7073 | * 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] | 7074 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7075 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7076 | .how = SP4_MACH_CRED, |
| 7077 | .enforce.u.words = { |
| 7078 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7079 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7080 | 1 << (OP_CREATE_SESSION - 32) | |
| 7081 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7082 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7083 | }, |
| 7084 | .allow.u.words = { |
| 7085 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7086 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7087 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7088 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7089 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7090 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7091 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7092 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7093 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7094 | 1 << (OP_FREE_STATEID - 32) | |
| 7095 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7096 | } |
| 7097 | }; |
| 7098 | |
| 7099 | /* |
| 7100 | * Select the state protection mode for client `clp' given the server results |
| 7101 | * from exchange_id in `sp'. |
| 7102 | * |
| 7103 | * Returns 0 on success, negative errno otherwise. |
| 7104 | */ |
| 7105 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7106 | struct nfs41_state_protection *sp) |
| 7107 | { |
| 7108 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7109 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7110 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7111 | 1 << (OP_CREATE_SESSION - 32) | |
| 7112 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7113 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7114 | }; |
| 7115 | unsigned int i; |
| 7116 | |
| 7117 | if (sp->how == SP4_MACH_CRED) { |
| 7118 | /* Print state protect result */ |
| 7119 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7120 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7121 | if (test_bit(i, sp->enforce.u.longs)) |
| 7122 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7123 | if (test_bit(i, sp->allow.u.longs)) |
| 7124 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7125 | } |
| 7126 | |
| 7127 | /* make sure nothing is on enforce list that isn't supported */ |
| 7128 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7129 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7130 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7131 | return -EINVAL; |
| 7132 | } |
| 7133 | } |
| 7134 | |
| 7135 | /* |
| 7136 | * Minimal mode - state operations are allowed to use machine |
| 7137 | * credential. Note this already happens by default, so the |
| 7138 | * client doesn't have to do anything more than the negotiation. |
| 7139 | * |
| 7140 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7141 | * we're already using the machine cred for exchange_id |
| 7142 | * and will never use a different cred. |
| 7143 | */ |
| 7144 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7145 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7146 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7147 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7148 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7149 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7150 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7151 | } else { |
| 7152 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7153 | return -EINVAL; |
| 7154 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7155 | |
| 7156 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7157 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7158 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7159 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7160 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7161 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7162 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7163 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7164 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7165 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7166 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7167 | &clp->cl_sp4_flags); |
| 7168 | } |
| 7169 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7170 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7171 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7172 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7173 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7174 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7175 | |
| 7176 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7177 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7178 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7179 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7180 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7181 | |
| 7182 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7183 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7184 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7185 | } |
| 7186 | |
| 7187 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7188 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7189 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7190 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | return 0; |
| 7194 | } |
| 7195 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7196 | struct nfs41_exchange_id_data { |
| 7197 | struct nfs41_exchange_id_res res; |
| 7198 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7199 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7200 | int rpc_status; |
| 7201 | }; |
| 7202 | |
| 7203 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7204 | { |
| 7205 | struct nfs41_exchange_id_data *cdata = |
| 7206 | (struct nfs41_exchange_id_data *)data; |
| 7207 | struct nfs_client *clp = cdata->args.client; |
| 7208 | int status = task->tk_status; |
| 7209 | |
| 7210 | trace_nfs4_exchange_id(clp, status); |
| 7211 | |
| 7212 | if (status == 0) |
| 7213 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7214 | |
| 7215 | if (cdata->xprt && status == 0) { |
| 7216 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7217 | cdata->xprt); |
| 7218 | goto out; |
| 7219 | } |
| 7220 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7221 | if (status == 0) |
| 7222 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7223 | |
| 7224 | if (status == 0) { |
| 7225 | clp->cl_clientid = cdata->res.clientid; |
| 7226 | clp->cl_exchange_flags = cdata->res.flags; |
| 7227 | /* Client ID is not confirmed */ |
| 7228 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7229 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7230 | &clp->cl_session->session_state); |
| 7231 | clp->cl_seqid = cdata->res.seqid; |
| 7232 | } |
| 7233 | |
| 7234 | kfree(clp->cl_serverowner); |
| 7235 | clp->cl_serverowner = cdata->res.server_owner; |
| 7236 | cdata->res.server_owner = NULL; |
| 7237 | |
| 7238 | /* use the most recent implementation id */ |
| 7239 | kfree(clp->cl_implid); |
| 7240 | clp->cl_implid = cdata->res.impl_id; |
| 7241 | cdata->res.impl_id = NULL; |
| 7242 | |
| 7243 | if (clp->cl_serverscope != NULL && |
| 7244 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7245 | cdata->res.server_scope)) { |
| 7246 | dprintk("%s: server_scope mismatch detected\n", |
| 7247 | __func__); |
| 7248 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7249 | kfree(clp->cl_serverscope); |
| 7250 | clp->cl_serverscope = NULL; |
| 7251 | } |
| 7252 | |
| 7253 | if (clp->cl_serverscope == NULL) { |
| 7254 | clp->cl_serverscope = cdata->res.server_scope; |
| 7255 | cdata->res.server_scope = NULL; |
| 7256 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7257 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7258 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7259 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7260 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7261 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7262 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7263 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | static void nfs4_exchange_id_release(void *data) |
| 7267 | { |
| 7268 | struct nfs41_exchange_id_data *cdata = |
| 7269 | (struct nfs41_exchange_id_data *)data; |
| 7270 | |
| 7271 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7272 | if (cdata->xprt) { |
| 7273 | xprt_put(cdata->xprt); |
| 7274 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7275 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7276 | kfree(cdata->res.impl_id); |
| 7277 | kfree(cdata->res.server_scope); |
| 7278 | kfree(cdata->res.server_owner); |
| 7279 | kfree(cdata); |
| 7280 | } |
| 7281 | |
| 7282 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7283 | .rpc_call_done = nfs4_exchange_id_done, |
| 7284 | .rpc_release = nfs4_exchange_id_release, |
| 7285 | }; |
| 7286 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7287 | /* |
| 7288 | * _nfs4_proc_exchange_id() |
| 7289 | * |
| 7290 | * Wrapper for EXCHANGE_ID operation. |
| 7291 | */ |
| 7292 | 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] | 7293 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7294 | { |
| 7295 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7296 | struct rpc_message msg = { |
| 7297 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7298 | .rpc_cred = cred, |
| 7299 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7300 | struct rpc_task_setup task_setup_data = { |
| 7301 | .rpc_client = clp->cl_rpcclient, |
| 7302 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7303 | .rpc_message = &msg, |
| 7304 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7305 | }; |
| 7306 | struct nfs41_exchange_id_data *calldata; |
| 7307 | struct rpc_task *task; |
| 7308 | int status = -EIO; |
| 7309 | |
| 7310 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7311 | goto out; |
| 7312 | |
| 7313 | status = -ENOMEM; |
| 7314 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7315 | if (!calldata) |
| 7316 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7317 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7318 | if (!xprt) |
| 7319 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7320 | |
| 7321 | status = nfs4_init_uniform_client_string(clp); |
| 7322 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7323 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7324 | |
| 7325 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7326 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7327 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7328 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7329 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7330 | GFP_NOFS); |
| 7331 | status = -ENOMEM; |
| 7332 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7333 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7334 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7335 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7336 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7337 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7338 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7339 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7340 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7341 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7342 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7343 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7344 | switch (sp4_how) { |
| 7345 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7346 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7347 | break; |
| 7348 | |
| 7349 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7350 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7351 | break; |
| 7352 | |
| 7353 | default: |
| 7354 | /* unsupported! */ |
| 7355 | WARN_ON_ONCE(1); |
| 7356 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7357 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7358 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7359 | if (xprt) { |
| 7360 | calldata->xprt = xprt; |
| 7361 | task_setup_data.rpc_xprt = xprt; |
| 7362 | task_setup_data.flags = |
| 7363 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7364 | calldata->args.verifier = &clp->cl_confirm; |
| 7365 | } else { |
| 7366 | calldata->args.verifier = &verifier; |
| 7367 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7368 | calldata->args.client = clp; |
| 7369 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7370 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7371 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7372 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7373 | #else |
| 7374 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7375 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7376 | #endif |
| 7377 | msg.rpc_argp = &calldata->args; |
| 7378 | msg.rpc_resp = &calldata->res; |
| 7379 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7380 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7381 | task = rpc_run_task(&task_setup_data); |
| 7382 | if (IS_ERR(task)) { |
| 7383 | status = PTR_ERR(task); |
| 7384 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7385 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7386 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7387 | if (!xprt) { |
| 7388 | status = rpc_wait_for_completion_task(task); |
| 7389 | if (!status) |
| 7390 | status = calldata->rpc_status; |
| 7391 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7392 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7393 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7394 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7395 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7396 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7397 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7398 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7399 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7400 | clp->cl_implid->date.seconds, |
| 7401 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7402 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7403 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7404 | |
| 7405 | out_impl_id: |
| 7406 | kfree(calldata->res.impl_id); |
| 7407 | out_server_scope: |
| 7408 | kfree(calldata->res.server_scope); |
| 7409 | out_server_owner: |
| 7410 | kfree(calldata->res.server_owner); |
| 7411 | out_calldata: |
| 7412 | kfree(calldata); |
| 7413 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7414 | } |
| 7415 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7416 | /* |
| 7417 | * nfs4_proc_exchange_id() |
| 7418 | * |
| 7419 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7420 | * |
| 7421 | * Since the clientid has expired, all compounds using sessions |
| 7422 | * associated with the stale clientid will be returning |
| 7423 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7424 | * be in some phase of session reset. |
| 7425 | * |
| 7426 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7427 | */ |
| 7428 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7429 | { |
| 7430 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7431 | int status; |
| 7432 | |
| 7433 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7434 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7435 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7436 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7437 | if (!status) |
| 7438 | return 0; |
| 7439 | } |
| 7440 | |
| 7441 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7442 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7443 | } |
| 7444 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7445 | /** |
| 7446 | * nfs4_test_session_trunk |
| 7447 | * |
| 7448 | * This is an add_xprt_test() test function called from |
| 7449 | * rpc_clnt_setup_test_and_add_xprt. |
| 7450 | * |
| 7451 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7452 | * and is dereferrenced in nfs4_exchange_id_release |
| 7453 | * |
| 7454 | * Upon success, add the new transport to the rpc_clnt |
| 7455 | * |
| 7456 | * @clnt: struct rpc_clnt to get new transport |
| 7457 | * @xprt: the rpc_xprt to test |
| 7458 | * @data: call data for _nfs4_proc_exchange_id. |
| 7459 | */ |
| 7460 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7461 | void *data) |
| 7462 | { |
| 7463 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7464 | u32 sp4_how; |
| 7465 | |
| 7466 | dprintk("--> %s try %s\n", __func__, |
| 7467 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7468 | |
| 7469 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7470 | |
| 7471 | /* Test connection for session trunking. Async exchange_id call */ |
| 7472 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7473 | } |
| 7474 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7475 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7476 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7477 | struct rpc_cred *cred) |
| 7478 | { |
| 7479 | struct rpc_message msg = { |
| 7480 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7481 | .rpc_argp = clp, |
| 7482 | .rpc_cred = cred, |
| 7483 | }; |
| 7484 | int status; |
| 7485 | |
| 7486 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7487 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7488 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7489 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7490 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7491 | return status; |
| 7492 | } |
| 7493 | |
| 7494 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7495 | struct rpc_cred *cred) |
| 7496 | { |
| 7497 | unsigned int loop; |
| 7498 | int ret; |
| 7499 | |
| 7500 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7501 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7502 | switch (ret) { |
| 7503 | case -NFS4ERR_DELAY: |
| 7504 | case -NFS4ERR_CLIENTID_BUSY: |
| 7505 | ssleep(1); |
| 7506 | break; |
| 7507 | default: |
| 7508 | return ret; |
| 7509 | } |
| 7510 | } |
| 7511 | return 0; |
| 7512 | } |
| 7513 | |
| 7514 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7515 | { |
| 7516 | struct rpc_cred *cred; |
| 7517 | int ret = 0; |
| 7518 | |
| 7519 | if (clp->cl_mvops->minor_version < 1) |
| 7520 | goto out; |
| 7521 | if (clp->cl_exchange_flags == 0) |
| 7522 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7523 | if (clp->cl_preserve_clid) |
| 7524 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7525 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7526 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7527 | if (cred) |
| 7528 | put_rpccred(cred); |
| 7529 | switch (ret) { |
| 7530 | case 0: |
| 7531 | case -NFS4ERR_STALE_CLIENTID: |
| 7532 | clp->cl_exchange_flags = 0; |
| 7533 | } |
| 7534 | out: |
| 7535 | return ret; |
| 7536 | } |
| 7537 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7538 | struct nfs4_get_lease_time_data { |
| 7539 | struct nfs4_get_lease_time_args *args; |
| 7540 | struct nfs4_get_lease_time_res *res; |
| 7541 | struct nfs_client *clp; |
| 7542 | }; |
| 7543 | |
| 7544 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7545 | void *calldata) |
| 7546 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7547 | struct nfs4_get_lease_time_data *data = |
| 7548 | (struct nfs4_get_lease_time_data *)calldata; |
| 7549 | |
| 7550 | dprintk("--> %s\n", __func__); |
| 7551 | /* just setup sequence, do not trigger session recovery |
| 7552 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7553 | nfs41_setup_sequence(data->clp->cl_session, |
| 7554 | &data->args->la_seq_args, |
| 7555 | &data->res->lr_seq_res, |
| 7556 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7557 | dprintk("<-- %s\n", __func__); |
| 7558 | } |
| 7559 | |
| 7560 | /* |
| 7561 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7562 | * from sequence operation or clientid errors. |
| 7563 | */ |
| 7564 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7565 | { |
| 7566 | struct nfs4_get_lease_time_data *data = |
| 7567 | (struct nfs4_get_lease_time_data *)calldata; |
| 7568 | |
| 7569 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7570 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7571 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7572 | switch (task->tk_status) { |
| 7573 | case -NFS4ERR_DELAY: |
| 7574 | case -NFS4ERR_GRACE: |
| 7575 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7576 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7577 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7578 | /* fall through */ |
| 7579 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7580 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7581 | return; |
| 7582 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7583 | dprintk("<-- %s\n", __func__); |
| 7584 | } |
| 7585 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7586 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7587 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7588 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7589 | }; |
| 7590 | |
| 7591 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7592 | { |
| 7593 | struct rpc_task *task; |
| 7594 | struct nfs4_get_lease_time_args args; |
| 7595 | struct nfs4_get_lease_time_res res = { |
| 7596 | .lr_fsinfo = fsinfo, |
| 7597 | }; |
| 7598 | struct nfs4_get_lease_time_data data = { |
| 7599 | .args = &args, |
| 7600 | .res = &res, |
| 7601 | .clp = clp, |
| 7602 | }; |
| 7603 | struct rpc_message msg = { |
| 7604 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7605 | .rpc_argp = &args, |
| 7606 | .rpc_resp = &res, |
| 7607 | }; |
| 7608 | struct rpc_task_setup task_setup = { |
| 7609 | .rpc_client = clp->cl_rpcclient, |
| 7610 | .rpc_message = &msg, |
| 7611 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7612 | .callback_data = &data, |
| 7613 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7614 | }; |
| 7615 | int status; |
| 7616 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7617 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7618 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7619 | dprintk("--> %s\n", __func__); |
| 7620 | task = rpc_run_task(&task_setup); |
| 7621 | |
| 7622 | if (IS_ERR(task)) |
| 7623 | status = PTR_ERR(task); |
| 7624 | else { |
| 7625 | status = task->tk_status; |
| 7626 | rpc_put_task(task); |
| 7627 | } |
| 7628 | dprintk("<-- %s return %d\n", __func__, status); |
| 7629 | |
| 7630 | return status; |
| 7631 | } |
| 7632 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7633 | /* |
| 7634 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7635 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7636 | * use them. |
| 7637 | * |
| 7638 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7639 | * always set csa_cachethis to FALSE because the current implementation |
| 7640 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7641 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7642 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7643 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7644 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7645 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7646 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7647 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7648 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7649 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7650 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7651 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7652 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7653 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7654 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7655 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7656 | |
| 7657 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7658 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7659 | __func__, |
| 7660 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7661 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7662 | |
| 7663 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7664 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7665 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7666 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7667 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7668 | 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] | 7669 | |
| 7670 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7671 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7672 | __func__, |
| 7673 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7674 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7675 | args->bc_attrs.max_reqs); |
| 7676 | } |
| 7677 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7678 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7679 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7680 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7681 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7682 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7683 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7684 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7685 | return -EINVAL; |
| 7686 | /* |
| 7687 | * Our requested max_ops is the minimum we need; we're not |
| 7688 | * prepared to break up compounds into smaller pieces than that. |
| 7689 | * So, no point even trying to continue if the server won't |
| 7690 | * cooperate: |
| 7691 | */ |
| 7692 | if (rcvd->max_ops < sent->max_ops) |
| 7693 | return -EINVAL; |
| 7694 | if (rcvd->max_reqs == 0) |
| 7695 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7696 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7697 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7698 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7699 | } |
| 7700 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7701 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7702 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7703 | { |
| 7704 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7705 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7706 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7707 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7708 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7709 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7710 | return -EINVAL; |
| 7711 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7712 | return -EINVAL; |
| 7713 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7714 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7715 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7716 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7717 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7718 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7719 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7720 | return 0; |
| 7721 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7722 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7723 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7724 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7725 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7726 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7727 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7728 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7729 | if (ret) |
| 7730 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7731 | return nfs4_verify_back_channel_attrs(args, res); |
| 7732 | } |
| 7733 | |
| 7734 | static void nfs4_update_session(struct nfs4_session *session, |
| 7735 | struct nfs41_create_session_res *res) |
| 7736 | { |
| 7737 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7738 | /* Mark client id and session as being confirmed */ |
| 7739 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7740 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7741 | session->flags = res->flags; |
| 7742 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7743 | if (res->flags & SESSION4_BACK_CHAN) |
| 7744 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7745 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7746 | } |
| 7747 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7748 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7749 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7750 | { |
| 7751 | struct nfs4_session *session = clp->cl_session; |
| 7752 | struct nfs41_create_session_args args = { |
| 7753 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7754 | .clientid = clp->cl_clientid, |
| 7755 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7756 | .cb_program = NFS4_CALLBACK, |
| 7757 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7758 | struct nfs41_create_session_res res; |
| 7759 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7760 | struct rpc_message msg = { |
| 7761 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7762 | .rpc_argp = &args, |
| 7763 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7764 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7765 | }; |
| 7766 | int status; |
| 7767 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7768 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7769 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7770 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7771 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7772 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7773 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7774 | switch (status) { |
| 7775 | case -NFS4ERR_STALE_CLIENTID: |
| 7776 | case -NFS4ERR_DELAY: |
| 7777 | case -ETIMEDOUT: |
| 7778 | case -EACCES: |
| 7779 | case -EAGAIN: |
| 7780 | goto out; |
| 7781 | }; |
| 7782 | |
| 7783 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7784 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7785 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7786 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7787 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7788 | if (status) |
| 7789 | goto out; |
| 7790 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7791 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7792 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7793 | return status; |
| 7794 | } |
| 7795 | |
| 7796 | /* |
| 7797 | * Issues a CREATE_SESSION operation to the server. |
| 7798 | * It is the responsibility of the caller to verify the session is |
| 7799 | * expired before calling this routine. |
| 7800 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7801 | 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] | 7802 | { |
| 7803 | int status; |
| 7804 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7805 | struct nfs4_session *session = clp->cl_session; |
| 7806 | |
| 7807 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7808 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7809 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7810 | if (status) |
| 7811 | goto out; |
| 7812 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7813 | /* Init or reset the session slot tables */ |
| 7814 | status = nfs4_setup_session_slot_tables(session); |
| 7815 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7816 | if (status) |
| 7817 | goto out; |
| 7818 | |
| 7819 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7820 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7821 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7822 | out: |
| 7823 | dprintk("<-- %s\n", __func__); |
| 7824 | return status; |
| 7825 | } |
| 7826 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7827 | /* |
| 7828 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7829 | * The caller must serialize access to this routine. |
| 7830 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7831 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7832 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7833 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7834 | struct rpc_message msg = { |
| 7835 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7836 | .rpc_argp = session, |
| 7837 | .rpc_cred = cred, |
| 7838 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7839 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7840 | |
| 7841 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7842 | |
| 7843 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7844 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7845 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7846 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7847 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7848 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7849 | |
| 7850 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7851 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7852 | "Session has been destroyed regardless...\n", status); |
| 7853 | |
| 7854 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7855 | return status; |
| 7856 | } |
| 7857 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7858 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7859 | * Renew the cl_session lease. |
| 7860 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7861 | struct nfs4_sequence_data { |
| 7862 | struct nfs_client *clp; |
| 7863 | struct nfs4_sequence_args args; |
| 7864 | struct nfs4_sequence_res res; |
| 7865 | }; |
| 7866 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7867 | static void nfs41_sequence_release(void *data) |
| 7868 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7869 | struct nfs4_sequence_data *calldata = data; |
| 7870 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7871 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7872 | if (atomic_read(&clp->cl_count) > 1) |
| 7873 | nfs4_schedule_state_renewal(clp); |
| 7874 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7875 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7876 | } |
| 7877 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7878 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7879 | { |
| 7880 | switch(task->tk_status) { |
| 7881 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7882 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7883 | return -EAGAIN; |
| 7884 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7885 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7886 | } |
| 7887 | return 0; |
| 7888 | } |
| 7889 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7890 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7891 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7892 | struct nfs4_sequence_data *calldata = data; |
| 7893 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7894 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7895 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7896 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7897 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7898 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7899 | if (task->tk_status < 0) { |
| 7900 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7901 | if (atomic_read(&clp->cl_count) == 1) |
| 7902 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7903 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7904 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7905 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7906 | return; |
| 7907 | } |
| 7908 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7909 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7910 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7911 | dprintk("<-- %s\n", __func__); |
| 7912 | } |
| 7913 | |
| 7914 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 7915 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7916 | struct nfs4_sequence_data *calldata = data; |
| 7917 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7918 | struct nfs4_sequence_args *args; |
| 7919 | struct nfs4_sequence_res *res; |
| 7920 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7921 | args = task->tk_msg.rpc_argp; |
| 7922 | res = task->tk_msg.rpc_resp; |
| 7923 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7924 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7925 | } |
| 7926 | |
| 7927 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 7928 | .rpc_call_done = nfs41_sequence_call_done, |
| 7929 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7930 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7931 | }; |
| 7932 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7933 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 7934 | struct rpc_cred *cred, |
| 7935 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7936 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7937 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7938 | struct rpc_message msg = { |
| 7939 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 7940 | .rpc_cred = cred, |
| 7941 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7942 | struct rpc_task_setup task_setup_data = { |
| 7943 | .rpc_client = clp->cl_rpcclient, |
| 7944 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7945 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 7946 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7947 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7948 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7949 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7950 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 7951 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7952 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7953 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7954 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7955 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7956 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7957 | if (is_privileged) |
| 7958 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7959 | msg.rpc_argp = &calldata->args; |
| 7960 | msg.rpc_resp = &calldata->res; |
| 7961 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7962 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7963 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7964 | return rpc_run_task(&task_setup_data); |
| 7965 | } |
| 7966 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7967 | 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] | 7968 | { |
| 7969 | struct rpc_task *task; |
| 7970 | int ret = 0; |
| 7971 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 7972 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 7973 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7974 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7975 | if (IS_ERR(task)) |
| 7976 | ret = PTR_ERR(task); |
| 7977 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 7978 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7979 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7980 | return ret; |
| 7981 | } |
| 7982 | |
| 7983 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 7984 | { |
| 7985 | struct rpc_task *task; |
| 7986 | int ret; |
| 7987 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7988 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7989 | if (IS_ERR(task)) { |
| 7990 | ret = PTR_ERR(task); |
| 7991 | goto out; |
| 7992 | } |
| 7993 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 7994 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7995 | ret = task->tk_status; |
| 7996 | rpc_put_task(task); |
| 7997 | out: |
| 7998 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 7999 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8000 | } |
| 8001 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8002 | struct nfs4_reclaim_complete_data { |
| 8003 | struct nfs_client *clp; |
| 8004 | struct nfs41_reclaim_complete_args arg; |
| 8005 | struct nfs41_reclaim_complete_res res; |
| 8006 | }; |
| 8007 | |
| 8008 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8009 | { |
| 8010 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8011 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8012 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8013 | &calldata->arg.seq_args, |
| 8014 | &calldata->res.seq_res, |
| 8015 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8016 | } |
| 8017 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8018 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8019 | { |
| 8020 | switch(task->tk_status) { |
| 8021 | case 0: |
| 8022 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8023 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8024 | break; |
| 8025 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8026 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8027 | /* fall through */ |
| 8028 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8029 | return -EAGAIN; |
| 8030 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8031 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8032 | } |
| 8033 | return 0; |
| 8034 | } |
| 8035 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8036 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8037 | { |
| 8038 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8039 | struct nfs_client *clp = calldata->clp; |
| 8040 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8041 | |
| 8042 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8043 | if (!nfs41_sequence_done(task, res)) |
| 8044 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8045 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8046 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8047 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8048 | rpc_restart_call_prepare(task); |
| 8049 | return; |
| 8050 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8051 | dprintk("<-- %s\n", __func__); |
| 8052 | } |
| 8053 | |
| 8054 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8055 | { |
| 8056 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8057 | |
| 8058 | kfree(calldata); |
| 8059 | } |
| 8060 | |
| 8061 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8062 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8063 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8064 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8065 | }; |
| 8066 | |
| 8067 | /* |
| 8068 | * Issue a global reclaim complete. |
| 8069 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8070 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8071 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8072 | { |
| 8073 | struct nfs4_reclaim_complete_data *calldata; |
| 8074 | struct rpc_task *task; |
| 8075 | struct rpc_message msg = { |
| 8076 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8077 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8078 | }; |
| 8079 | struct rpc_task_setup task_setup_data = { |
| 8080 | .rpc_client = clp->cl_rpcclient, |
| 8081 | .rpc_message = &msg, |
| 8082 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8083 | .flags = RPC_TASK_ASYNC, |
| 8084 | }; |
| 8085 | int status = -ENOMEM; |
| 8086 | |
| 8087 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8088 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8089 | if (calldata == NULL) |
| 8090 | goto out; |
| 8091 | calldata->clp = clp; |
| 8092 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8093 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8094 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8095 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8096 | msg.rpc_argp = &calldata->arg; |
| 8097 | msg.rpc_resp = &calldata->res; |
| 8098 | task_setup_data.callback_data = calldata; |
| 8099 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8100 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8101 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8102 | goto out; |
| 8103 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8104 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8105 | if (status == 0) |
| 8106 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8107 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8108 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8109 | out: |
| 8110 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8111 | return status; |
| 8112 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8113 | |
| 8114 | static void |
| 8115 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8116 | { |
| 8117 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8118 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8119 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8120 | |
| 8121 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8122 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8123 | &lgp->res.seq_res, task); |
| 8124 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8128 | { |
| 8129 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8130 | |
| 8131 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8132 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8133 | dprintk("<-- %s\n", __func__); |
| 8134 | } |
| 8135 | |
| 8136 | static int |
| 8137 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8138 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8139 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8140 | struct inode *inode = lgp->args.inode; |
| 8141 | struct nfs_server *server = NFS_SERVER(inode); |
| 8142 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8143 | int nfs4err = task->tk_status; |
| 8144 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8145 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8146 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8147 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8148 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8149 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8150 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8151 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8152 | |
| 8153 | /* |
| 8154 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8155 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8156 | * retry go inband. |
| 8157 | */ |
| 8158 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8159 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8160 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8161 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8162 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8163 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8164 | */ |
| 8165 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8166 | status = -EOVERFLOW; |
| 8167 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8168 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8169 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8170 | * (or clients) writing to the same RAID stripe except when |
| 8171 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8172 | * |
| 8173 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8174 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8175 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8176 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8177 | if (lgp->args.minlength == 0) { |
| 8178 | status = -EOVERFLOW; |
| 8179 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8180 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8181 | status = -EBUSY; |
| 8182 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8183 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8184 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8185 | break; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8186 | case -NFS4ERR_EXPIRED: |
| 8187 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8188 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8189 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8190 | lo = NFS_I(inode)->layout; |
| 8191 | /* If the open stateid was bad, then recover it. */ |
| 8192 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8193 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8194 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8195 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8196 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8197 | break; |
| 8198 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8199 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8200 | /* |
| 8201 | * Mark the bad layout state as invalid, then retry |
| 8202 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8203 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8204 | spin_unlock(&inode->i_lock); |
| 8205 | pnfs_free_lseg_list(&head); |
| 8206 | status = -EAGAIN; |
| 8207 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8208 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8209 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8210 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8211 | if (!status) { |
| 8212 | if (exception->retry) |
| 8213 | status = -EAGAIN; |
| 8214 | else |
| 8215 | status = err; |
| 8216 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8217 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8218 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8219 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8220 | } |
| 8221 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8222 | static size_t max_response_pages(struct nfs_server *server) |
| 8223 | { |
| 8224 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8225 | return nfs_page_array_len(0, max_resp_sz); |
| 8226 | } |
| 8227 | |
| 8228 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8229 | { |
| 8230 | int i; |
| 8231 | |
| 8232 | if (!pages) |
| 8233 | return; |
| 8234 | |
| 8235 | for (i = 0; i < size; i++) { |
| 8236 | if (!pages[i]) |
| 8237 | break; |
| 8238 | __free_page(pages[i]); |
| 8239 | } |
| 8240 | kfree(pages); |
| 8241 | } |
| 8242 | |
| 8243 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8244 | { |
| 8245 | struct page **pages; |
| 8246 | int i; |
| 8247 | |
| 8248 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8249 | if (!pages) { |
| 8250 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8251 | return NULL; |
| 8252 | } |
| 8253 | |
| 8254 | for (i = 0; i < size; i++) { |
| 8255 | pages[i] = alloc_page(gfp_flags); |
| 8256 | if (!pages[i]) { |
| 8257 | dprintk("%s: failed to allocate page\n", __func__); |
| 8258 | nfs4_free_pages(pages, size); |
| 8259 | return NULL; |
| 8260 | } |
| 8261 | } |
| 8262 | |
| 8263 | return pages; |
| 8264 | } |
| 8265 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8266 | static void nfs4_layoutget_release(void *calldata) |
| 8267 | { |
| 8268 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8269 | struct inode *inode = lgp->args.inode; |
| 8270 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8271 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8272 | |
| 8273 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8274 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8275 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8276 | put_nfs_open_context(lgp->args.ctx); |
| 8277 | kfree(calldata); |
| 8278 | dprintk("<-- %s\n", __func__); |
| 8279 | } |
| 8280 | |
| 8281 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8282 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8283 | .rpc_call_done = nfs4_layoutget_done, |
| 8284 | .rpc_release = nfs4_layoutget_release, |
| 8285 | }; |
| 8286 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8287 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8288 | 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] | 8289 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8290 | struct inode *inode = lgp->args.inode; |
| 8291 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8292 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8293 | struct rpc_task *task; |
| 8294 | struct rpc_message msg = { |
| 8295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8296 | .rpc_argp = &lgp->args, |
| 8297 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8298 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8299 | }; |
| 8300 | struct rpc_task_setup task_setup_data = { |
| 8301 | .rpc_client = server->client, |
| 8302 | .rpc_message = &msg, |
| 8303 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8304 | .callback_data = lgp, |
| 8305 | .flags = RPC_TASK_ASYNC, |
| 8306 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8307 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8308 | struct nfs4_exception exception = { |
| 8309 | .inode = inode, |
| 8310 | .timeout = *timeout, |
| 8311 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8312 | int status = 0; |
| 8313 | |
| 8314 | dprintk("--> %s\n", __func__); |
| 8315 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8316 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8317 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8318 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8319 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8320 | if (!lgp->args.layout.pages) { |
| 8321 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8322 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8323 | } |
| 8324 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8325 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8326 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8327 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8328 | 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] | 8329 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8330 | task = rpc_run_task(&task_setup_data); |
| 8331 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8332 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8333 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8334 | if (status == 0) { |
| 8335 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8336 | *timeout = exception.timeout; |
| 8337 | } |
| 8338 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8339 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8340 | &lgp->args.range, |
| 8341 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8342 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8343 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8344 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8345 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8346 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8347 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8348 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8349 | rpc_put_task(task); |
| 8350 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8351 | if (status) |
| 8352 | return ERR_PTR(status); |
| 8353 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8354 | } |
| 8355 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8356 | static void |
| 8357 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8358 | { |
| 8359 | struct nfs4_layoutreturn *lrp = calldata; |
| 8360 | |
| 8361 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8362 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8363 | &lrp->args.seq_args, |
| 8364 | &lrp->res.seq_res, |
| 8365 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8369 | { |
| 8370 | struct nfs4_layoutreturn *lrp = calldata; |
| 8371 | struct nfs_server *server; |
| 8372 | |
| 8373 | dprintk("--> %s\n", __func__); |
| 8374 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8375 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8376 | return; |
| 8377 | |
| 8378 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8379 | switch (task->tk_status) { |
| 8380 | default: |
| 8381 | task->tk_status = 0; |
| 8382 | case 0: |
| 8383 | break; |
| 8384 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8385 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8386 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8387 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8388 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8389 | return; |
| 8390 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8391 | dprintk("<-- %s\n", __func__); |
| 8392 | } |
| 8393 | |
| 8394 | static void nfs4_layoutreturn_release(void *calldata) |
| 8395 | { |
| 8396 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8397 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8398 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8399 | |
| 8400 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8401 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8402 | if (lrp->res.lrs_present) { |
| 8403 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8404 | &lrp->args.range, |
| 8405 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8406 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8407 | } else |
| 8408 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8409 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8410 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8411 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8412 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8413 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8414 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8415 | kfree(calldata); |
| 8416 | dprintk("<-- %s\n", __func__); |
| 8417 | } |
| 8418 | |
| 8419 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8420 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8421 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8422 | .rpc_release = nfs4_layoutreturn_release, |
| 8423 | }; |
| 8424 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8425 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8426 | { |
| 8427 | struct rpc_task *task; |
| 8428 | struct rpc_message msg = { |
| 8429 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8430 | .rpc_argp = &lrp->args, |
| 8431 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8432 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8433 | }; |
| 8434 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8435 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8436 | .rpc_message = &msg, |
| 8437 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8438 | .callback_data = lrp, |
| 8439 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8440 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8441 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8442 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8443 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8444 | &task_setup_data.rpc_client, &msg); |
| 8445 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8446 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8447 | if (!sync) { |
| 8448 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8449 | if (!lrp->inode) { |
| 8450 | nfs4_layoutreturn_release(lrp); |
| 8451 | return -EAGAIN; |
| 8452 | } |
| 8453 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8454 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8455 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8456 | task = rpc_run_task(&task_setup_data); |
| 8457 | if (IS_ERR(task)) |
| 8458 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8459 | if (sync) |
| 8460 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8461 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8462 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8463 | rpc_put_task(task); |
| 8464 | return status; |
| 8465 | } |
| 8466 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8467 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8468 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8469 | struct pnfs_device *pdev, |
| 8470 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8471 | { |
| 8472 | struct nfs4_getdeviceinfo_args args = { |
| 8473 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8474 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8475 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8476 | }; |
| 8477 | struct nfs4_getdeviceinfo_res res = { |
| 8478 | .pdev = pdev, |
| 8479 | }; |
| 8480 | struct rpc_message msg = { |
| 8481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8482 | .rpc_argp = &args, |
| 8483 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8484 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8485 | }; |
| 8486 | int status; |
| 8487 | |
| 8488 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8489 | 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] | 8490 | if (res.notification & ~args.notify_types) |
| 8491 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8492 | if (res.notification != args.notify_types) |
| 8493 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8494 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8495 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8496 | |
| 8497 | return status; |
| 8498 | } |
| 8499 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8500 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8501 | struct pnfs_device *pdev, |
| 8502 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8503 | { |
| 8504 | struct nfs4_exception exception = { }; |
| 8505 | int err; |
| 8506 | |
| 8507 | do { |
| 8508 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8509 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8510 | &exception); |
| 8511 | } while (exception.retry); |
| 8512 | return err; |
| 8513 | } |
| 8514 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8515 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8516 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8517 | { |
| 8518 | struct nfs4_layoutcommit_data *data = calldata; |
| 8519 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8520 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8521 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8522 | nfs41_setup_sequence(session, |
| 8523 | &data->args.seq_args, |
| 8524 | &data->res.seq_res, |
| 8525 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8526 | } |
| 8527 | |
| 8528 | static void |
| 8529 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8530 | { |
| 8531 | struct nfs4_layoutcommit_data *data = calldata; |
| 8532 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8533 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8534 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8535 | return; |
| 8536 | |
| 8537 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8538 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8539 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8540 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8541 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8542 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8543 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8544 | break; |
| 8545 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8546 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8547 | rpc_restart_call_prepare(task); |
| 8548 | return; |
| 8549 | } |
| 8550 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8551 | } |
| 8552 | |
| 8553 | static void nfs4_layoutcommit_release(void *calldata) |
| 8554 | { |
| 8555 | struct nfs4_layoutcommit_data *data = calldata; |
| 8556 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8557 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8558 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8559 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8560 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8561 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8562 | kfree(data); |
| 8563 | } |
| 8564 | |
| 8565 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8566 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8567 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8568 | .rpc_release = nfs4_layoutcommit_release, |
| 8569 | }; |
| 8570 | |
| 8571 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8572 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8573 | { |
| 8574 | struct rpc_message msg = { |
| 8575 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8576 | .rpc_argp = &data->args, |
| 8577 | .rpc_resp = &data->res, |
| 8578 | .rpc_cred = data->cred, |
| 8579 | }; |
| 8580 | struct rpc_task_setup task_setup_data = { |
| 8581 | .task = &data->task, |
| 8582 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8583 | .rpc_message = &msg, |
| 8584 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8585 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8586 | }; |
| 8587 | struct rpc_task *task; |
| 8588 | int status = 0; |
| 8589 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8590 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8591 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8592 | data->args.lastbytewritten, |
| 8593 | data->args.inode->i_ino); |
| 8594 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8595 | if (!sync) { |
| 8596 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8597 | if (data->inode == NULL) { |
| 8598 | nfs4_layoutcommit_release(data); |
| 8599 | return -EAGAIN; |
| 8600 | } |
| 8601 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8602 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8603 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8604 | task = rpc_run_task(&task_setup_data); |
| 8605 | if (IS_ERR(task)) |
| 8606 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8607 | if (sync) |
| 8608 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8609 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8610 | dprintk("%s: status %d\n", __func__, status); |
| 8611 | rpc_put_task(task); |
| 8612 | return status; |
| 8613 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8614 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8615 | /** |
| 8616 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8617 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8618 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8619 | static int |
| 8620 | _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] | 8621 | struct nfs_fsinfo *info, |
| 8622 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8623 | { |
| 8624 | struct nfs41_secinfo_no_name_args args = { |
| 8625 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8626 | }; |
| 8627 | struct nfs4_secinfo_res res = { |
| 8628 | .flavors = flavors, |
| 8629 | }; |
| 8630 | struct rpc_message msg = { |
| 8631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8632 | .rpc_argp = &args, |
| 8633 | .rpc_resp = &res, |
| 8634 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8635 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8636 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8637 | int status; |
| 8638 | |
| 8639 | if (use_integrity) { |
| 8640 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8641 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8642 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8643 | } |
| 8644 | |
| 8645 | dprintk("--> %s\n", __func__); |
| 8646 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8647 | &res.seq_res, 0); |
| 8648 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8649 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8650 | if (cred) |
| 8651 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8652 | |
| 8653 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8654 | } |
| 8655 | |
| 8656 | static int |
| 8657 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8658 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8659 | { |
| 8660 | struct nfs4_exception exception = { }; |
| 8661 | int err; |
| 8662 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8663 | /* first try using integrity protection */ |
| 8664 | err = -NFS4ERR_WRONGSEC; |
| 8665 | |
| 8666 | /* try to use integrity protection with machine cred */ |
| 8667 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8668 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8669 | flavors, true); |
| 8670 | |
| 8671 | /* |
| 8672 | * if unable to use integrity protection, or SECINFO with |
| 8673 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8674 | * disallowed by spec, but exists in deployed servers) use |
| 8675 | * the current filesystem's rpc_client and the user cred. |
| 8676 | */ |
| 8677 | if (err == -NFS4ERR_WRONGSEC) |
| 8678 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8679 | flavors, false); |
| 8680 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8681 | switch (err) { |
| 8682 | case 0: |
| 8683 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8684 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8685 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8686 | default: |
| 8687 | err = nfs4_handle_exception(server, err, &exception); |
| 8688 | } |
| 8689 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8690 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8691 | return err; |
| 8692 | } |
| 8693 | |
| 8694 | static int |
| 8695 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8696 | struct nfs_fsinfo *info) |
| 8697 | { |
| 8698 | int err; |
| 8699 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8700 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8701 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8702 | struct nfs4_secinfo4 *secinfo; |
| 8703 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8704 | |
| 8705 | page = alloc_page(GFP_KERNEL); |
| 8706 | if (!page) { |
| 8707 | err = -ENOMEM; |
| 8708 | goto out; |
| 8709 | } |
| 8710 | |
| 8711 | flavors = page_address(page); |
| 8712 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8713 | |
| 8714 | /* |
| 8715 | * Fall back on "guess and check" method if |
| 8716 | * the server doesn't support SECINFO_NO_NAME |
| 8717 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8718 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8719 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8720 | goto out_freepage; |
| 8721 | } |
| 8722 | if (err) |
| 8723 | goto out_freepage; |
| 8724 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8725 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8726 | secinfo = &flavors->flavors[i]; |
| 8727 | |
| 8728 | switch (secinfo->flavor) { |
| 8729 | case RPC_AUTH_NULL: |
| 8730 | case RPC_AUTH_UNIX: |
| 8731 | case RPC_AUTH_GSS: |
| 8732 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8733 | &secinfo->flavor_info); |
| 8734 | break; |
| 8735 | default: |
| 8736 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8737 | break; |
| 8738 | } |
| 8739 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8740 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8741 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8742 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8743 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8744 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8745 | info, flavor); |
| 8746 | if (!err) |
| 8747 | break; |
| 8748 | } |
| 8749 | } |
| 8750 | |
| 8751 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8752 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8753 | |
| 8754 | out_freepage: |
| 8755 | put_page(page); |
| 8756 | if (err == -EACCES) |
| 8757 | return -EPERM; |
| 8758 | out: |
| 8759 | return err; |
| 8760 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8761 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8762 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8763 | nfs4_stateid *stateid, |
| 8764 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8765 | { |
| 8766 | int status; |
| 8767 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8768 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8769 | }; |
| 8770 | struct nfs41_test_stateid_res res; |
| 8771 | struct rpc_message msg = { |
| 8772 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8773 | .rpc_argp = &args, |
| 8774 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8775 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8776 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8777 | struct rpc_clnt *rpc_client = server->client; |
| 8778 | |
| 8779 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8780 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8781 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8782 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8783 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8784 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8785 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8786 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8787 | if (status != NFS_OK) { |
| 8788 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8789 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8790 | } |
| 8791 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8792 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8793 | } |
| 8794 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8795 | /** |
| 8796 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8797 | * |
| 8798 | * @server: server / transport on which to perform the operation |
| 8799 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8800 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8801 | * |
| 8802 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8803 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8804 | * failed or the state ID is not currently valid. |
| 8805 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8806 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8807 | nfs4_stateid *stateid, |
| 8808 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8809 | { |
| 8810 | struct nfs4_exception exception = { }; |
| 8811 | int err; |
| 8812 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8813 | err = _nfs41_test_stateid(server, stateid, cred); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8814 | if (err != -NFS4ERR_DELAY) |
| 8815 | break; |
| 8816 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8817 | } while (exception.retry); |
| 8818 | return err; |
| 8819 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8820 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8821 | struct nfs_free_stateid_data { |
| 8822 | struct nfs_server *server; |
| 8823 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8824 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8825 | }; |
| 8826 | |
| 8827 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8828 | { |
| 8829 | struct nfs_free_stateid_data *data = calldata; |
| 8830 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8831 | &data->args.seq_args, |
| 8832 | &data->res.seq_res, |
| 8833 | task); |
| 8834 | } |
| 8835 | |
| 8836 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8837 | { |
| 8838 | struct nfs_free_stateid_data *data = calldata; |
| 8839 | |
| 8840 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8841 | |
| 8842 | switch (task->tk_status) { |
| 8843 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8844 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8845 | rpc_restart_call_prepare(task); |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | static void nfs41_free_stateid_release(void *calldata) |
| 8850 | { |
| 8851 | kfree(calldata); |
| 8852 | } |
| 8853 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8854 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8855 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8856 | .rpc_call_done = nfs41_free_stateid_done, |
| 8857 | .rpc_release = nfs41_free_stateid_release, |
| 8858 | }; |
| 8859 | |
| 8860 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
| 8861 | nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8862 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8863 | bool privileged) |
| 8864 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8865 | struct rpc_message msg = { |
| 8866 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8867 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8868 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8869 | struct rpc_task_setup task_setup = { |
| 8870 | .rpc_client = server->client, |
| 8871 | .rpc_message = &msg, |
| 8872 | .callback_ops = &nfs41_free_stateid_ops, |
| 8873 | .flags = RPC_TASK_ASYNC, |
| 8874 | }; |
| 8875 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8876 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8877 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8878 | &task_setup.rpc_client, &msg); |
| 8879 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8880 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8881 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8882 | if (!data) |
| 8883 | return ERR_PTR(-ENOMEM); |
| 8884 | data->server = server; |
| 8885 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8886 | |
| 8887 | task_setup.callback_data = data; |
| 8888 | |
| 8889 | msg.rpc_argp = &data->args; |
| 8890 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8891 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8892 | if (privileged) |
| 8893 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8894 | |
| 8895 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8896 | } |
| 8897 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8898 | /** |
| 8899 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 8900 | * |
| 8901 | * @server: server / transport on which to perform the operation |
| 8902 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8903 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8904 | * |
| 8905 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 8906 | * negative NFS4ERR value is returned. |
| 8907 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8908 | static int nfs41_free_stateid(struct nfs_server *server, |
| 8909 | nfs4_stateid *stateid, |
| 8910 | struct rpc_cred *cred) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8911 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8912 | struct rpc_task *task; |
| 8913 | int ret; |
| 8914 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8915 | task = _nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8916 | if (IS_ERR(task)) |
| 8917 | return PTR_ERR(task); |
| 8918 | ret = rpc_wait_for_completion_task(task); |
| 8919 | if (!ret) |
| 8920 | ret = task->tk_status; |
| 8921 | rpc_put_task(task); |
| 8922 | return ret; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8923 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8924 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8925 | static void |
| 8926 | 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] | 8927 | { |
| 8928 | struct rpc_task *task; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8929 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8930 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8931 | task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8932 | nfs4_free_lock_state(server, lsp); |
| 8933 | if (IS_ERR(task)) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 8934 | return; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8935 | rpc_put_task(task); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 8936 | } |
| 8937 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8938 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 8939 | const nfs4_stateid *s2) |
| 8940 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 8941 | if (s1->type != s2->type) |
| 8942 | return false; |
| 8943 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8944 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8945 | return false; |
| 8946 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8947 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8948 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 8949 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8950 | return true; |
| 8951 | |
| 8952 | return false; |
| 8953 | } |
| 8954 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 8955 | #endif /* CONFIG_NFS_V4_1 */ |
| 8956 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8957 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 8958 | const nfs4_stateid *s2) |
| 8959 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8960 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 8961 | } |
| 8962 | |
| 8963 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8964 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8965 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8966 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8967 | .recover_open = nfs4_open_reclaim, |
| 8968 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8969 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8970 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8971 | }; |
| 8972 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8973 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8974 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8975 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 8976 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 8977 | .recover_open = nfs4_open_reclaim, |
| 8978 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8979 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8980 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 8981 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8982 | }; |
| 8983 | #endif /* CONFIG_NFS_V4_1 */ |
| 8984 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8985 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 8986 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 8987 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 8988 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8989 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8990 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8991 | }; |
| 8992 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8993 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 8994 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 8995 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 8996 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 8997 | .recover_open = nfs41_open_expired, |
| 8998 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 8999 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9000 | }; |
| 9001 | #endif /* CONFIG_NFS_V4_1 */ |
| 9002 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9003 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9004 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9005 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9006 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9007 | }; |
| 9008 | |
| 9009 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9010 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9011 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9012 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9013 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9014 | }; |
| 9015 | #endif |
| 9016 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9017 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9018 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9019 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9020 | }; |
| 9021 | |
| 9022 | #if defined(CONFIG_NFS_V4_1) |
| 9023 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9024 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9025 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9026 | }; |
| 9027 | #endif /* CONFIG_NFS_V4_1 */ |
| 9028 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9029 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9030 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9031 | .init_caps = NFS_CAP_READDIRPLUS |
| 9032 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9033 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9034 | .init_client = nfs40_init_client, |
| 9035 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9036 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9037 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9038 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9039 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9040 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9041 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9042 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9043 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9044 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9045 | }; |
| 9046 | |
| 9047 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9048 | static struct nfs_seqid * |
| 9049 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9050 | { |
| 9051 | return NULL; |
| 9052 | } |
| 9053 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9054 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9055 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9056 | .init_caps = NFS_CAP_READDIRPLUS |
| 9057 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9058 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9059 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9060 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9061 | .init_client = nfs41_init_client, |
| 9062 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9063 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9064 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9065 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9066 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9067 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9068 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9069 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9070 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9071 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9072 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9073 | }; |
| 9074 | #endif |
| 9075 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9076 | #if defined(CONFIG_NFS_V4_2) |
| 9077 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9078 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9079 | .init_caps = NFS_CAP_READDIRPLUS |
| 9080 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9081 | | NFS_CAP_POSIX_LOCK |
| 9082 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9083 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9084 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9085 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9086 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9087 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9088 | | NFS_CAP_LAYOUTSTATS |
| 9089 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9090 | .init_client = nfs41_init_client, |
| 9091 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9092 | .match_stateid = nfs41_match_stateid, |
| 9093 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9094 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9095 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9096 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9097 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9098 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9099 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9100 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9101 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9102 | }; |
| 9103 | #endif |
| 9104 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9105 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9106 | [0] = &nfs_v4_0_minor_ops, |
| 9107 | #if defined(CONFIG_NFS_V4_1) |
| 9108 | [1] = &nfs_v4_1_minor_ops, |
| 9109 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9110 | #if defined(CONFIG_NFS_V4_2) |
| 9111 | [2] = &nfs_v4_2_minor_ops, |
| 9112 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9113 | }; |
| 9114 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9115 | 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] | 9116 | { |
| 9117 | ssize_t error, error2; |
| 9118 | |
| 9119 | error = generic_listxattr(dentry, list, size); |
| 9120 | if (error < 0) |
| 9121 | return error; |
| 9122 | if (list) { |
| 9123 | list += error; |
| 9124 | size -= error; |
| 9125 | } |
| 9126 | |
| 9127 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9128 | if (error2 < 0) |
| 9129 | return error2; |
| 9130 | return error + error2; |
| 9131 | } |
| 9132 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9133 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9134 | .create = nfs_create, |
| 9135 | .lookup = nfs_lookup, |
| 9136 | .atomic_open = nfs_atomic_open, |
| 9137 | .link = nfs_link, |
| 9138 | .unlink = nfs_unlink, |
| 9139 | .symlink = nfs_symlink, |
| 9140 | .mkdir = nfs_mkdir, |
| 9141 | .rmdir = nfs_rmdir, |
| 9142 | .mknod = nfs_mknod, |
| 9143 | .rename = nfs_rename, |
| 9144 | .permission = nfs_permission, |
| 9145 | .getattr = nfs_getattr, |
| 9146 | .setattr = nfs_setattr, |
| 9147 | .getxattr = generic_getxattr, |
| 9148 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9149 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9150 | .removexattr = generic_removexattr, |
| 9151 | }; |
| 9152 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9153 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9154 | .permission = nfs_permission, |
| 9155 | .getattr = nfs_getattr, |
| 9156 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9157 | .getxattr = generic_getxattr, |
| 9158 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9159 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9160 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9161 | }; |
| 9162 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9163 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9164 | .version = 4, /* protocol version */ |
| 9165 | .dentry_ops = &nfs4_dentry_operations, |
| 9166 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9167 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9168 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9169 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9170 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9171 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9172 | .getattr = nfs4_proc_getattr, |
| 9173 | .setattr = nfs4_proc_setattr, |
| 9174 | .lookup = nfs4_proc_lookup, |
| 9175 | .access = nfs4_proc_access, |
| 9176 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9177 | .create = nfs4_proc_create, |
| 9178 | .remove = nfs4_proc_remove, |
| 9179 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9180 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9181 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9182 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9183 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9184 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9185 | .link = nfs4_proc_link, |
| 9186 | .symlink = nfs4_proc_symlink, |
| 9187 | .mkdir = nfs4_proc_mkdir, |
| 9188 | .rmdir = nfs4_proc_remove, |
| 9189 | .readdir = nfs4_proc_readdir, |
| 9190 | .mknod = nfs4_proc_mknod, |
| 9191 | .statfs = nfs4_proc_statfs, |
| 9192 | .fsinfo = nfs4_proc_fsinfo, |
| 9193 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9194 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9195 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9196 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9197 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9198 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9199 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9200 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9201 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9202 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9203 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9204 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9205 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9206 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9207 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9208 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9209 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9210 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9211 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9212 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9213 | .create_server = nfs4_create_server, |
| 9214 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9215 | }; |
| 9216 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9217 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9218 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9219 | .list = nfs4_xattr_list_nfs4_acl, |
| 9220 | .get = nfs4_xattr_get_nfs4_acl, |
| 9221 | .set = nfs4_xattr_set_nfs4_acl, |
| 9222 | }; |
| 9223 | |
| 9224 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9225 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9226 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9227 | &nfs4_xattr_nfs4_label_handler, |
| 9228 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9229 | NULL |
| 9230 | }; |
| 9231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9232 | /* |
| 9233 | * Local variables: |
| 9234 | * c-basic-offset: 8 |
| 9235 | * End: |
| 9236 | */ |