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 *); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 102 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
| 103 | struct rpc_cred *, bool); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 104 | #endif |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 107 | static inline struct nfs4_label * |
| 108 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 109 | struct iattr *sattr, struct nfs4_label *label) |
| 110 | { |
| 111 | int err; |
| 112 | |
| 113 | if (label == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
| 117 | return NULL; |
| 118 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 119 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
| 120 | &dentry->d_name, (void **)&label->label, &label->len); |
| 121 | if (err == 0) |
| 122 | return label; |
| 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | static inline void |
| 127 | nfs4_label_release_security(struct nfs4_label *label) |
| 128 | { |
| 129 | if (label) |
| 130 | security_release_secctx(label->label, label->len); |
| 131 | } |
| 132 | static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 133 | { |
| 134 | if (label) |
| 135 | return server->attr_bitmask; |
| 136 | |
| 137 | return server->attr_bitmask_nl; |
| 138 | } |
| 139 | #else |
| 140 | static inline struct nfs4_label * |
| 141 | nfs4_label_init_security(struct inode *dir, struct dentry *dentry, |
| 142 | struct iattr *sattr, struct nfs4_label *l) |
| 143 | { return NULL; } |
| 144 | static inline void |
| 145 | nfs4_label_release_security(struct nfs4_label *label) |
| 146 | { return; } |
| 147 | static inline u32 * |
| 148 | nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) |
| 149 | { return server->attr_bitmask; } |
| 150 | #endif |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 153 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 155 | if (err >= -1000) |
| 156 | return err; |
| 157 | switch (err) { |
| 158 | case -NFS4ERR_RESOURCE: |
Weston Andros Adamson | 3000512 | 2013-02-28 20:30:10 -0500 | [diff] [blame] | 159 | case -NFS4ERR_LAYOUTTRYLATER: |
| 160 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 161 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 162 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 8897538 | 2013-08-13 16:37:38 -0400 | [diff] [blame] | 163 | case -NFS4ERR_WRONG_CRED: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 164 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 165 | case -NFS4ERR_BADOWNER: |
| 166 | case -NFS4ERR_BADNAME: |
| 167 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 168 | case -NFS4ERR_SHARE_DENIED: |
| 169 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 170 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 171 | return -EPROTONOSUPPORT; |
Trond Myklebust | 6e3cf24 | 2013-03-23 15:22:45 -0400 | [diff] [blame] | 172 | case -NFS4ERR_FILE_OPEN: |
| 173 | return -EBUSY; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 174 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 176 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 179 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This is our standard bitmap for GETATTR requests. |
| 184 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 185 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID, |
| 191 | FATTR4_WORD1_MODE |
| 192 | | FATTR4_WORD1_NUMLINKS |
| 193 | | FATTR4_WORD1_OWNER |
| 194 | | FATTR4_WORD1_OWNER_GROUP |
| 195 | | FATTR4_WORD1_RAWDEV |
| 196 | | FATTR4_WORD1_SPACE_USED |
| 197 | | FATTR4_WORD1_TIME_ACCESS |
| 198 | | FATTR4_WORD1_TIME_METADATA |
Anna Schumaker | ea96d1e | 2015-04-03 14:35:59 -0400 | [diff] [blame] | 199 | | FATTR4_WORD1_TIME_MODIFY |
| 200 | | FATTR4_WORD1_MOUNTED_ON_FILEID, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 202 | FATTR4_WORD2_SECURITY_LABEL |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 206 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 207 | FATTR4_WORD0_TYPE |
| 208 | | FATTR4_WORD0_CHANGE |
| 209 | | FATTR4_WORD0_SIZE |
| 210 | | FATTR4_WORD0_FSID |
| 211 | | FATTR4_WORD0_FILEID, |
| 212 | FATTR4_WORD1_MODE |
| 213 | | FATTR4_WORD1_NUMLINKS |
| 214 | | FATTR4_WORD1_OWNER |
| 215 | | FATTR4_WORD1_OWNER_GROUP |
| 216 | | FATTR4_WORD1_RAWDEV |
| 217 | | FATTR4_WORD1_SPACE_USED |
| 218 | | FATTR4_WORD1_TIME_ACCESS |
| 219 | | FATTR4_WORD1_TIME_METADATA |
| 220 | | FATTR4_WORD1_TIME_MODIFY, |
| 221 | FATTR4_WORD2_MDSTHRESHOLD |
Trond Myklebust | 95864c9 | 2015-12-26 15:06:03 -0500 | [diff] [blame] | 222 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 223 | | FATTR4_WORD2_SECURITY_LABEL |
| 224 | #endif |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 227 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 228 | FATTR4_WORD0_TYPE |
| 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 | |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 331 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
| 332 | nfs4_stateid *stateid, |
| 333 | struct rpc_cred *cred) |
| 334 | { |
| 335 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
| 336 | |
| 337 | ops->test_and_free_expired(server, stateid, cred); |
| 338 | } |
| 339 | |
| 340 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
| 341 | nfs4_stateid *stateid, |
| 342 | struct rpc_cred *cred) |
| 343 | { |
| 344 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
| 345 | nfs4_test_and_free_stateid(server, stateid, cred); |
| 346 | } |
| 347 | |
| 348 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
| 349 | const nfs4_stateid *stateid, |
| 350 | struct rpc_cred *cred) |
| 351 | { |
| 352 | nfs4_stateid tmp; |
| 353 | |
| 354 | nfs4_stateid_copy(&tmp, stateid); |
| 355 | __nfs4_free_revoked_stateid(server, &tmp, cred); |
| 356 | } |
| 357 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 358 | static long nfs4_update_delay(long *timeout) |
| 359 | { |
| 360 | long ret; |
| 361 | if (!timeout) |
| 362 | return NFS4_POLL_RETRY_MAX; |
| 363 | if (*timeout <= 0) |
| 364 | *timeout = NFS4_POLL_RETRY_MIN; |
| 365 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 366 | *timeout = NFS4_POLL_RETRY_MAX; |
| 367 | ret = *timeout; |
| 368 | *timeout <<= 1; |
| 369 | return ret; |
| 370 | } |
| 371 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 372 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 373 | { |
| 374 | int res = 0; |
| 375 | |
| 376 | might_sleep(); |
| 377 | |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 378 | freezable_schedule_timeout_killable_unsafe( |
| 379 | nfs4_update_delay(timeout)); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 380 | if (fatal_signal_pending(current)) |
| 381 | res = -ERESTARTSYS; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 382 | return res; |
| 383 | } |
| 384 | |
| 385 | /* This is the error handling routine for processes that are allowed |
| 386 | * to sleep. |
| 387 | */ |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 388 | static int nfs4_do_handle_exception(struct nfs_server *server, |
| 389 | int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 390 | { |
| 391 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 392 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 393 | const nfs4_stateid *stateid = exception->stateid; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 394 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 395 | int ret = errorcode; |
| 396 | |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 397 | exception->delay = 0; |
| 398 | exception->recovering = 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 399 | exception->retry = 0; |
| 400 | switch(errorcode) { |
| 401 | case 0: |
| 402 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 403 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 5ba1244 | 2015-06-16 11:26:35 -0400 | [diff] [blame] | 404 | case -NFS4ERR_DELEG_REVOKED: |
| 405 | case -NFS4ERR_ADMIN_REVOKED: |
| 406 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 407 | if (inode) { |
| 408 | int err; |
| 409 | |
| 410 | err = nfs_async_inode_return_delegation(inode, |
| 411 | stateid); |
| 412 | if (err == 0) |
| 413 | goto wait_on_recovery; |
| 414 | if (stateid != NULL && stateid->type == NFS4_DELEGATION_STATEID_TYPE) { |
| 415 | exception->retry = 1; |
| 416 | break; |
| 417 | } |
| 418 | } |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 419 | if (state == NULL) |
| 420 | break; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 421 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 422 | if (ret < 0) |
| 423 | break; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 424 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 425 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 426 | if (state != NULL) { |
| 427 | ret = nfs4_schedule_stateid_recovery(server, state); |
| 428 | if (ret < 0) |
| 429 | break; |
| 430 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 431 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 432 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 433 | nfs4_schedule_lease_recovery(clp); |
| 434 | goto wait_on_recovery; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 435 | case -NFS4ERR_MOVED: |
| 436 | ret = nfs4_schedule_migration_recovery(server); |
| 437 | if (ret < 0) |
| 438 | break; |
| 439 | goto wait_on_recovery; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 440 | case -NFS4ERR_LEASE_MOVED: |
| 441 | nfs4_schedule_lease_moved_recovery(clp); |
| 442 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 443 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 444 | case -NFS4ERR_BADSESSION: |
| 445 | case -NFS4ERR_BADSLOT: |
| 446 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 447 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 448 | case -NFS4ERR_DEADSESSION: |
| 449 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 450 | case -NFS4ERR_SEQ_MISORDERED: |
| 451 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 452 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 453 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Bryan Schumaker | 399f11c | 2012-10-30 16:06:35 -0400 | [diff] [blame] | 454 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 455 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 456 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 457 | if (exception->timeout > HZ) { |
| 458 | /* We have retried a decent amount, time to |
| 459 | * fail |
| 460 | */ |
| 461 | ret = -EBUSY; |
| 462 | break; |
| 463 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 464 | case -NFS4ERR_DELAY: |
Trond Myklebust | 2598ed3 | 2015-09-20 16:10:18 -0400 | [diff] [blame] | 465 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
| 466 | case -NFS4ERR_GRACE: |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 467 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 468 | case -NFS4ERR_RECALLCONFLICT: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 469 | exception->delay = 1; |
| 470 | return 0; |
| 471 | |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 472 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 473 | case -NFS4ERR_OLD_STATEID: |
| 474 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 475 | break; |
| 476 | case -NFS4ERR_BADOWNER: |
| 477 | /* The following works around a Linux server bug! */ |
| 478 | case -NFS4ERR_BADNAME: |
| 479 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 480 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 481 | exception->retry = 1; |
| 482 | printk(KERN_WARNING "NFS: v4 server %s " |
| 483 | "does not accept raw " |
| 484 | "uid/gids. " |
| 485 | "Reenabling the idmapper.\n", |
| 486 | server->nfs_client->cl_hostname); |
| 487 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 488 | } |
| 489 | /* We failed to handle the error */ |
| 490 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 491 | wait_on_recovery: |
Trond Myklebust | b3c2aa0 | 2015-09-20 14:32:45 -0400 | [diff] [blame] | 492 | exception->recovering = 1; |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | /* This is the error handling routine for processes that are allowed |
| 497 | * to sleep. |
| 498 | */ |
| 499 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 500 | { |
| 501 | struct nfs_client *clp = server->nfs_client; |
| 502 | int ret; |
| 503 | |
| 504 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 505 | if (exception->delay) { |
| 506 | ret = nfs4_delay(server->client, &exception->timeout); |
| 507 | goto out_retry; |
| 508 | } |
| 509 | if (exception->recovering) { |
| 510 | ret = nfs4_wait_clnt_recover(clp); |
| 511 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 512 | return -EIO; |
| 513 | goto out_retry; |
| 514 | } |
| 515 | return ret; |
| 516 | out_retry: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 517 | if (ret == 0) |
| 518 | exception->retry = 1; |
| 519 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Trond Myklebust | 037fc98 | 2015-09-20 15:51:00 -0400 | [diff] [blame] | 522 | static int |
| 523 | nfs4_async_handle_exception(struct rpc_task *task, struct nfs_server *server, |
| 524 | int errorcode, struct nfs4_exception *exception) |
| 525 | { |
| 526 | struct nfs_client *clp = server->nfs_client; |
| 527 | int ret; |
| 528 | |
| 529 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
| 530 | if (exception->delay) { |
| 531 | rpc_delay(task, nfs4_update_delay(&exception->timeout)); |
| 532 | goto out_retry; |
| 533 | } |
| 534 | if (exception->recovering) { |
| 535 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 536 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 537 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 538 | goto out_retry; |
| 539 | } |
| 540 | if (test_bit(NFS_MIG_FAILED, &server->mig_status)) |
| 541 | ret = -EIO; |
| 542 | return ret; |
| 543 | out_retry: |
| 544 | if (ret == 0) |
| 545 | exception->retry = 1; |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | static int |
| 550 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server, |
| 551 | struct nfs4_state *state, long *timeout) |
| 552 | { |
| 553 | struct nfs4_exception exception = { |
| 554 | .state = state, |
| 555 | }; |
| 556 | |
| 557 | if (task->tk_status >= 0) |
| 558 | return 0; |
| 559 | if (timeout) |
| 560 | exception.timeout = *timeout; |
| 561 | task->tk_status = nfs4_async_handle_exception(task, server, |
| 562 | task->tk_status, |
| 563 | &exception); |
| 564 | if (exception.delay && timeout) |
| 565 | *timeout = exception.timeout; |
| 566 | if (exception.retry) |
| 567 | return -EAGAIN; |
| 568 | return 0; |
| 569 | } |
| 570 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 571 | /* |
| 572 | * Return 'true' if 'clp' is using an rpc_client that is integrity protected |
| 573 | * or 'false' otherwise. |
| 574 | */ |
| 575 | static bool _nfs4_is_integrity_protected(struct nfs_client *clp) |
| 576 | { |
| 577 | rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 578 | |
| 579 | if (flavor == RPC_AUTH_GSS_KRB5I || |
| 580 | flavor == RPC_AUTH_GSS_KRB5P) |
| 581 | return true; |
| 582 | |
| 583 | return false; |
| 584 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 585 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 586 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | spin_lock(&clp->cl_lock); |
| 589 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 590 | clp->cl_last_renewal = timestamp; |
| 591 | spin_unlock(&clp->cl_lock); |
| 592 | } |
| 593 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 594 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 595 | { |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 596 | struct nfs_client *clp = server->nfs_client; |
| 597 | |
| 598 | if (!nfs4_has_session(clp)) |
| 599 | do_renew_lease(clp, timestamp); |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 602 | struct nfs4_call_sync_data { |
| 603 | const struct nfs_server *seq_server; |
| 604 | struct nfs4_sequence_args *seq_args; |
| 605 | struct nfs4_sequence_res *seq_res; |
| 606 | }; |
| 607 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 608 | void nfs4_init_sequence(struct nfs4_sequence_args *args, |
| 609 | struct nfs4_sequence_res *res, int cache_reply) |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 610 | { |
| 611 | args->sa_slot = NULL; |
| 612 | args->sa_cache_this = cache_reply; |
| 613 | args->sa_privileged = 0; |
| 614 | |
| 615 | res->sr_slot = NULL; |
| 616 | } |
| 617 | |
| 618 | static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) |
| 619 | { |
| 620 | args->sa_privileged = 1; |
| 621 | } |
| 622 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 623 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 624 | struct nfs4_sequence_args *args, |
| 625 | struct nfs4_sequence_res *res, |
| 626 | struct rpc_task *task) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 627 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 628 | struct nfs4_slot *slot; |
| 629 | |
| 630 | /* slot already allocated? */ |
| 631 | if (res->sr_slot != NULL) |
| 632 | goto out_start; |
| 633 | |
| 634 | spin_lock(&tbl->slot_tbl_lock); |
| 635 | if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
| 636 | goto out_sleep; |
| 637 | |
| 638 | slot = nfs4_alloc_slot(tbl); |
| 639 | if (IS_ERR(slot)) { |
| 640 | if (slot == ERR_PTR(-ENOMEM)) |
| 641 | task->tk_timeout = HZ >> 2; |
| 642 | goto out_sleep; |
| 643 | } |
| 644 | spin_unlock(&tbl->slot_tbl_lock); |
| 645 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 646 | slot->privileged = args->sa_privileged ? 1 : 0; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 647 | args->sa_slot = slot; |
| 648 | res->sr_slot = slot; |
| 649 | |
| 650 | out_start: |
| 651 | rpc_call_start(task); |
| 652 | return 0; |
| 653 | |
| 654 | out_sleep: |
| 655 | if (args->sa_privileged) |
| 656 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 657 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 658 | else |
| 659 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 660 | spin_unlock(&tbl->slot_tbl_lock); |
| 661 | return -EAGAIN; |
| 662 | } |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 663 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 664 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 665 | static void nfs40_sequence_free_slot(struct nfs4_sequence_res *res) |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 666 | { |
| 667 | struct nfs4_slot *slot = res->sr_slot; |
| 668 | struct nfs4_slot_table *tbl; |
| 669 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 670 | tbl = slot->table; |
| 671 | spin_lock(&tbl->slot_tbl_lock); |
| 672 | if (!nfs41_wake_and_assign_slot(tbl, slot)) |
| 673 | nfs4_free_slot(tbl, slot); |
| 674 | spin_unlock(&tbl->slot_tbl_lock); |
| 675 | |
| 676 | res->sr_slot = NULL; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static int nfs40_sequence_done(struct rpc_task *task, |
| 680 | struct nfs4_sequence_res *res) |
| 681 | { |
| 682 | if (res->sr_slot != NULL) |
| 683 | nfs40_sequence_free_slot(res); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 684 | return 1; |
| 685 | } |
| 686 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 687 | #if defined(CONFIG_NFS_V4_1) |
| 688 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 689 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 690 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 691 | struct nfs4_session *session; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 692 | struct nfs4_slot_table *tbl; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 693 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 694 | bool send_new_highest_used_slotid = false; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 695 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 696 | tbl = slot->table; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 697 | session = tbl->session; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 698 | |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 699 | /* Bump the slot sequence number */ |
| 700 | if (slot->seq_done) |
| 701 | slot->seq_nr++; |
| 702 | slot->seq_done = 0; |
| 703 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 704 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 705 | /* Be nice to the server: try to ensure that the last transmitted |
| 706 | * value for highest_user_slotid <= target_highest_slotid |
| 707 | */ |
| 708 | if (tbl->highest_used_slotid > tbl->target_highest_slotid) |
| 709 | send_new_highest_used_slotid = true; |
| 710 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 711 | if (nfs41_wake_and_assign_slot(tbl, slot)) { |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 712 | send_new_highest_used_slotid = false; |
| 713 | goto out_unlock; |
| 714 | } |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 715 | nfs4_free_slot(tbl, slot); |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 716 | |
| 717 | if (tbl->highest_used_slotid != NFS4_NO_SLOT) |
| 718 | send_new_highest_used_slotid = false; |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 719 | out_unlock: |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 720 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 721 | res->sr_slot = NULL; |
Trond Myklebust | c10e449 | 2012-11-26 16:16:54 -0500 | [diff] [blame] | 722 | if (send_new_highest_used_slotid) |
Anna Schumaker | 3f10a6a | 2015-07-13 14:01:31 -0400 | [diff] [blame] | 723 | nfs41_notify_server(session->clp); |
Trond Myklebust | 045d2a6 | 2016-08-28 13:25:43 -0400 | [diff] [blame] | 724 | if (waitqueue_active(&tbl->slot_waitq)) |
| 725 | wake_up_all(&tbl->slot_waitq); |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 726 | } |
| 727 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 728 | static int nfs41_sequence_process(struct rpc_task *task, |
| 729 | struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 730 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 731 | struct nfs4_session *session; |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 732 | struct nfs4_slot *slot = res->sr_slot; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 733 | struct nfs_client *clp; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 734 | bool interrupted = false; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 735 | int ret = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 736 | |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 737 | if (slot == NULL) |
| 738 | goto out_noaction; |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 739 | /* don't increment the sequence number if the task wasn't sent */ |
| 740 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 741 | goto out; |
| 742 | |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 743 | session = slot->table->session; |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 744 | |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 745 | if (slot->interrupted) { |
| 746 | slot->interrupted = 0; |
| 747 | interrupted = true; |
| 748 | } |
| 749 | |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 750 | trace_nfs4_sequence_done(session, res); |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 751 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 752 | switch (res->sr_status) { |
| 753 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 754 | /* Update the slot's sequence and clientid lease timer */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 755 | slot->seq_done = 1; |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 756 | clp = session->clp; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 757 | do_renew_lease(clp, res->sr_timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 758 | /* Check sequence flags */ |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 759 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
| 760 | !!slot->privileged); |
Trond Myklebust | 464ee9f | 2012-11-20 12:49:27 -0500 | [diff] [blame] | 761 | nfs41_update_target_slotid(slot->table, slot, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 762 | break; |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 763 | case 1: |
| 764 | /* |
| 765 | * sr_status remains 1 if an RPC level error occurred. |
| 766 | * The server may or may not have processed the sequence |
| 767 | * operation.. |
| 768 | * Mark the slot as having hosted an interrupted RPC call. |
| 769 | */ |
| 770 | slot->interrupted = 1; |
| 771 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 772 | case -NFS4ERR_DELAY: |
| 773 | /* The server detected a resend of the RPC call and |
| 774 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 775 | * of RFC5661. |
| 776 | */ |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 777 | dprintk("%s: slot=%u seq=%u: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 778 | __func__, |
Trond Myklebust | df2fabf | 2012-11-16 12:45:06 -0500 | [diff] [blame] | 779 | slot->slot_nr, |
Trond Myklebust | 933602e | 2012-11-16 12:12:38 -0500 | [diff] [blame] | 780 | slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 781 | goto out_retry; |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 782 | case -NFS4ERR_BADSLOT: |
| 783 | /* |
| 784 | * The slot id we used was probably retired. Try again |
| 785 | * using a different slot id. |
| 786 | */ |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 787 | goto retry_nowait; |
| 788 | case -NFS4ERR_SEQ_MISORDERED: |
| 789 | /* |
Trond Myklebust | ac20d16 | 2012-12-15 15:36:07 -0500 | [diff] [blame] | 790 | * Was the last operation on this sequence interrupted? |
| 791 | * If so, retry after bumping the sequence number. |
| 792 | */ |
| 793 | if (interrupted) { |
| 794 | ++slot->seq_nr; |
| 795 | goto retry_nowait; |
| 796 | } |
| 797 | /* |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 798 | * Could this slot have been previously retired? |
| 799 | * If so, then the server may be expecting seq_nr = 1! |
| 800 | */ |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 801 | if (slot->seq_nr != 1) { |
| 802 | slot->seq_nr = 1; |
| 803 | goto retry_nowait; |
| 804 | } |
| 805 | break; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 806 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 807 | ++slot->seq_nr; |
| 808 | goto retry_nowait; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 809 | default: |
| 810 | /* Just update the slot sequence no. */ |
Trond Myklebust | 07e8dcb | 2016-08-28 10:28:25 -0400 | [diff] [blame] | 811 | slot->seq_done = 1; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 812 | } |
| 813 | out: |
| 814 | /* The session may be reset by one of the error handlers. */ |
| 815 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | a13ce7c | 2014-01-29 12:24:03 -0500 | [diff] [blame] | 816 | out_noaction: |
Trond Myklebust | 8556307 | 2012-12-11 10:31:12 -0500 | [diff] [blame] | 817 | return ret; |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 818 | retry_nowait: |
| 819 | if (rpc_restart_call_prepare(task)) { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 820 | nfs41_sequence_free_slot(res); |
Trond Myklebust | e879444 | 2012-12-15 13:56:18 -0500 | [diff] [blame] | 821 | task->tk_status = 0; |
| 822 | ret = 0; |
| 823 | } |
| 824 | goto out; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 825 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 826 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 827 | goto out; |
| 828 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 829 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 830 | } |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 831 | |
| 832 | int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 833 | { |
| 834 | if (!nfs41_sequence_process(task, res)) |
| 835 | return 0; |
| 836 | if (res->sr_slot != NULL) |
| 837 | nfs41_sequence_free_slot(res); |
| 838 | return 1; |
| 839 | |
| 840 | } |
Andy Adamson | f9c96fc | 2014-01-29 11:34:38 -0500 | [diff] [blame] | 841 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 842 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 843 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 844 | { |
| 845 | if (res->sr_slot == NULL) |
| 846 | return 1; |
| 847 | if (res->sr_slot->table->session != NULL) |
| 848 | return nfs41_sequence_process(task, res); |
| 849 | return nfs40_sequence_done(task, res); |
| 850 | } |
| 851 | |
| 852 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 853 | { |
| 854 | if (res->sr_slot != NULL) { |
| 855 | if (res->sr_slot->table->session != NULL) |
| 856 | nfs41_sequence_free_slot(res); |
| 857 | else |
| 858 | nfs40_sequence_free_slot(res); |
| 859 | } |
| 860 | } |
| 861 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 862 | 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] | 863 | { |
Trond Myklebust | e3725ec | 2012-11-16 12:25:01 -0500 | [diff] [blame] | 864 | if (res->sr_slot == NULL) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 865 | return 1; |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 866 | if (!res->sr_slot->table->session) |
| 867 | return nfs40_sequence_done(task, res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 868 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 869 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 870 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 871 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 872 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 873 | struct nfs4_sequence_args *args, |
| 874 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 875 | struct rpc_task *task) |
| 876 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 877 | struct nfs4_slot *slot; |
| 878 | struct nfs4_slot_table *tbl; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 879 | |
| 880 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 881 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 882 | if (res->sr_slot != NULL) |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 883 | goto out_success; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 884 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 885 | tbl = &session->fc_slot_table; |
| 886 | |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 887 | task->tk_timeout = 0; |
| 888 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 889 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 890 | if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) && |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 891 | !args->sa_privileged) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 892 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 893 | dprintk("%s session is draining\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 894 | goto out_sleep; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 895 | } |
| 896 | |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 897 | slot = nfs4_alloc_slot(tbl); |
Trond Myklebust | 69d206b | 2012-11-22 13:21:02 -0500 | [diff] [blame] | 898 | if (IS_ERR(slot)) { |
| 899 | /* If out of memory, try again in 1/4 second */ |
| 900 | if (slot == ERR_PTR(-ENOMEM)) |
| 901 | task->tk_timeout = HZ >> 2; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 902 | dprintk("<-- %s: no free slots\n", __func__); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 903 | goto out_sleep; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 904 | } |
| 905 | spin_unlock(&tbl->slot_tbl_lock); |
| 906 | |
Trond Myklebust | 0a014a4 | 2016-09-22 13:38:51 -0400 | [diff] [blame] | 907 | slot->privileged = args->sa_privileged ? 1 : 0; |
Trond Myklebust | 2b2fa71 | 2012-11-16 12:58:36 -0500 | [diff] [blame] | 908 | args->sa_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 909 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 910 | dprintk("<-- %s slotid=%u seqid=%u\n", __func__, |
Trond Myklebust | 2dc03b7 | 2012-11-16 16:10:11 -0500 | [diff] [blame] | 911 | slot->slot_nr, slot->seq_nr); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 912 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 913 | res->sr_slot = slot; |
Trond Myklebust | 8e63b6a | 2012-12-15 15:21:52 -0500 | [diff] [blame] | 914 | res->sr_timestamp = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 915 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 916 | /* |
| 917 | * sr_status is only set in decode_sequence, and so will remain |
| 918 | * set to 1 if an rpc level failure occurs. |
| 919 | */ |
| 920 | res->sr_status = 1; |
Trond Myklebust | 2f92ae3 | 2013-08-14 17:58:28 -0400 | [diff] [blame] | 921 | trace_nfs4_setup_sequence(session, args); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 922 | out_success: |
| 923 | rpc_call_start(task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 924 | return 0; |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 925 | out_sleep: |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 926 | /* Privileged tasks are queued with top priority */ |
| 927 | if (args->sa_privileged) |
Trond Myklebust | 1e1093c | 2012-11-01 16:44:05 -0400 | [diff] [blame] | 928 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
| 929 | NULL, RPC_PRIORITY_PRIVILEGED); |
| 930 | else |
| 931 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Trond Myklebust | 7b939a3 | 2012-11-01 15:19:46 -0400 | [diff] [blame] | 932 | spin_unlock(&tbl->slot_tbl_lock); |
| 933 | return -EAGAIN; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 934 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 935 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 936 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 937 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 938 | struct nfs4_sequence_args *args, |
| 939 | struct nfs4_sequence_res *res, |
| 940 | struct rpc_task *task) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 941 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 942 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 943 | int ret = 0; |
| 944 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 945 | if (!session) |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 946 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 947 | args, res, task); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 948 | |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 949 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 950 | __func__, session->clp, session, res->sr_slot ? |
Chuck Lever | e8d9238 | 2013-08-09 12:47:51 -0400 | [diff] [blame] | 951 | res->sr_slot->slot_nr : NFS4_NO_SLOT); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 952 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 953 | ret = nfs41_setup_sequence(session, args, res, task); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 954 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 955 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 956 | return ret; |
| 957 | } |
| 958 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 959 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 960 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 961 | struct nfs4_call_sync_data *data = calldata; |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 962 | struct nfs4_session *session = nfs4_get_session(data->seq_server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 963 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 964 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 965 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 966 | nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 967 | } |
| 968 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 969 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 970 | { |
Chuck Lever | 2a3eb2b | 2013-08-09 12:48:00 -0400 | [diff] [blame] | 971 | struct nfs4_call_sync_data *data = calldata; |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 972 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 973 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 974 | } |
| 975 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 976 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 977 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 978 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 979 | }; |
| 980 | |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 981 | #else /* !CONFIG_NFS_V4_1 */ |
| 982 | |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 983 | static int nfs4_setup_sequence(const struct nfs_server *server, |
| 984 | struct nfs4_sequence_args *args, |
| 985 | struct nfs4_sequence_res *res, |
| 986 | struct rpc_task *task) |
| 987 | { |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 988 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 989 | args, res, task); |
Chuck Lever | 5a580e0 | 2013-08-09 12:48:09 -0400 | [diff] [blame] | 990 | } |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 991 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 992 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 993 | { |
| 994 | return nfs40_sequence_done(task, res); |
| 995 | } |
| 996 | |
| 997 | static void nfs4_sequence_free_slot(struct nfs4_sequence_res *res) |
| 998 | { |
| 999 | if (res->sr_slot != NULL) |
| 1000 | nfs40_sequence_free_slot(res); |
| 1001 | } |
| 1002 | |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1003 | int nfs4_sequence_done(struct rpc_task *task, |
| 1004 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1005 | { |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1006 | return nfs40_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1007 | } |
Peng Tao | 2c4b131 | 2014-06-11 05:24:16 +0800 | [diff] [blame] | 1008 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
Chuck Lever | 3bd2384 | 2013-08-09 12:49:19 -0400 | [diff] [blame] | 1009 | |
| 1010 | #endif /* !CONFIG_NFS_V4_1 */ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1011 | |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1012 | static void nfs40_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 1013 | { |
| 1014 | struct nfs4_call_sync_data *data = calldata; |
| 1015 | nfs4_setup_sequence(data->seq_server, |
| 1016 | data->seq_args, data->seq_res, task); |
| 1017 | } |
| 1018 | |
| 1019 | static void nfs40_call_sync_done(struct rpc_task *task, void *calldata) |
| 1020 | { |
| 1021 | struct nfs4_call_sync_data *data = calldata; |
| 1022 | nfs4_sequence_done(task, data->seq_res); |
| 1023 | } |
| 1024 | |
| 1025 | static const struct rpc_call_ops nfs40_call_sync_ops = { |
| 1026 | .rpc_call_prepare = nfs40_call_sync_prepare, |
| 1027 | .rpc_call_done = nfs40_call_sync_done, |
| 1028 | }; |
| 1029 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1030 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1031 | struct nfs_server *server, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1032 | struct rpc_message *msg, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1033 | struct nfs4_sequence_args *args, |
| 1034 | struct nfs4_sequence_res *res) |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1035 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1036 | int ret; |
| 1037 | struct rpc_task *task; |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1038 | struct nfs_client *clp = server->nfs_client; |
| 1039 | struct nfs4_call_sync_data data = { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1040 | .seq_server = server, |
| 1041 | .seq_args = args, |
| 1042 | .seq_res = res, |
| 1043 | }; |
| 1044 | struct rpc_task_setup task_setup = { |
| 1045 | .rpc_client = clnt, |
| 1046 | .rpc_message = msg, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1047 | .callback_ops = clp->cl_mvops->call_sync_ops, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1048 | .callback_data = &data |
| 1049 | }; |
| 1050 | |
| 1051 | task = rpc_run_task(&task_setup); |
| 1052 | if (IS_ERR(task)) |
| 1053 | ret = PTR_ERR(task); |
| 1054 | else { |
| 1055 | ret = task->tk_status; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 1056 | rpc_put_task(task); |
| 1057 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1058 | return ret; |
| 1059 | } |
| 1060 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1061 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 1062 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1063 | struct rpc_message *msg, |
| 1064 | struct nfs4_sequence_args *args, |
| 1065 | struct nfs4_sequence_res *res, |
| 1066 | int cache_reply) |
| 1067 | { |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 1068 | nfs4_init_sequence(args, res, cache_reply); |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 1069 | return nfs4_call_sync_sequence(clnt, server, msg, args, res); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 1070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
| 1073 | { |
| 1074 | struct nfs_inode *nfsi = NFS_I(dir); |
| 1075 | |
| 1076 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 1077 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1078 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 1080 | dir->i_version = cinfo->after; |
Trond Myklebust | 3235b40 | 2015-02-26 19:52:06 -0500 | [diff] [blame] | 1081 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 1082 | nfs_fscache_invalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | spin_unlock(&dir->i_lock); |
| 1084 | } |
| 1085 | |
| 1086 | struct nfs4_opendata { |
| 1087 | struct kref kref; |
| 1088 | struct nfs_openargs o_arg; |
| 1089 | struct nfs_openres o_res; |
| 1090 | struct nfs_open_confirmargs c_arg; |
| 1091 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1092 | struct nfs4_string owner_name; |
| 1093 | struct nfs4_string group_name; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1094 | struct nfs4_label *a_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | struct nfs_fattr f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1096 | struct nfs4_label *f_label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1098 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | struct nfs4_state_owner *owner; |
| 1100 | struct nfs4_state *state; |
| 1101 | struct iattr attrs; |
| 1102 | unsigned long timestamp; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1103 | unsigned int rpc_done : 1; |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 1104 | unsigned int file_created : 1; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1105 | unsigned int is_recover : 1; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1106 | int rpc_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | int cancelled; |
| 1108 | }; |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 1109 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1110 | static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, |
| 1111 | int err, struct nfs4_exception *exception) |
| 1112 | { |
| 1113 | if (err != -EINVAL) |
| 1114 | return false; |
| 1115 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1116 | return false; |
| 1117 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
| 1118 | exception->retry = 1; |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1122 | static u32 |
| 1123 | nfs4_map_atomic_open_share(struct nfs_server *server, |
| 1124 | fmode_t fmode, int openflags) |
| 1125 | { |
| 1126 | u32 res = 0; |
| 1127 | |
| 1128 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { |
| 1129 | case FMODE_READ: |
| 1130 | res = NFS4_SHARE_ACCESS_READ; |
| 1131 | break; |
| 1132 | case FMODE_WRITE: |
| 1133 | res = NFS4_SHARE_ACCESS_WRITE; |
| 1134 | break; |
| 1135 | case FMODE_READ|FMODE_WRITE: |
| 1136 | res = NFS4_SHARE_ACCESS_BOTH; |
| 1137 | } |
| 1138 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) |
| 1139 | goto out; |
| 1140 | /* Want no delegation if we're using O_DIRECT */ |
| 1141 | if (openflags & O_DIRECT) |
| 1142 | res |= NFS4_SHARE_WANT_NO_DELEG; |
| 1143 | out: |
| 1144 | return res; |
| 1145 | } |
| 1146 | |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1147 | static enum open_claim_type4 |
| 1148 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 1149 | enum open_claim_type4 claim) |
| 1150 | { |
| 1151 | if (server->caps & NFS_CAP_ATOMIC_OPEN_V1) |
| 1152 | return claim; |
| 1153 | switch (claim) { |
| 1154 | default: |
| 1155 | return claim; |
| 1156 | case NFS4_OPEN_CLAIM_FH: |
| 1157 | return NFS4_OPEN_CLAIM_NULL; |
| 1158 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1159 | return NFS4_OPEN_CLAIM_DELEGATE_CUR; |
| 1160 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1161 | return NFS4_OPEN_CLAIM_DELEGATE_PREV; |
| 1162 | } |
| 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
| 1165 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1166 | { |
| 1167 | p->o_res.f_attr = &p->f_attr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1168 | p->o_res.f_label = p->f_label; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1169 | p->o_res.seqid = p->o_arg.seqid; |
| 1170 | p->c_res.seqid = p->c_arg.seqid; |
| 1171 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 1172 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1173 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1174 | 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] | 1175 | } |
| 1176 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1177 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1178 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1179 | const struct iattr *attrs, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1180 | struct nfs4_label *label, |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1181 | enum open_claim_type4 claim, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1182 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1183 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1184 | struct dentry *parent = dget_parent(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1185 | struct inode *dir = d_inode(parent); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1186 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1187 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1188 | struct nfs4_opendata *p; |
| 1189 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1190 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1191 | if (p == NULL) |
| 1192 | goto err; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1193 | |
| 1194 | p->f_label = nfs4_label_alloc(server, gfp_mask); |
| 1195 | if (IS_ERR(p->f_label)) |
| 1196 | goto err_free_p; |
| 1197 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1198 | p->a_label = nfs4_label_alloc(server, gfp_mask); |
| 1199 | if (IS_ERR(p->a_label)) |
| 1200 | goto err_free_f; |
| 1201 | |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 1202 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 1203 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 1204 | if (IS_ERR(p->o_arg.seqid)) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1205 | goto err_free_label; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1206 | nfs_sb_active(dentry->d_sb); |
| 1207 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1208 | p->dir = parent; |
| 1209 | p->owner = sp; |
| 1210 | atomic_inc(&sp->so_count); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1211 | p->o_arg.open_flags = flags; |
| 1212 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 1213 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, |
| 1214 | fmode, flags); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1215 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1216 | * will return permission denied for all bits until close */ |
| 1217 | if (!(flags & O_EXCL)) { |
| 1218 | /* ask server to check for all possible rights as results |
| 1219 | * are cached */ |
| 1220 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 1221 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 1222 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1223 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1224 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 1225 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1226 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1227 | p->o_arg.server = server; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 1228 | p->o_arg.bitmask = nfs4_bitmask(server, label); |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1229 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1230 | p->o_arg.label = nfs4_label_copy(p->a_label, label); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1231 | p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); |
| 1232 | switch (p->o_arg.claim) { |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1233 | case NFS4_OPEN_CLAIM_NULL: |
| 1234 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1235 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1236 | p->o_arg.fh = NFS_FH(dir); |
| 1237 | break; |
| 1238 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1239 | case NFS4_OPEN_CLAIM_FH: |
| 1240 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1241 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1242 | p->o_arg.fh = NFS_FH(d_inode(dentry)); |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1243 | } |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1244 | if (attrs != NULL && attrs->ia_valid != 0) { |
Trond Myklebust | c281fa9c | 2013-08-20 21:06:49 -0400 | [diff] [blame] | 1245 | __u32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1246 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1247 | p->o_arg.u.attrs = &p->attrs; |
| 1248 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 1249 | |
| 1250 | verf[0] = jiffies; |
| 1251 | verf[1] = current->pid; |
| 1252 | memcpy(p->o_arg.u.verifier.data, verf, |
| 1253 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1254 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1255 | p->c_arg.fh = &p->o_res.fh; |
| 1256 | p->c_arg.stateid = &p->o_res.stateid; |
| 1257 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1258 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1259 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1260 | return p; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1261 | |
| 1262 | err_free_label: |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1263 | nfs4_label_free(p->a_label); |
| 1264 | err_free_f: |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1265 | nfs4_label_free(p->f_label); |
| 1266 | err_free_p: |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | kfree(p); |
| 1268 | err: |
| 1269 | dput(parent); |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1273 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1274 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1275 | struct nfs4_opendata *p = container_of(kref, |
| 1276 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1277 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | |
| 1279 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1280 | nfs4_sequence_free_slot(&p->o_res.seq_res); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1281 | if (p->state != NULL) |
| 1282 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1283 | nfs4_put_state_owner(p->owner); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1284 | |
Kinglong Mee | a49c269 | 2015-07-27 15:31:38 +0800 | [diff] [blame] | 1285 | nfs4_label_free(p->a_label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 1286 | nfs4_label_free(p->f_label); |
| 1287 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1288 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1289 | dput(p->dentry); |
| 1290 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1291 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 1292 | kfree(p->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1293 | kfree(p); |
| 1294 | } |
| 1295 | |
| 1296 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 1297 | { |
| 1298 | if (p != NULL) |
| 1299 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1300 | } |
| 1301 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1302 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 1303 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1304 | int ret; |
| 1305 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1306 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 1307 | return ret; |
| 1308 | } |
| 1309 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1310 | static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, |
| 1311 | fmode_t fmode) |
| 1312 | { |
| 1313 | switch(fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1314 | case FMODE_READ|FMODE_WRITE: |
| 1315 | return state->n_rdwr != 0; |
| 1316 | case FMODE_WRITE: |
| 1317 | return state->n_wronly != 0; |
| 1318 | case FMODE_READ: |
| 1319 | return state->n_rdonly != 0; |
| 1320 | } |
| 1321 | WARN_ON_ONCE(1); |
| 1322 | return false; |
| 1323 | } |
| 1324 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1325 | 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] | 1326 | { |
| 1327 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1328 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1329 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1330 | goto out; |
| 1331 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1332 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1333 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 1334 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1335 | break; |
| 1336 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1337 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 1338 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1339 | break; |
| 1340 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1341 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 1342 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1343 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1344 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1345 | return ret; |
| 1346 | } |
| 1347 | |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1348 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, |
| 1349 | enum open_claim_type4 claim) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1350 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1351 | if (delegation == NULL) |
| 1352 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1353 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1354 | return 0; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1355 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1356 | return 0; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1357 | switch (claim) { |
| 1358 | case NFS4_OPEN_CLAIM_NULL: |
| 1359 | case NFS4_OPEN_CLAIM_FH: |
| 1360 | break; |
| 1361 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1362 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
| 1363 | break; |
| 1364 | default: |
| 1365 | return 0; |
| 1366 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1367 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
| 1370 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1371 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1372 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1373 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1374 | case FMODE_WRITE: |
| 1375 | state->n_wronly++; |
| 1376 | break; |
| 1377 | case FMODE_READ: |
| 1378 | state->n_rdonly++; |
| 1379 | break; |
| 1380 | case FMODE_READ|FMODE_WRITE: |
| 1381 | state->n_rdwr++; |
| 1382 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1386 | 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] | 1387 | { |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1388 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
| 1389 | bool need_recover = false; |
| 1390 | |
| 1391 | if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) |
| 1392 | need_recover = true; |
| 1393 | if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) |
| 1394 | need_recover = true; |
| 1395 | if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) |
| 1396 | need_recover = true; |
| 1397 | if (need_recover) |
| 1398 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 1399 | } |
| 1400 | |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1401 | static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
| 1402 | nfs4_stateid *stateid) |
| 1403 | { |
| 1404 | if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) |
| 1405 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1406 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
| 1407 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1408 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1409 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1410 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1411 | return true; |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1415 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1416 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1417 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1418 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1419 | if (state->n_wronly) |
| 1420 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1421 | if (state->n_rdonly) |
| 1422 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1423 | if (state->n_rdwr) |
| 1424 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1425 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1428 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1429 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1430 | nfs4_stateid *stateid, fmode_t fmode) |
| 1431 | { |
| 1432 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1433 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1434 | case FMODE_WRITE: |
| 1435 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1436 | break; |
| 1437 | case FMODE_READ: |
| 1438 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1439 | break; |
| 1440 | case 0: |
| 1441 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1442 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1443 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1444 | } |
| 1445 | if (stateid == NULL) |
| 1446 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1447 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1448 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1449 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1450 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1451 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1452 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1453 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1454 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1455 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1456 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1457 | } |
| 1458 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1459 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1460 | nfs4_stateid *arg_stateid, |
| 1461 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1462 | { |
| 1463 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1464 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1465 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1466 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1467 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1468 | } |
| 1469 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1470 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
| 1471 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1472 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1473 | case FMODE_READ: |
| 1474 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1475 | break; |
| 1476 | case FMODE_WRITE: |
| 1477 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1478 | break; |
| 1479 | case FMODE_READ|FMODE_WRITE: |
| 1480 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1481 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1482 | if (!nfs_need_update_open_stateid(state, stateid)) |
| 1483 | return; |
| 1484 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1485 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1486 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1489 | 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] | 1490 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1491 | /* |
| 1492 | * Protect the call to nfs4_state_set_mode_locked and |
| 1493 | * serialise the stateid update |
| 1494 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1495 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1496 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1497 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1498 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1499 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1500 | } |
| 1501 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1502 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1503 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1504 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1505 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1508 | 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] | 1509 | { |
| 1510 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1511 | struct nfs_delegation *deleg_cur; |
| 1512 | int ret = 0; |
| 1513 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1514 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1515 | |
| 1516 | rcu_read_lock(); |
| 1517 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1518 | if (deleg_cur == NULL) |
| 1519 | goto no_delegation; |
| 1520 | |
| 1521 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1522 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1523 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1524 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1525 | goto no_delegation_unlock; |
| 1526 | |
| 1527 | if (delegation == NULL) |
| 1528 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1529 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1530 | goto no_delegation_unlock; |
| 1531 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1532 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1533 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1534 | ret = 1; |
| 1535 | no_delegation_unlock: |
| 1536 | spin_unlock(&deleg_cur->lock); |
| 1537 | no_delegation: |
| 1538 | rcu_read_unlock(); |
| 1539 | |
| 1540 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1541 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1542 | ret = 1; |
| 1543 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1544 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1545 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1546 | |
| 1547 | return ret; |
| 1548 | } |
| 1549 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1550 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1551 | const nfs4_stateid *stateid) |
| 1552 | { |
| 1553 | struct nfs4_state *state = lsp->ls_state; |
| 1554 | bool ret = false; |
| 1555 | |
| 1556 | spin_lock(&state->state_lock); |
| 1557 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1558 | goto out_noupdate; |
| 1559 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1560 | goto out_noupdate; |
| 1561 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1562 | ret = true; |
| 1563 | out_noupdate: |
| 1564 | spin_unlock(&state->state_lock); |
| 1565 | return ret; |
| 1566 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1567 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1568 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1569 | { |
| 1570 | struct nfs_delegation *delegation; |
| 1571 | |
| 1572 | rcu_read_lock(); |
| 1573 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1574 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1575 | rcu_read_unlock(); |
| 1576 | return; |
| 1577 | } |
| 1578 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1579 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1580 | } |
| 1581 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1582 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1583 | { |
| 1584 | struct nfs4_state *state = opendata->state; |
| 1585 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1586 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1587 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1588 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1589 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1590 | nfs4_stateid stateid; |
| 1591 | int ret = -EAGAIN; |
| 1592 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1593 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1594 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1595 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1596 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1597 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1598 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1599 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1600 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1601 | rcu_read_lock(); |
| 1602 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1603 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1604 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1605 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1606 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1607 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1608 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1609 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1610 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1611 | if (!opendata->is_recover) { |
| 1612 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1613 | if (ret != 0) |
| 1614 | goto out; |
| 1615 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1616 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1617 | |
| 1618 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1619 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1620 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1621 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1622 | out: |
| 1623 | return ERR_PTR(ret); |
| 1624 | out_return_state: |
| 1625 | atomic_inc(&state->count); |
| 1626 | return state; |
| 1627 | } |
| 1628 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1629 | static void |
| 1630 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1631 | { |
| 1632 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1633 | struct nfs_delegation *delegation; |
| 1634 | int delegation_flags = 0; |
| 1635 | |
| 1636 | rcu_read_lock(); |
| 1637 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1638 | if (delegation) |
| 1639 | delegation_flags = delegation->flags; |
| 1640 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1641 | switch (data->o_arg.claim) { |
| 1642 | default: |
| 1643 | break; |
| 1644 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1645 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1646 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1647 | "returning a delegation for " |
| 1648 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1649 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1650 | return; |
| 1651 | } |
| 1652 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1653 | nfs_inode_set_delegation(state->inode, |
| 1654 | data->owner->so_cred, |
| 1655 | &data->o_res); |
| 1656 | else |
| 1657 | nfs_inode_reclaim_delegation(state->inode, |
| 1658 | data->owner->so_cred, |
| 1659 | &data->o_res); |
| 1660 | } |
| 1661 | |
| 1662 | /* |
| 1663 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1664 | * and update the nfs4_state. |
| 1665 | */ |
| 1666 | static struct nfs4_state * |
| 1667 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1668 | { |
| 1669 | struct inode *inode = data->state->inode; |
| 1670 | struct nfs4_state *state = data->state; |
| 1671 | int ret; |
| 1672 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1673 | if (!data->rpc_done) { |
| 1674 | if (data->rpc_status) { |
| 1675 | ret = data->rpc_status; |
| 1676 | goto err; |
| 1677 | } |
| 1678 | /* cached opens have already been processed */ |
| 1679 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1682 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1683 | if (ret) |
| 1684 | goto err; |
| 1685 | |
| 1686 | if (data->o_res.delegation_type != 0) |
| 1687 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1688 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1689 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1690 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1691 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1692 | |
| 1693 | return state; |
| 1694 | err: |
| 1695 | return ERR_PTR(ret); |
| 1696 | |
| 1697 | } |
| 1698 | |
| 1699 | static struct nfs4_state * |
| 1700 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1701 | { |
| 1702 | struct inode *inode; |
| 1703 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1704 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1705 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1706 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1707 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1708 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1709 | goto out; |
| 1710 | } |
| 1711 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1712 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1713 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1714 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1715 | 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] | 1716 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1717 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1718 | goto err; |
| 1719 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1720 | state = nfs4_get_open_state(inode, data->owner); |
| 1721 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1722 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1723 | if (data->o_res.delegation_type != 0) |
| 1724 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1725 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1726 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1727 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1728 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1729 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1730 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1731 | err_put_inode: |
| 1732 | iput(inode); |
| 1733 | err: |
| 1734 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1735 | } |
| 1736 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1737 | static struct nfs4_state * |
| 1738 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1739 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1740 | struct nfs4_state *ret; |
| 1741 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1742 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1743 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1744 | else |
| 1745 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1746 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1747 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1748 | } |
| 1749 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1750 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1751 | { |
| 1752 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1753 | struct nfs_open_context *ctx; |
| 1754 | |
| 1755 | spin_lock(&state->inode->i_lock); |
| 1756 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1757 | if (ctx->state != state) |
| 1758 | continue; |
| 1759 | get_nfs_open_context(ctx); |
| 1760 | spin_unlock(&state->inode->i_lock); |
| 1761 | return ctx; |
| 1762 | } |
| 1763 | spin_unlock(&state->inode->i_lock); |
| 1764 | return ERR_PTR(-ENOENT); |
| 1765 | } |
| 1766 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1767 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1768 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1769 | { |
| 1770 | struct nfs4_opendata *opendata; |
| 1771 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1772 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1773 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1774 | if (opendata == NULL) |
| 1775 | return ERR_PTR(-ENOMEM); |
| 1776 | opendata->state = state; |
| 1777 | atomic_inc(&state->count); |
| 1778 | return opendata; |
| 1779 | } |
| 1780 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1781 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1782 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1783 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1784 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1785 | int ret; |
| 1786 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1787 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1788 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1789 | opendata->o_arg.open_flags = 0; |
| 1790 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1791 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1792 | NFS_SB(opendata->dentry->d_sb), |
| 1793 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1794 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1795 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1796 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1797 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1798 | if (ret != 0) |
| 1799 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1800 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1801 | if (IS_ERR(newstate)) |
| 1802 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1803 | if (newstate != opendata->state) |
| 1804 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1805 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1806 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1810 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1811 | int ret; |
| 1812 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1813 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1814 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1815 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1816 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1817 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1818 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1819 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1820 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1821 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1822 | if (ret != 0) |
| 1823 | return ret; |
| 1824 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1825 | if (ret != 0) |
| 1826 | return ret; |
| 1827 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1828 | if (ret != 0) |
| 1829 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1830 | /* |
| 1831 | * We may have performed cached opens for all three recoveries. |
| 1832 | * Check if we need to update the current stateid. |
| 1833 | */ |
| 1834 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1835 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1836 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1837 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1838 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1839 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1840 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1841 | return 0; |
| 1842 | } |
| 1843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | /* |
| 1845 | * OPEN_RECLAIM: |
| 1846 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1848 | 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] | 1849 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1850 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1851 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1852 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | int status; |
| 1854 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1855 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1856 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1857 | if (IS_ERR(opendata)) |
| 1858 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1859 | rcu_read_lock(); |
| 1860 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1861 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1862 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1863 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1864 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1865 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1866 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | return status; |
| 1868 | } |
| 1869 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1870 | 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] | 1871 | { |
| 1872 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1873 | struct nfs4_exception exception = { }; |
| 1874 | int err; |
| 1875 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1876 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1877 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1878 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1879 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1880 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1881 | break; |
| 1882 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } while (exception.retry); |
| 1884 | return err; |
| 1885 | } |
| 1886 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1887 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1888 | { |
| 1889 | struct nfs_open_context *ctx; |
| 1890 | int ret; |
| 1891 | |
| 1892 | ctx = nfs4_state_find_open_context(state); |
| 1893 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1894 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1895 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1896 | put_nfs_open_context(ctx); |
| 1897 | return ret; |
| 1898 | } |
| 1899 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1900 | 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] | 1901 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1902 | switch (err) { |
| 1903 | default: |
| 1904 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1905 | "%d.\n", __func__, err); |
| 1906 | case 0: |
| 1907 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1908 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1909 | case -ESTALE: |
| 1910 | break; |
| 1911 | case -NFS4ERR_BADSESSION: |
| 1912 | case -NFS4ERR_BADSLOT: |
| 1913 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1914 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1915 | case -NFS4ERR_DEADSESSION: |
| 1916 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1917 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1918 | return -EAGAIN; |
| 1919 | case -NFS4ERR_STALE_CLIENTID: |
| 1920 | case -NFS4ERR_STALE_STATEID: |
| 1921 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1922 | /* Don't recall a delegation if it was lost */ |
| 1923 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1924 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1925 | case -NFS4ERR_MOVED: |
| 1926 | nfs4_schedule_migration_recovery(server); |
| 1927 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1928 | case -NFS4ERR_LEASE_MOVED: |
| 1929 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1930 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1931 | case -NFS4ERR_DELEG_REVOKED: |
| 1932 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1933 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1934 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1935 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1936 | nfs_inode_find_state_and_recover(state->inode, |
| 1937 | stateid); |
| 1938 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1939 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1940 | case -NFS4ERR_DELAY: |
| 1941 | case -NFS4ERR_GRACE: |
| 1942 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1943 | ssleep(1); |
| 1944 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1945 | case -ENOMEM: |
| 1946 | case -NFS4ERR_DENIED: |
| 1947 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1948 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | return err; |
| 1951 | } |
| 1952 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1953 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1954 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1955 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1956 | { |
| 1957 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1958 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1959 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1960 | |
| 1961 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1962 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1963 | if (IS_ERR(opendata)) |
| 1964 | return PTR_ERR(opendata); |
| 1965 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1966 | write_seqlock(&state->seqlock); |
| 1967 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1968 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1969 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1970 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1971 | case FMODE_READ|FMODE_WRITE: |
| 1972 | case FMODE_WRITE: |
| 1973 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1974 | if (err) |
| 1975 | break; |
| 1976 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1977 | if (err) |
| 1978 | break; |
| 1979 | case FMODE_READ: |
| 1980 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1981 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1982 | nfs4_opendata_put(opendata); |
| 1983 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 1984 | } |
| 1985 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1986 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 1987 | { |
| 1988 | struct nfs4_opendata *data = calldata; |
| 1989 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 1990 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1991 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1992 | } |
| 1993 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1994 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1995 | { |
| 1996 | struct nfs4_opendata *data = calldata; |
| 1997 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 1998 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 1999 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2000 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2001 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2002 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2003 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2004 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2005 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2006 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static void nfs4_open_confirm_release(void *calldata) |
| 2010 | { |
| 2011 | struct nfs4_opendata *data = calldata; |
| 2012 | struct nfs4_state *state = NULL; |
| 2013 | |
| 2014 | /* If this request hasn't been cancelled, do nothing */ |
| 2015 | if (data->cancelled == 0) |
| 2016 | goto out_free; |
| 2017 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2018 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2019 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2020 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2021 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2022 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2023 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2024 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2028 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2029 | .rpc_call_done = nfs4_open_confirm_done, |
| 2030 | .rpc_release = nfs4_open_confirm_release, |
| 2031 | }; |
| 2032 | |
| 2033 | /* |
| 2034 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2035 | */ |
| 2036 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2037 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2038 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2039 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2040 | struct rpc_message msg = { |
| 2041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2042 | .rpc_argp = &data->c_arg, |
| 2043 | .rpc_resp = &data->c_res, |
| 2044 | .rpc_cred = data->owner->so_cred, |
| 2045 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2046 | struct rpc_task_setup task_setup_data = { |
| 2047 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2048 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2049 | .callback_ops = &nfs4_open_confirm_ops, |
| 2050 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2051 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2052 | .flags = RPC_TASK_ASYNC, |
| 2053 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | int status; |
| 2055 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2056 | 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] | 2057 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2058 | data->rpc_done = 0; |
| 2059 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2060 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2061 | if (data->is_recover) |
| 2062 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2063 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2064 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2065 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2066 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2067 | if (status != 0) { |
| 2068 | data->cancelled = 1; |
| 2069 | smp_wmb(); |
| 2070 | } else |
| 2071 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2072 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | return status; |
| 2074 | } |
| 2075 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2076 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2078 | struct nfs4_opendata *data = calldata; |
| 2079 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2080 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2081 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2082 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2083 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2084 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2085 | /* |
| 2086 | * Check if we still need to send an OPEN call, or if we can use |
| 2087 | * a delegation instead. |
| 2088 | */ |
| 2089 | if (data->state != NULL) { |
| 2090 | struct nfs_delegation *delegation; |
| 2091 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2092 | 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] | 2093 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2094 | rcu_read_lock(); |
| 2095 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2096 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2097 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2098 | rcu_read_unlock(); |
| 2099 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2100 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2101 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2102 | switch (claim) { |
| 2103 | default: |
| 2104 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2105 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2106 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2107 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2108 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2109 | case NFS4_OPEN_CLAIM_FH: |
| 2110 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2111 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2112 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2113 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2114 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2115 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2116 | &data->o_res.seq_res, |
| 2117 | task) != 0) |
| 2118 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2119 | |
| 2120 | /* Set the create mode (note dependency on the session type) */ |
| 2121 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2122 | if (data->o_arg.open_flags & O_EXCL) { |
| 2123 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2124 | if (nfs4_has_persistent_session(clp)) |
| 2125 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2126 | else if (clp->cl_mvops->minor_version > 0) |
| 2127 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2128 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2129 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2130 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2131 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2132 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2133 | out_no_action: |
| 2134 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2135 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2136 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2137 | } |
| 2138 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2139 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2140 | { |
| 2141 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2143 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2144 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2145 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2146 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2147 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2148 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2149 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2150 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2151 | case S_IFREG: |
| 2152 | break; |
| 2153 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2154 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2155 | break; |
| 2156 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2157 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2158 | break; |
| 2159 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2161 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2162 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2163 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2164 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2165 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2166 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2167 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2168 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2169 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2170 | static void nfs4_open_release(void *calldata) |
| 2171 | { |
| 2172 | struct nfs4_opendata *data = calldata; |
| 2173 | struct nfs4_state *state = NULL; |
| 2174 | |
| 2175 | /* If this request hasn't been cancelled, do nothing */ |
| 2176 | if (data->cancelled == 0) |
| 2177 | goto out_free; |
| 2178 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2179 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2180 | goto out_free; |
| 2181 | /* In case we need an open_confirm, no cleanup! */ |
| 2182 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2183 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2184 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2185 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2186 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2187 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2188 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2192 | .rpc_call_prepare = nfs4_open_prepare, |
| 2193 | .rpc_call_done = nfs4_open_done, |
| 2194 | .rpc_release = nfs4_open_release, |
| 2195 | }; |
| 2196 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2197 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2198 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2199 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2200 | struct nfs_server *server = NFS_SERVER(dir); |
| 2201 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2202 | struct nfs_openres *o_res = &data->o_res; |
| 2203 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2204 | struct rpc_message msg = { |
| 2205 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2206 | .rpc_argp = o_arg, |
| 2207 | .rpc_resp = o_res, |
| 2208 | .rpc_cred = data->owner->so_cred, |
| 2209 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2210 | struct rpc_task_setup task_setup_data = { |
| 2211 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2212 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2213 | .callback_ops = &nfs4_open_ops, |
| 2214 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2215 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2216 | .flags = RPC_TASK_ASYNC, |
| 2217 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2218 | int status; |
| 2219 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2220 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2221 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2222 | data->rpc_done = 0; |
| 2223 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2224 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2225 | data->is_recover = 0; |
| 2226 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2227 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2228 | data->is_recover = 1; |
| 2229 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2230 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2231 | if (IS_ERR(task)) |
| 2232 | return PTR_ERR(task); |
| 2233 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2234 | if (status != 0) { |
| 2235 | data->cancelled = 1; |
| 2236 | smp_wmb(); |
| 2237 | } else |
| 2238 | status = data->rpc_status; |
| 2239 | rpc_put_task(task); |
| 2240 | |
| 2241 | return status; |
| 2242 | } |
| 2243 | |
| 2244 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2245 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2246 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2247 | struct nfs_openres *o_res = &data->o_res; |
| 2248 | int status; |
| 2249 | |
| 2250 | status = nfs4_run_open_task(data, 1); |
| 2251 | if (status != 0 || !data->rpc_done) |
| 2252 | return status; |
| 2253 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2254 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2255 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2256 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2257 | status = _nfs4_proc_open_confirm(data); |
| 2258 | if (status != 0) |
| 2259 | return status; |
| 2260 | } |
| 2261 | |
| 2262 | return status; |
| 2263 | } |
| 2264 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2265 | /* |
| 2266 | * Additional permission checks in order to distinguish between an |
| 2267 | * open for read, and an open for execute. This works around the |
| 2268 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2269 | * the same. |
| 2270 | * Note that in the non-execute case, we want to turn off permission |
| 2271 | * checking if we just created a new file (POSIX open() semantics). |
| 2272 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2273 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2274 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2275 | struct nfs4_state *state, fmode_t fmode, |
| 2276 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2277 | { |
| 2278 | struct nfs_access_entry cache; |
| 2279 | u32 mask; |
| 2280 | |
| 2281 | /* access call failed or for some reason the server doesn't |
| 2282 | * support any access modes -- defer access call until later */ |
| 2283 | if (opendata->o_res.access_supported == 0) |
| 2284 | return 0; |
| 2285 | |
| 2286 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2287 | /* |
| 2288 | * Use openflags to check for exec, because fmode won't |
| 2289 | * always have FMODE_EXEC set when file open for exec. |
| 2290 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2291 | if (openflags & __FMODE_EXEC) { |
| 2292 | /* ONLY check for exec rights */ |
| 2293 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2294 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2295 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2296 | |
| 2297 | cache.cred = cred; |
| 2298 | cache.jiffies = jiffies; |
| 2299 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2300 | nfs_access_add_cache(state->inode, &cache); |
| 2301 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2302 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2303 | return 0; |
| 2304 | |
| 2305 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2306 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2307 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2310 | /* |
| 2311 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2312 | */ |
| 2313 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2314 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2315 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2316 | struct nfs_server *server = NFS_SERVER(dir); |
| 2317 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2318 | struct nfs_openres *o_res = &data->o_res; |
| 2319 | int status; |
| 2320 | |
| 2321 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2322 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2323 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2324 | if (status != 0) { |
| 2325 | if (status == -NFS4ERR_BADNAME && |
| 2326 | !(o_arg->open_flags & O_CREAT)) |
| 2327 | return -ENOENT; |
| 2328 | return status; |
| 2329 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2330 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2331 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2332 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2333 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2334 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2335 | if (o_arg->open_flags & O_EXCL) |
| 2336 | data->file_created = 1; |
| 2337 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2338 | data->file_created = 1; |
| 2339 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2340 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2341 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2343 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2345 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | } |
| 2347 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2348 | 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] | 2349 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2352 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2353 | { |
| 2354 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2355 | } |
| 2356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | /* |
| 2358 | * OPEN_EXPIRED: |
| 2359 | * reclaim state on the server after a network partition. |
| 2360 | * Assumes caller holds the appropriate lock |
| 2361 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2362 | 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] | 2363 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2364 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2365 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2367 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2368 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2369 | if (IS_ERR(opendata)) |
| 2370 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2371 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2372 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2373 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2374 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2375 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2378 | 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] | 2379 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2380 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2381 | struct nfs4_exception exception = { }; |
| 2382 | int err; |
| 2383 | |
| 2384 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2385 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2386 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2387 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2388 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2389 | switch (err) { |
| 2390 | default: |
| 2391 | goto out; |
| 2392 | case -NFS4ERR_GRACE: |
| 2393 | case -NFS4ERR_DELAY: |
| 2394 | nfs4_handle_exception(server, err, &exception); |
| 2395 | err = 0; |
| 2396 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2397 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2398 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2399 | return err; |
| 2400 | } |
| 2401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2403 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2405 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2407 | ctx = nfs4_state_find_open_context(state); |
| 2408 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2409 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2410 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2411 | put_nfs_open_context(ctx); |
| 2412 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2415 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2416 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2417 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2418 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2419 | write_seqlock(&state->seqlock); |
| 2420 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2421 | write_sequnlock(&state->seqlock); |
| 2422 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2423 | } |
| 2424 | |
| 2425 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2426 | { |
| 2427 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2428 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2432 | { |
| 2433 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2434 | nfs40_clear_delegation_stateid(state); |
| 2435 | return nfs4_open_expired(sp, state); |
| 2436 | } |
| 2437 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2438 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2439 | nfs4_stateid *stateid, |
| 2440 | struct rpc_cred *cred) |
| 2441 | { |
| 2442 | return -NFS4ERR_BAD_STATEID; |
| 2443 | } |
| 2444 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2445 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2446 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2447 | nfs4_stateid *stateid, |
| 2448 | struct rpc_cred *cred) |
| 2449 | { |
| 2450 | int status; |
| 2451 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2452 | switch (stateid->type) { |
| 2453 | default: |
| 2454 | break; |
| 2455 | case NFS4_INVALID_STATEID_TYPE: |
| 2456 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2457 | return -NFS4ERR_BAD_STATEID; |
| 2458 | case NFS4_REVOKED_STATEID_TYPE: |
| 2459 | goto out_free; |
| 2460 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2461 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2462 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2463 | switch (status) { |
| 2464 | case -NFS4ERR_EXPIRED: |
| 2465 | case -NFS4ERR_ADMIN_REVOKED: |
| 2466 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2467 | break; |
| 2468 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2469 | return status; |
| 2470 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2471 | out_free: |
| 2472 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2473 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2474 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2475 | } |
| 2476 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2477 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2478 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2479 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2480 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2481 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2482 | struct rpc_cred *cred; |
| 2483 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2484 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2485 | /* Get the delegation credential for use by test/free_stateid */ |
| 2486 | rcu_read_lock(); |
| 2487 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2488 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2489 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2490 | return; |
| 2491 | } |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2492 | |
| 2493 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2494 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2495 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2496 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2497 | return; |
| 2498 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2499 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2500 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2501 | rcu_read_unlock(); |
| 2502 | return; |
| 2503 | } |
| 2504 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2505 | cred = get_rpccred(delegation->cred); |
| 2506 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2507 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2508 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2509 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2510 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2511 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2512 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2516 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2517 | * |
| 2518 | * @state: NFSv4 state for an inode |
| 2519 | * |
| 2520 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2521 | * Otherwise a negative NFS4ERR value is returned. |
| 2522 | */ |
| 2523 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2524 | { |
| 2525 | int status, ret = NFS_OK; |
| 2526 | struct nfs4_lock_state *lsp; |
| 2527 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2528 | |
| 2529 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2530 | goto out; |
| 2531 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2532 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2533 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2534 | |
| 2535 | status = nfs41_test_and_free_expired_stateid(server, |
| 2536 | &lsp->ls_stateid, |
| 2537 | cred); |
| 2538 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2539 | if (status == -NFS4ERR_EXPIRED || |
| 2540 | status == -NFS4ERR_BAD_STATEID) { |
| 2541 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 2542 | if (!recover_lost_locks) |
| 2543 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2544 | } else if (status != NFS_OK) { |
| 2545 | ret = status; |
| 2546 | break; |
| 2547 | } |
| 2548 | } |
| 2549 | }; |
| 2550 | out: |
| 2551 | return ret; |
| 2552 | } |
| 2553 | |
| 2554 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2555 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2556 | * |
| 2557 | * @state: NFSv4 state for an inode |
| 2558 | * |
| 2559 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2560 | * Otherwise a negative NFS4ERR value is returned. |
| 2561 | */ |
| 2562 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2563 | { |
| 2564 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2565 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2566 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2567 | int status; |
| 2568 | |
| 2569 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2570 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2571 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2572 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2573 | return -NFS4ERR_BAD_STATEID; |
| 2574 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2575 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2576 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2577 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2578 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2579 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2580 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2581 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2582 | } |
| 2583 | return status; |
| 2584 | } |
| 2585 | |
| 2586 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2587 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2588 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2589 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2590 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2591 | status = nfs41_check_expired_locks(state); |
| 2592 | if (status != NFS_OK) |
| 2593 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2594 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2595 | if (status != NFS_OK) |
| 2596 | status = nfs4_open_expired(sp, state); |
| 2597 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2598 | } |
| 2599 | #endif |
| 2600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2602 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2603 | * fields corresponding to attributes that were used to store the verifier. |
| 2604 | * Make sure we clobber those fields in the later setattr call |
| 2605 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2606 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2607 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2608 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2609 | const u32 *attrset = opendata->o_res.attrset; |
| 2610 | |
| 2611 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2612 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2613 | sattr->ia_valid |= ATTR_ATIME; |
| 2614 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2615 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2616 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2617 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2618 | |
| 2619 | /* Except MODE, it seems harmless of setting twice. */ |
| 2620 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2621 | sattr->ia_valid &= ~ATTR_MODE; |
| 2622 | |
| 2623 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2624 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2627 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2628 | fmode_t fmode, |
| 2629 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2630 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2631 | { |
| 2632 | struct nfs4_state_owner *sp = opendata->owner; |
| 2633 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2634 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2635 | struct nfs4_state *state; |
| 2636 | unsigned int seq; |
| 2637 | int ret; |
| 2638 | |
| 2639 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2640 | |
| 2641 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2642 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2643 | goto out; |
| 2644 | |
| 2645 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2646 | ret = PTR_ERR(state); |
| 2647 | if (IS_ERR(state)) |
| 2648 | goto out; |
| 2649 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2650 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2651 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2652 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2653 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2654 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2655 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2656 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2657 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2658 | alias = d_exact_alias(dentry, state->inode); |
| 2659 | if (!alias) |
| 2660 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2661 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2662 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2663 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2664 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2665 | } |
| 2666 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2667 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2668 | } |
| 2669 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2670 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2671 | if (ret != 0) |
| 2672 | goto out; |
| 2673 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2674 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2675 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2676 | nfs_inode_attach_open_context(ctx); |
| 2677 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2678 | nfs4_schedule_stateid_recovery(server, state); |
| 2679 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2680 | out: |
| 2681 | return ret; |
| 2682 | } |
| 2683 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2684 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2685 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2687 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2688 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2689 | int flags, |
| 2690 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2691 | struct nfs4_label *label, |
| 2692 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | { |
| 2694 | struct nfs4_state_owner *sp; |
| 2695 | struct nfs4_state *state = NULL; |
| 2696 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2697 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2698 | struct dentry *dentry = ctx->dentry; |
| 2699 | struct rpc_cred *cred = ctx->cred; |
| 2700 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2701 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2702 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2703 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2704 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | |
| 2706 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2708 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2709 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2711 | goto out_err; |
| 2712 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2713 | status = nfs4_recover_expired_lease(server); |
| 2714 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2715 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2716 | if (d_really_is_positive(dentry)) |
| 2717 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2718 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2719 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2720 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2721 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2722 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2723 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2724 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2726 | if (label) { |
| 2727 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2728 | if (IS_ERR(olabel)) { |
| 2729 | status = PTR_ERR(olabel); |
| 2730 | goto err_opendata_put; |
| 2731 | } |
| 2732 | } |
| 2733 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2734 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2735 | if (!opendata->f_attr.mdsthreshold) { |
| 2736 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2737 | if (!opendata->f_attr.mdsthreshold) |
| 2738 | goto err_free_label; |
| 2739 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2740 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2741 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2742 | if (d_really_is_positive(dentry)) |
| 2743 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2744 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2745 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2746 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2747 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2748 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2749 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2750 | 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] | 2751 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2752 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2753 | /* |
| 2754 | * send create attributes which was not set by open |
| 2755 | * with an extra setattr. |
| 2756 | */ |
| 2757 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2758 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2759 | status = nfs4_do_setattr(state->inode, cred, |
| 2760 | opendata->o_res.f_attr, sattr, |
| 2761 | state, label, olabel); |
| 2762 | if (status == 0) { |
| 2763 | nfs_setattr_update_inode(state->inode, sattr, |
| 2764 | opendata->o_res.f_attr); |
| 2765 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2766 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2767 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2768 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2769 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2770 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2771 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2772 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2773 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2774 | opendata->f_attr.mdsthreshold = NULL; |
| 2775 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2776 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2777 | nfs4_label_free(olabel); |
| 2778 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2779 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2782 | err_free_label: |
| 2783 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2784 | err_opendata_put: |
| 2785 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2786 | err_put_state_owner: |
| 2787 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | return status; |
| 2790 | } |
| 2791 | |
| 2792 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2793 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2794 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2795 | int flags, |
| 2796 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2797 | struct nfs4_label *label, |
| 2798 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2800 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | struct nfs4_exception exception = { }; |
| 2802 | struct nfs4_state *res; |
| 2803 | int status; |
| 2804 | |
| 2805 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2806 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2807 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2808 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | if (status == 0) |
| 2810 | break; |
| 2811 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2812 | * book-keeping w.r.t. state-changing operations |
| 2813 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2814 | * It is actually a sign of a bug on the client or on the server. |
| 2815 | * |
| 2816 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2817 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | * have unhashed the old state_owner for us, and that we can |
| 2819 | * therefore safely retry using a new one. We should still warn |
| 2820 | * the user though... |
| 2821 | */ |
| 2822 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2823 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2824 | " returned a bad sequence-id error!\n", |
| 2825 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | exception.retry = 1; |
| 2827 | continue; |
| 2828 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2829 | /* |
| 2830 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2831 | * state before it received the OPEN_CONFIRM. |
| 2832 | * Recover by retrying the request as per the discussion |
| 2833 | * on Page 181 of RFC3530. |
| 2834 | */ |
| 2835 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2836 | exception.retry = 1; |
| 2837 | continue; |
| 2838 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2839 | if (status == -EAGAIN) { |
| 2840 | /* We must have found a delegation */ |
| 2841 | exception.retry = 1; |
| 2842 | continue; |
| 2843 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2844 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2845 | continue; |
| 2846 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | status, &exception)); |
| 2848 | } while (exception.retry); |
| 2849 | return res; |
| 2850 | } |
| 2851 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2852 | static int _nfs4_do_setattr(struct inode *inode, |
| 2853 | struct nfs_setattrargs *arg, |
| 2854 | struct nfs_setattrres *res, |
| 2855 | struct rpc_cred *cred, |
| 2856 | struct nfs4_state *state) |
| 2857 | { |
| 2858 | struct nfs_server *server = NFS_SERVER(inode); |
| 2859 | struct rpc_message msg = { |
| 2860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2861 | .rpc_argp = arg, |
| 2862 | .rpc_resp = res, |
| 2863 | .rpc_cred = cred, |
| 2864 | }; |
| 2865 | struct rpc_cred *delegation_cred = NULL; |
| 2866 | unsigned long timestamp = jiffies; |
| 2867 | fmode_t fmode; |
| 2868 | bool truncate; |
| 2869 | int status; |
| 2870 | |
| 2871 | nfs_fattr_init(res->fattr); |
| 2872 | |
| 2873 | /* Servers should only apply open mode checks for file size changes */ |
| 2874 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2875 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2876 | |
| 2877 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2878 | /* Use that stateid */ |
| 2879 | } else if (truncate && state != NULL) { |
| 2880 | struct nfs_lockowner lockowner = { |
| 2881 | .l_owner = current->files, |
| 2882 | .l_pid = current->tgid, |
| 2883 | }; |
| 2884 | if (!nfs4_valid_open_stateid(state)) |
| 2885 | return -EBADF; |
| 2886 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2887 | &arg->stateid, &delegation_cred) == -EIO) |
| 2888 | return -EBADF; |
| 2889 | } else |
| 2890 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2891 | if (delegation_cred) |
| 2892 | msg.rpc_cred = delegation_cred; |
| 2893 | |
| 2894 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2895 | |
| 2896 | put_rpccred(delegation_cred); |
| 2897 | if (status == 0 && state != NULL) |
| 2898 | renew_lease(server, timestamp); |
| 2899 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2900 | return status; |
| 2901 | } |
| 2902 | |
| 2903 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2904 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2905 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2906 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2908 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2910 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | .iap = sattr, |
| 2912 | .server = server, |
| 2913 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2914 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | }; |
| 2916 | struct nfs_setattrres res = { |
| 2917 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2918 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | .server = server, |
| 2920 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2921 | struct nfs4_exception exception = { |
| 2922 | .state = state, |
| 2923 | .inode = inode, |
| 2924 | .stateid = &arg.stateid, |
| 2925 | }; |
| 2926 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2928 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2929 | if (ilabel) |
| 2930 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2933 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2934 | switch (err) { |
| 2935 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2936 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2937 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2938 | "applying open mode checks to " |
| 2939 | "a SETATTR that is not " |
| 2940 | "changing file size.\n", |
| 2941 | server->nfs_client->cl_hostname); |
| 2942 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2943 | if (state && !(state->state & FMODE_WRITE)) { |
| 2944 | err = -EBADF; |
| 2945 | if (sattr->ia_valid & ATTR_OPEN) |
| 2946 | err = -EACCES; |
| 2947 | goto out; |
| 2948 | } |
| 2949 | } |
| 2950 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2952 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | return err; |
| 2954 | } |
| 2955 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2956 | static bool |
| 2957 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2958 | { |
| 2959 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2960 | return false; |
| 2961 | |
| 2962 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2963 | } |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | struct nfs4_closedata { |
| 2966 | struct inode *inode; |
| 2967 | struct nfs4_state *state; |
| 2968 | struct nfs_closeargs arg; |
| 2969 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2970 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2971 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2972 | bool roc; |
| 2973 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | }; |
| 2975 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2976 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2977 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2978 | struct nfs4_closedata *calldata = data; |
| 2979 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2980 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2981 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2982 | if (calldata->roc) |
| 2983 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2984 | nfs4_put_open_state(calldata->state); |
| 2985 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2986 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 2987 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2988 | kfree(calldata); |
| 2989 | } |
| 2990 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2991 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2993 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 2996 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2998 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2999 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3000 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3001 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | /* hmm. we are done with the inode, and in the process of freeing |
| 3003 | * the state_owner. we keep this around to process errors |
| 3004 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | switch (task->tk_status) { |
| 3006 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3007 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3008 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3009 | pnfs_roc_set_barrier(state->inode, |
| 3010 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3011 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3012 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3013 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3015 | case -NFS4ERR_EXPIRED: |
| 3016 | nfs4_free_revoked_stateid(server, |
| 3017 | &calldata->arg.stateid, |
| 3018 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3019 | case -NFS4ERR_OLD_STATEID: |
| 3020 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3021 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3022 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3023 | rpc_restart_call_prepare(task); |
| 3024 | goto out_release; |
| 3025 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3026 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3027 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3029 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3030 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3031 | goto out_release; |
| 3032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3034 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3035 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3036 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3037 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3038 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3039 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3042 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3044 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3045 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3046 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3047 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3048 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3049 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3050 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3051 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3052 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3053 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3054 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3055 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3056 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3057 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3058 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3059 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3060 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3061 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3062 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3063 | if (state->n_rdonly == 0) |
| 3064 | call_close |= is_rdonly; |
| 3065 | else if (is_rdonly) |
| 3066 | calldata->arg.fmode |= FMODE_READ; |
| 3067 | if (state->n_wronly == 0) |
| 3068 | call_close |= is_wronly; |
| 3069 | else if (is_wronly) |
| 3070 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3071 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3072 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3073 | } else if (is_rdwr) |
| 3074 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3075 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3076 | if (!nfs4_valid_open_stateid(state)) |
| 3077 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3078 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3079 | |
| 3080 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3081 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3082 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3083 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3084 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3085 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 3086 | nfs_release_seqid(calldata->arg.seqid); |
| 3087 | goto out_wait; |
| 3088 | } |
| 3089 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3090 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3091 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3092 | if (calldata->roc) |
| 3093 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 3094 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3095 | calldata->arg.share_access = |
| 3096 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3097 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3098 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3099 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3100 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3101 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3102 | &calldata->arg.seq_args, |
| 3103 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3104 | task) != 0) |
| 3105 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3106 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3107 | return; |
| 3108 | out_no_action: |
| 3109 | task->tk_action = NULL; |
| 3110 | out_wait: |
| 3111 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | } |
| 3113 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3114 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3115 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3116 | .rpc_call_done = nfs4_close_done, |
| 3117 | .rpc_release = nfs4_free_closedata, |
| 3118 | }; |
| 3119 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3120 | static bool nfs4_roc(struct inode *inode) |
| 3121 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3122 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3123 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3124 | return pnfs_roc(inode); |
| 3125 | } |
| 3126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | /* |
| 3128 | * It is possible for data to be read/written from a mem-mapped file |
| 3129 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3130 | * This means that we can't safely call nfsv4 close on a file until |
| 3131 | * the inode is cleared. This in turn means that we are not good |
| 3132 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3133 | * share state even when we are done with one of the three share |
| 3134 | * stateid's in the inode. |
| 3135 | * |
| 3136 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3137 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3138 | 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] | 3139 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3140 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3141 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3143 | struct nfs4_state_owner *sp = state->owner; |
| 3144 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3145 | struct rpc_message msg = { |
| 3146 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3147 | .rpc_cred = state->owner->so_cred, |
| 3148 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3149 | struct rpc_task_setup task_setup_data = { |
| 3150 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3151 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3152 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3153 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3154 | .flags = RPC_TASK_ASYNC, |
| 3155 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3156 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3158 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3159 | &task_setup_data.rpc_client, &msg); |
| 3160 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3161 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3163 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3164 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3165 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3167 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3169 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3170 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3171 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3172 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3173 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3174 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3175 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3176 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3177 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3178 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3179 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3181 | msg.rpc_argp = &calldata->arg; |
| 3182 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3183 | task_setup_data.callback_data = calldata; |
| 3184 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3185 | if (IS_ERR(task)) |
| 3186 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3187 | status = 0; |
| 3188 | if (wait) |
| 3189 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3190 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3191 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3192 | out_free_calldata: |
| 3193 | kfree(calldata); |
| 3194 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3195 | nfs4_put_open_state(state); |
| 3196 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3197 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3200 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3201 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3202 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3205 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3206 | |
| 3207 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3209 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3210 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3211 | |
| 3212 | nfs4_label_release_security(label); |
| 3213 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3214 | if (IS_ERR(state)) |
| 3215 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3216 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3219 | 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] | 3220 | { |
| 3221 | if (ctx->state == NULL) |
| 3222 | return; |
| 3223 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3224 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3225 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3226 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3229 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3230 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3231 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3234 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3235 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3236 | struct nfs4_server_caps_arg args = { |
| 3237 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3238 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3239 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | struct nfs4_server_caps_res res = {}; |
| 3241 | struct rpc_message msg = { |
| 3242 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3243 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | .rpc_resp = &res, |
| 3245 | }; |
| 3246 | int status; |
| 3247 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3248 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3249 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3250 | FATTR4_WORD0_LINK_SUPPORT | |
| 3251 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3252 | FATTR4_WORD0_ACLSUPPORT; |
| 3253 | if (minorversion) |
| 3254 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3255 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3256 | 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] | 3257 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3258 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3259 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3260 | case 0: |
| 3261 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3262 | res.attr_bitmask[2] = 0; |
| 3263 | break; |
| 3264 | case 1: |
| 3265 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3266 | break; |
| 3267 | case 2: |
| 3268 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3271 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3272 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3273 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3274 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3275 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3276 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3277 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3278 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | server->caps |= NFS_CAP_ACLS; |
| 3280 | if (res.has_links != 0) |
| 3281 | server->caps |= NFS_CAP_HARDLINKS; |
| 3282 | if (res.has_symlinks != 0) |
| 3283 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3284 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3285 | server->caps |= NFS_CAP_FILEID; |
| 3286 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3287 | server->caps |= NFS_CAP_MODE; |
| 3288 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3289 | server->caps |= NFS_CAP_NLINK; |
| 3290 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3291 | server->caps |= NFS_CAP_OWNER; |
| 3292 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3293 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3294 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3295 | server->caps |= NFS_CAP_ATIME; |
| 3296 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3297 | server->caps |= NFS_CAP_CTIME; |
| 3298 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3299 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3300 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3301 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3302 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3303 | #endif |
| 3304 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3305 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3306 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3307 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3308 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3309 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3310 | 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] | 3311 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3312 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3313 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3315 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | return status; |
| 3319 | } |
| 3320 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3321 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | { |
| 3323 | struct nfs4_exception exception = { }; |
| 3324 | int err; |
| 3325 | do { |
| 3326 | err = nfs4_handle_exception(server, |
| 3327 | _nfs4_server_capabilities(server, fhandle), |
| 3328 | &exception); |
| 3329 | } while (exception.retry); |
| 3330 | return err; |
| 3331 | } |
| 3332 | |
| 3333 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3334 | struct nfs_fsinfo *info) |
| 3335 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3336 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3338 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | }; |
| 3340 | struct nfs4_lookup_res res = { |
| 3341 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3342 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | .fh = fhandle, |
| 3344 | }; |
| 3345 | struct rpc_message msg = { |
| 3346 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3347 | .rpc_argp = &args, |
| 3348 | .rpc_resp = &res, |
| 3349 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3350 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3351 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3352 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3353 | /* |
| 3354 | * Process the label in the upcoming getfattr |
| 3355 | */ |
| 3356 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3357 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3358 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3359 | 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] | 3360 | } |
| 3361 | |
| 3362 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3363 | struct nfs_fsinfo *info) |
| 3364 | { |
| 3365 | struct nfs4_exception exception = { }; |
| 3366 | int err; |
| 3367 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3368 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3369 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3370 | switch (err) { |
| 3371 | case 0: |
| 3372 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3373 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3374 | default: |
| 3375 | err = nfs4_handle_exception(server, err, &exception); |
| 3376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3378 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | return err; |
| 3380 | } |
| 3381 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3382 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3383 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3384 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3385 | struct rpc_auth_create_args auth_args = { |
| 3386 | .pseudoflavor = flavor, |
| 3387 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3388 | struct rpc_auth *auth; |
| 3389 | int ret; |
| 3390 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3391 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3392 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3393 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3394 | goto out; |
| 3395 | } |
| 3396 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3397 | out: |
| 3398 | return ret; |
| 3399 | } |
| 3400 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3401 | /* |
| 3402 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3403 | * |
| 3404 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3405 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3406 | * |
| 3407 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3408 | * negative errno value. |
| 3409 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3410 | 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] | 3411 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3413 | /* Per 3530bis 15.33.5 */ |
| 3414 | static const rpc_authflavor_t flav_array[] = { |
| 3415 | RPC_AUTH_GSS_KRB5P, |
| 3416 | RPC_AUTH_GSS_KRB5I, |
| 3417 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3418 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3419 | RPC_AUTH_NULL, |
| 3420 | }; |
| 3421 | int status = -EPERM; |
| 3422 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3424 | if (server->auth_info.flavor_len > 0) { |
| 3425 | /* try each flavor specified by user */ |
| 3426 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3427 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3428 | server->auth_info.flavors[i]); |
| 3429 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3430 | continue; |
| 3431 | break; |
| 3432 | } |
| 3433 | } else { |
| 3434 | /* no flavors specified by user, try default list */ |
| 3435 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3436 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3437 | flav_array[i]); |
| 3438 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3439 | continue; |
| 3440 | break; |
| 3441 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3442 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3443 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3444 | /* |
| 3445 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3446 | * to access the mount. It could also mean that we tried to mount |
| 3447 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3448 | * existing mount programs don't handle -EACCES very well so it should |
| 3449 | * be mapped to -EPERM instead. |
| 3450 | */ |
| 3451 | if (status == -EACCES) |
| 3452 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3453 | return status; |
| 3454 | } |
| 3455 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3456 | /** |
| 3457 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3458 | * @server: initialized nfs_server handle |
| 3459 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3460 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3461 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3462 | * |
| 3463 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3464 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3465 | 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] | 3466 | struct nfs_fsinfo *info, |
| 3467 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3468 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3469 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3470 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3471 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3472 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3473 | |
| 3474 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3475 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3476 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | if (status == 0) |
| 3479 | status = nfs4_server_capabilities(server, fhandle); |
| 3480 | if (status == 0) |
| 3481 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3482 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3483 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3486 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3487 | struct nfs_fsinfo *info) |
| 3488 | { |
| 3489 | int error; |
| 3490 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3491 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3492 | |
| 3493 | error = nfs4_server_capabilities(server, mntfh); |
| 3494 | if (error < 0) { |
| 3495 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3496 | return error; |
| 3497 | } |
| 3498 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3499 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3500 | if (IS_ERR(label)) |
| 3501 | return PTR_ERR(label); |
| 3502 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3503 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3504 | if (error < 0) { |
| 3505 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3506 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3510 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3511 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3512 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3513 | err_free_label: |
| 3514 | nfs4_label_free(label); |
| 3515 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3516 | return error; |
| 3517 | } |
| 3518 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3519 | /* |
| 3520 | * Get locations and (maybe) other attributes of a referral. |
| 3521 | * Note that we'll actually follow the referral later when |
| 3522 | * we detect fsid mismatch in inode revalidation |
| 3523 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3524 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3525 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3526 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3527 | { |
| 3528 | int status = -ENOMEM; |
| 3529 | struct page *page = NULL; |
| 3530 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3531 | |
| 3532 | page = alloc_page(GFP_KERNEL); |
| 3533 | if (page == NULL) |
| 3534 | goto out; |
| 3535 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3536 | if (locations == NULL) |
| 3537 | goto out; |
| 3538 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3539 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3540 | if (status != 0) |
| 3541 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3542 | |
| 3543 | /* |
| 3544 | * If the fsid didn't change, this is a migration event, not a |
| 3545 | * referral. Cause us to drop into the exception handler, which |
| 3546 | * will kick off migration recovery. |
| 3547 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3548 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3549 | dprintk("%s: server did not return a different fsid for" |
| 3550 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3551 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3552 | goto out; |
| 3553 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3554 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3555 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3556 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3557 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3558 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3559 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3560 | out: |
| 3561 | if (page) |
| 3562 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3563 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3564 | return status; |
| 3565 | } |
| 3566 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3567 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3568 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | { |
| 3570 | struct nfs4_getattr_arg args = { |
| 3571 | .fh = fhandle, |
| 3572 | .bitmask = server->attr_bitmask, |
| 3573 | }; |
| 3574 | struct nfs4_getattr_res res = { |
| 3575 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3576 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | .server = server, |
| 3578 | }; |
| 3579 | struct rpc_message msg = { |
| 3580 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3581 | .rpc_argp = &args, |
| 3582 | .rpc_resp = &res, |
| 3583 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3584 | |
| 3585 | args.bitmask = nfs4_bitmask(server, label); |
| 3586 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3587 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3588 | 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] | 3589 | } |
| 3590 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3591 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3592 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | { |
| 3594 | struct nfs4_exception exception = { }; |
| 3595 | int err; |
| 3596 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3597 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3598 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3599 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | &exception); |
| 3601 | } while (exception.retry); |
| 3602 | return err; |
| 3603 | } |
| 3604 | |
| 3605 | /* |
| 3606 | * The file is not closed if it is opened due to the a request to change |
| 3607 | * the size of the file. The open call will not be needed once the |
| 3608 | * VFS layer lookup-intents are implemented. |
| 3609 | * |
| 3610 | * Close is called when the inode is destroyed. |
| 3611 | * If we haven't opened the file for O_WRONLY, we |
| 3612 | * need to in the size_change case to obtain a stateid. |
| 3613 | * |
| 3614 | * Got race? |
| 3615 | * Because OPEN is always done by name in nfsv4, it is |
| 3616 | * possible that we opened a different file by the same |
| 3617 | * name. We can recognize this race condition, but we |
| 3618 | * can't do anything about it besides returning an error. |
| 3619 | * |
| 3620 | * This will be fixed with VFS changes (lookup-intent). |
| 3621 | */ |
| 3622 | static int |
| 3623 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3624 | struct iattr *sattr) |
| 3625 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3626 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3627 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3628 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3629 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | int status; |
| 3631 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3632 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3633 | sattr->ia_valid & ATTR_SIZE && |
| 3634 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3635 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3636 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3637 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3639 | /* Deal with open(O_TRUNC) */ |
| 3640 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3641 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3642 | |
| 3643 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3644 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3645 | return 0; |
| 3646 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3647 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3648 | if (sattr->ia_valid & ATTR_FILE) { |
| 3649 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3650 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3651 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3652 | if (ctx) { |
| 3653 | cred = ctx->cred; |
| 3654 | state = ctx->state; |
| 3655 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3656 | } |
| 3657 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3658 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3659 | if (IS_ERR(label)) |
| 3660 | return PTR_ERR(label); |
| 3661 | |
| 3662 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3663 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3664 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3665 | nfs_setsecurity(inode, fattr, label); |
| 3666 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3667 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | return status; |
| 3669 | } |
| 3670 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3671 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3672 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3673 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3674 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3675 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3676 | int status; |
| 3677 | struct nfs4_lookup_arg args = { |
| 3678 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3679 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3680 | .name = name, |
| 3681 | }; |
| 3682 | struct nfs4_lookup_res res = { |
| 3683 | .server = server, |
| 3684 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3685 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3686 | .fh = fhandle, |
| 3687 | }; |
| 3688 | struct rpc_message msg = { |
| 3689 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3690 | .rpc_argp = &args, |
| 3691 | .rpc_resp = &res, |
| 3692 | }; |
| 3693 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3694 | args.bitmask = nfs4_bitmask(server, label); |
| 3695 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3696 | nfs_fattr_init(fattr); |
| 3697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3699 | 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] | 3700 | dprintk("NFS reply lookup: %d\n", status); |
| 3701 | return status; |
| 3702 | } |
| 3703 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3704 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3705 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3706 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3707 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3708 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3709 | fattr->nlink = 2; |
| 3710 | } |
| 3711 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3712 | 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] | 3713 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3714 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3715 | { |
| 3716 | struct nfs4_exception exception = { }; |
| 3717 | struct rpc_clnt *client = *clnt; |
| 3718 | int err; |
| 3719 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3720 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3721 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3722 | switch (err) { |
| 3723 | case -NFS4ERR_BADNAME: |
| 3724 | err = -ENOENT; |
| 3725 | goto out; |
| 3726 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3727 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3728 | if (err == -NFS4ERR_MOVED) |
| 3729 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3730 | goto out; |
| 3731 | case -NFS4ERR_WRONGSEC: |
| 3732 | err = -EPERM; |
| 3733 | if (client != *clnt) |
| 3734 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3735 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3736 | if (IS_ERR(client)) |
| 3737 | return PTR_ERR(client); |
| 3738 | |
| 3739 | exception.retry = 1; |
| 3740 | break; |
| 3741 | default: |
| 3742 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3743 | } |
| 3744 | } while (exception.retry); |
| 3745 | |
| 3746 | out: |
| 3747 | if (err == 0) |
| 3748 | *clnt = client; |
| 3749 | else if (client != *clnt) |
| 3750 | rpc_shutdown_client(client); |
| 3751 | |
| 3752 | return err; |
| 3753 | } |
| 3754 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3755 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3756 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3757 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3759 | int status; |
| 3760 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3761 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3762 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3763 | if (client != NFS_CLIENT(dir)) { |
| 3764 | rpc_shutdown_client(client); |
| 3765 | nfs_fixup_secinfo_attributes(fattr); |
| 3766 | } |
| 3767 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3770 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3771 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3772 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3773 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3774 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3775 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3776 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3777 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3778 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3779 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3780 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3781 | } |
| 3782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3784 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3785 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | struct nfs4_accessargs args = { |
| 3787 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3788 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3790 | struct nfs4_accessres res = { |
| 3791 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3792 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | struct rpc_message msg = { |
| 3794 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3795 | .rpc_argp = &args, |
| 3796 | .rpc_resp = &res, |
| 3797 | .rpc_cred = entry->cred, |
| 3798 | }; |
| 3799 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3800 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
| 3802 | /* |
| 3803 | * Determine which access bits we want to ask for... |
| 3804 | */ |
| 3805 | if (mode & MAY_READ) |
| 3806 | args.access |= NFS4_ACCESS_READ; |
| 3807 | if (S_ISDIR(inode->i_mode)) { |
| 3808 | if (mode & MAY_WRITE) |
| 3809 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3810 | if (mode & MAY_EXEC) |
| 3811 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3812 | } else { |
| 3813 | if (mode & MAY_WRITE) |
| 3814 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3815 | if (mode & MAY_EXEC) |
| 3816 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3817 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3818 | |
| 3819 | res.fattr = nfs_alloc_fattr(); |
| 3820 | if (res.fattr == NULL) |
| 3821 | return -ENOMEM; |
| 3822 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3823 | 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] | 3824 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3825 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3826 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3828 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | return status; |
| 3830 | } |
| 3831 | |
| 3832 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3833 | { |
| 3834 | struct nfs4_exception exception = { }; |
| 3835 | int err; |
| 3836 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3837 | err = _nfs4_proc_access(inode, entry); |
| 3838 | trace_nfs4_access(inode, err); |
| 3839 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | &exception); |
| 3841 | } while (exception.retry); |
| 3842 | return err; |
| 3843 | } |
| 3844 | |
| 3845 | /* |
| 3846 | * TODO: For the time being, we don't try to get any attributes |
| 3847 | * along with any of the zero-copy operations READ, READDIR, |
| 3848 | * READLINK, WRITE. |
| 3849 | * |
| 3850 | * In the case of the first three, we want to put the GETATTR |
| 3851 | * after the read-type operation -- this is because it is hard |
| 3852 | * to predict the length of a GETATTR response in v4, and thus |
| 3853 | * align the READ data correctly. This means that the GETATTR |
| 3854 | * may end up partially falling into the page cache, and we should |
| 3855 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3856 | * To do this efficiently, we need to know the total length |
| 3857 | * of data received, which doesn't seem to be available outside |
| 3858 | * of the RPC layer. |
| 3859 | * |
| 3860 | * In the case of WRITE, we also want to put the GETATTR after |
| 3861 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3862 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | * |
| 3864 | * Both of these changes to the XDR layer would in fact be quite |
| 3865 | * minor, but I decided to leave them for a subsequent patch. |
| 3866 | */ |
| 3867 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3868 | unsigned int pgbase, unsigned int pglen) |
| 3869 | { |
| 3870 | struct nfs4_readlink args = { |
| 3871 | .fh = NFS_FH(inode), |
| 3872 | .pgbase = pgbase, |
| 3873 | .pglen = pglen, |
| 3874 | .pages = &page, |
| 3875 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3876 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | struct rpc_message msg = { |
| 3878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3879 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3880 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | }; |
| 3882 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3883 | 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] | 3884 | } |
| 3885 | |
| 3886 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3887 | unsigned int pgbase, unsigned int pglen) |
| 3888 | { |
| 3889 | struct nfs4_exception exception = { }; |
| 3890 | int err; |
| 3891 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3892 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3893 | trace_nfs4_readlink(inode, err); |
| 3894 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | &exception); |
| 3896 | } while (exception.retry); |
| 3897 | return err; |
| 3898 | } |
| 3899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3901 | * 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] | 3902 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | static int |
| 3904 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3905 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3907 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3908 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | int status = 0; |
| 3911 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3912 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3913 | if (IS_ERR(ctx)) |
| 3914 | return PTR_ERR(ctx); |
| 3915 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3916 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3917 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3918 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3919 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | if (IS_ERR(state)) { |
| 3921 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3922 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3925 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3926 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | return status; |
| 3928 | } |
| 3929 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3930 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3932 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3933 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3935 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3937 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3938 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3939 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3941 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3942 | .rpc_argp = &args, |
| 3943 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3945 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3946 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3947 | 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] | 3948 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3949 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | return status; |
| 3951 | } |
| 3952 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3953 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | { |
| 3955 | struct nfs4_exception exception = { }; |
| 3956 | int err; |
| 3957 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3958 | err = _nfs4_proc_remove(dir, name); |
| 3959 | trace_nfs4_remove(dir, name, err); |
| 3960 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | &exception); |
| 3962 | } while (exception.retry); |
| 3963 | return err; |
| 3964 | } |
| 3965 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3966 | 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] | 3967 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3968 | struct nfs_server *server = NFS_SERVER(dir); |
| 3969 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3970 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3972 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3974 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3975 | |
| 3976 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3979 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3980 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3981 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3982 | &data->args.seq_args, |
| 3983 | &data->res.seq_res, |
| 3984 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3987 | 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] | 3988 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3989 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 3990 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3991 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3992 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3993 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3994 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 3995 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3996 | return 0; |
| 3997 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3998 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4001 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4002 | { |
| 4003 | struct nfs_server *server = NFS_SERVER(dir); |
| 4004 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4005 | struct nfs_renameres *res = msg->rpc_resp; |
| 4006 | |
| 4007 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4008 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4009 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4010 | } |
| 4011 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4012 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4013 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4014 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4015 | &data->args.seq_args, |
| 4016 | &data->res.seq_res, |
| 4017 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4021 | struct inode *new_dir) |
| 4022 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4023 | struct nfs_renamedata *data = task->tk_calldata; |
| 4024 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4025 | |
| 4026 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4027 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4028 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4029 | return 0; |
| 4030 | |
| 4031 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4032 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4033 | return 1; |
| 4034 | } |
| 4035 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4036 | 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] | 4037 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4038 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | struct nfs4_link_arg arg = { |
| 4040 | .fh = NFS_FH(inode), |
| 4041 | .dir_fh = NFS_FH(dir), |
| 4042 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4043 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4045 | struct nfs4_link_res res = { |
| 4046 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4047 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4048 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | struct rpc_message msg = { |
| 4050 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4051 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4052 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4054 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4056 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4057 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4058 | goto out; |
| 4059 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4060 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4061 | if (IS_ERR(res.label)) { |
| 4062 | status = PTR_ERR(res.label); |
| 4063 | goto out; |
| 4064 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4065 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4066 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4067 | 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] | 4068 | if (!status) { |
| 4069 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4070 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4071 | if (!status) |
| 4072 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4073 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4074 | |
| 4075 | |
| 4076 | nfs4_label_free(res.label); |
| 4077 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4078 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4079 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | return status; |
| 4081 | } |
| 4082 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4083 | 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] | 4084 | { |
| 4085 | struct nfs4_exception exception = { }; |
| 4086 | int err; |
| 4087 | do { |
| 4088 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4089 | _nfs4_proc_link(inode, dir, name), |
| 4090 | &exception); |
| 4091 | } while (exception.retry); |
| 4092 | return err; |
| 4093 | } |
| 4094 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4095 | struct nfs4_createdata { |
| 4096 | struct rpc_message msg; |
| 4097 | struct nfs4_create_arg arg; |
| 4098 | struct nfs4_create_res res; |
| 4099 | struct nfs_fh fh; |
| 4100 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4101 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4102 | }; |
| 4103 | |
| 4104 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4105 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4106 | { |
| 4107 | struct nfs4_createdata *data; |
| 4108 | |
| 4109 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4110 | if (data != NULL) { |
| 4111 | struct nfs_server *server = NFS_SERVER(dir); |
| 4112 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4113 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4114 | if (IS_ERR(data->label)) |
| 4115 | goto out_free; |
| 4116 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4117 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4118 | data->msg.rpc_argp = &data->arg; |
| 4119 | data->msg.rpc_resp = &data->res; |
| 4120 | data->arg.dir_fh = NFS_FH(dir); |
| 4121 | data->arg.server = server; |
| 4122 | data->arg.name = name; |
| 4123 | data->arg.attrs = sattr; |
| 4124 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4125 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4126 | data->res.server = server; |
| 4127 | data->res.fh = &data->fh; |
| 4128 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4129 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4130 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4131 | } |
| 4132 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4133 | out_free: |
| 4134 | kfree(data); |
| 4135 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4139 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4140 | 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] | 4141 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4142 | if (status == 0) { |
| 4143 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4144 | 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] | 4145 | } |
| 4146 | return status; |
| 4147 | } |
| 4148 | |
| 4149 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4150 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4151 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4152 | kfree(data); |
| 4153 | } |
| 4154 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4155 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4156 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4157 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4159 | struct nfs4_createdata *data; |
| 4160 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4162 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4163 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4164 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4165 | status = -ENOMEM; |
| 4166 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4167 | if (data == NULL) |
| 4168 | goto out; |
| 4169 | |
| 4170 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4171 | data->arg.u.symlink.pages = &page; |
| 4172 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4173 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4175 | status = nfs4_do_create(dir, dentry, data); |
| 4176 | |
| 4177 | nfs4_free_createdata(data); |
| 4178 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | return status; |
| 4180 | } |
| 4181 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4182 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4183 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | { |
| 4185 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4186 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4188 | |
| 4189 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4192 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4193 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4194 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | &exception); |
| 4196 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4197 | |
| 4198 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | return err; |
| 4200 | } |
| 4201 | |
| 4202 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4203 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4205 | struct nfs4_createdata *data; |
| 4206 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4208 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4209 | if (data == NULL) |
| 4210 | goto out; |
| 4211 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4212 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4213 | status = nfs4_do_create(dir, dentry, data); |
| 4214 | |
| 4215 | nfs4_free_createdata(data); |
| 4216 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | return status; |
| 4218 | } |
| 4219 | |
| 4220 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4221 | struct iattr *sattr) |
| 4222 | { |
| 4223 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4224 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4226 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4227 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4228 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4229 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4231 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4232 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4233 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | &exception); |
| 4235 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4236 | nfs4_label_release_security(label); |
| 4237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | return err; |
| 4239 | } |
| 4240 | |
| 4241 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4242 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4244 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | struct nfs4_readdir_arg args = { |
| 4246 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4247 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | .pgbase = 0, |
| 4249 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4250 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4251 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | }; |
| 4253 | struct nfs4_readdir_res res; |
| 4254 | struct rpc_message msg = { |
| 4255 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4256 | .rpc_argp = &args, |
| 4257 | .rpc_resp = &res, |
| 4258 | .rpc_cred = cred, |
| 4259 | }; |
| 4260 | int status; |
| 4261 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4262 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4263 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4264 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4265 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4267 | 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] | 4268 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4269 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4270 | status += args.pgbase; |
| 4271 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4272 | |
| 4273 | nfs_invalidate_atime(dir); |
| 4274 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4275 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | return status; |
| 4277 | } |
| 4278 | |
| 4279 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4280 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | { |
| 4282 | struct nfs4_exception exception = { }; |
| 4283 | int err; |
| 4284 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4285 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4286 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4287 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4288 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | &exception); |
| 4290 | } while (exception.retry); |
| 4291 | return err; |
| 4292 | } |
| 4293 | |
| 4294 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4295 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4297 | struct nfs4_createdata *data; |
| 4298 | int mode = sattr->ia_mode; |
| 4299 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4301 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4302 | if (data == NULL) |
| 4303 | goto out; |
| 4304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4306 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4308 | data->arg.ftype = NF4BLK; |
| 4309 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4310 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | } |
| 4312 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4313 | data->arg.ftype = NF4CHR; |
| 4314 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4315 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4316 | } else if (!S_ISSOCK(mode)) { |
| 4317 | status = -EINVAL; |
| 4318 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4320 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4321 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4322 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4323 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4324 | nfs4_free_createdata(data); |
| 4325 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | return status; |
| 4327 | } |
| 4328 | |
| 4329 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4330 | struct iattr *sattr, dev_t rdev) |
| 4331 | { |
| 4332 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4333 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4335 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4336 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4337 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4338 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4340 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4341 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4342 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | &exception); |
| 4344 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4345 | |
| 4346 | nfs4_label_release_security(label); |
| 4347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | return err; |
| 4349 | } |
| 4350 | |
| 4351 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4352 | struct nfs_fsstat *fsstat) |
| 4353 | { |
| 4354 | struct nfs4_statfs_arg args = { |
| 4355 | .fh = fhandle, |
| 4356 | .bitmask = server->attr_bitmask, |
| 4357 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4358 | struct nfs4_statfs_res res = { |
| 4359 | .fsstat = fsstat, |
| 4360 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | struct rpc_message msg = { |
| 4362 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4363 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4364 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | }; |
| 4366 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4367 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4368 | 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] | 4369 | } |
| 4370 | |
| 4371 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4372 | { |
| 4373 | struct nfs4_exception exception = { }; |
| 4374 | int err; |
| 4375 | do { |
| 4376 | err = nfs4_handle_exception(server, |
| 4377 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4378 | &exception); |
| 4379 | } while (exception.retry); |
| 4380 | return err; |
| 4381 | } |
| 4382 | |
| 4383 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4384 | struct nfs_fsinfo *fsinfo) |
| 4385 | { |
| 4386 | struct nfs4_fsinfo_arg args = { |
| 4387 | .fh = fhandle, |
| 4388 | .bitmask = server->attr_bitmask, |
| 4389 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4390 | struct nfs4_fsinfo_res res = { |
| 4391 | .fsinfo = fsinfo, |
| 4392 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | struct rpc_message msg = { |
| 4394 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4395 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4396 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | }; |
| 4398 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4399 | 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] | 4400 | } |
| 4401 | |
| 4402 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4403 | { |
| 4404 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4405 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | int err; |
| 4407 | |
| 4408 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4409 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4410 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4411 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4412 | nfs4_set_lease_period(server->nfs_client, |
| 4413 | fsinfo->lease_time * HZ, |
| 4414 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4415 | break; |
| 4416 | } |
| 4417 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | } while (exception.retry); |
| 4419 | return err; |
| 4420 | } |
| 4421 | |
| 4422 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4423 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4424 | int error; |
| 4425 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4426 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4427 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4428 | if (error == 0) { |
| 4429 | /* block layout checks this! */ |
| 4430 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4431 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4432 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4433 | |
| 4434 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4438 | struct nfs_pathconf *pathconf) |
| 4439 | { |
| 4440 | struct nfs4_pathconf_arg args = { |
| 4441 | .fh = fhandle, |
| 4442 | .bitmask = server->attr_bitmask, |
| 4443 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4444 | struct nfs4_pathconf_res res = { |
| 4445 | .pathconf = pathconf, |
| 4446 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | struct rpc_message msg = { |
| 4448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4449 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4450 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | }; |
| 4452 | |
| 4453 | /* None of the pathconf attributes are mandatory to implement */ |
| 4454 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4455 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4456 | return 0; |
| 4457 | } |
| 4458 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4459 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4460 | 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] | 4461 | } |
| 4462 | |
| 4463 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4464 | struct nfs_pathconf *pathconf) |
| 4465 | { |
| 4466 | struct nfs4_exception exception = { }; |
| 4467 | int err; |
| 4468 | |
| 4469 | do { |
| 4470 | err = nfs4_handle_exception(server, |
| 4471 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4472 | &exception); |
| 4473 | } while (exception.retry); |
| 4474 | return err; |
| 4475 | } |
| 4476 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4477 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4478 | const struct nfs_open_context *ctx, |
| 4479 | const struct nfs_lock_context *l_ctx, |
| 4480 | fmode_t fmode) |
| 4481 | { |
| 4482 | const struct nfs_lockowner *lockowner = NULL; |
| 4483 | |
| 4484 | if (l_ctx != NULL) |
| 4485 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4486 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4487 | } |
| 4488 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4489 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4490 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4491 | const struct nfs_open_context *ctx, |
| 4492 | const struct nfs_lock_context *l_ctx, |
| 4493 | fmode_t fmode) |
| 4494 | { |
| 4495 | nfs4_stateid current_stateid; |
| 4496 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4497 | /* If the current stateid represents a lost lock, then exit */ |
| 4498 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4499 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4500 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4501 | } |
| 4502 | |
| 4503 | static bool nfs4_error_stateid_expired(int err) |
| 4504 | { |
| 4505 | switch (err) { |
| 4506 | case -NFS4ERR_DELEG_REVOKED: |
| 4507 | case -NFS4ERR_ADMIN_REVOKED: |
| 4508 | case -NFS4ERR_BAD_STATEID: |
| 4509 | case -NFS4ERR_STALE_STATEID: |
| 4510 | case -NFS4ERR_OLD_STATEID: |
| 4511 | case -NFS4ERR_OPENMODE: |
| 4512 | case -NFS4ERR_EXPIRED: |
| 4513 | return true; |
| 4514 | } |
| 4515 | return false; |
| 4516 | } |
| 4517 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4518 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4519 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4520 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4521 | } |
| 4522 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4523 | 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] | 4524 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4525 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4527 | trace_nfs4_read(hdr, task->tk_status); |
| 4528 | if (nfs4_async_handle_error(task, server, |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4529 | hdr->args.context->state, |
| 4530 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4531 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4532 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4534 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4535 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4537 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4538 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4541 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4542 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4543 | { |
| 4544 | |
| 4545 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4546 | nfs4_stateid_is_current(&args->stateid, |
| 4547 | args->context, |
| 4548 | args->lock_context, |
| 4549 | FMODE_READ)) |
| 4550 | return false; |
| 4551 | rpc_restart_call_prepare(task); |
| 4552 | return true; |
| 4553 | } |
| 4554 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4555 | 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] | 4556 | { |
| 4557 | |
| 4558 | dprintk("--> %s\n", __func__); |
| 4559 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4560 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4561 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4562 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4563 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4564 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4565 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4568 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4569 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4571 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4572 | if (!hdr->pgio_done_cb) |
| 4573 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4574 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4575 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4578 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4579 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4580 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4581 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4582 | &hdr->args.seq_args, |
| 4583 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4584 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4585 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4586 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4587 | hdr->args.lock_context, |
| 4588 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4589 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4590 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4591 | return -EIO; |
| 4592 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4595 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4596 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4598 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4599 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4600 | trace_nfs4_write(hdr, task->tk_status); |
| 4601 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4602 | hdr->args.context->state, |
| 4603 | NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4604 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4605 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4607 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4608 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4609 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4610 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4611 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4614 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4615 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4616 | { |
| 4617 | |
| 4618 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4619 | nfs4_stateid_is_current(&args->stateid, |
| 4620 | args->context, |
| 4621 | args->lock_context, |
| 4622 | FMODE_WRITE)) |
| 4623 | return false; |
| 4624 | rpc_restart_call_prepare(task); |
| 4625 | return true; |
| 4626 | } |
| 4627 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4628 | 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] | 4629 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4630 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4631 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4632 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4633 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4634 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4635 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4638 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4639 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4640 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4641 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4642 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4643 | return false; |
| 4644 | /* Otherwise, request attributes if and only if we don't hold |
| 4645 | * a delegation |
| 4646 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4647 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4648 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4649 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4650 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4651 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4653 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4654 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4655 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4656 | hdr->args.bitmask = NULL; |
| 4657 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4658 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4659 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4660 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4661 | if (!hdr->pgio_done_cb) |
| 4662 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4663 | hdr->res.server = server; |
| 4664 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4666 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4667 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4670 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4671 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4672 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4673 | &data->args.seq_args, |
| 4674 | &data->res.seq_res, |
| 4675 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | } |
| 4677 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4678 | 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] | 4679 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4681 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4682 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4683 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4684 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4685 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4686 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4688 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4691 | 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] | 4692 | { |
| 4693 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4694 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4695 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4698 | 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] | 4699 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4700 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4701 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4702 | if (data->commit_done_cb == NULL) |
| 4703 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4704 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4705 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4706 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4709 | struct nfs4_renewdata { |
| 4710 | struct nfs_client *client; |
| 4711 | unsigned long timestamp; |
| 4712 | }; |
| 4713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | /* |
| 4715 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4716 | * standalone procedure for queueing an asynchronous RENEW. |
| 4717 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4718 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4719 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4720 | struct nfs4_renewdata *data = calldata; |
| 4721 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4722 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4723 | if (atomic_read(&clp->cl_count) > 1) |
| 4724 | nfs4_schedule_state_renewal(clp); |
| 4725 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4726 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4727 | } |
| 4728 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4729 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4731 | struct nfs4_renewdata *data = calldata; |
| 4732 | struct nfs_client *clp = data->client; |
| 4733 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4735 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4736 | switch (task->tk_status) { |
| 4737 | case 0: |
| 4738 | break; |
| 4739 | case -NFS4ERR_LEASE_MOVED: |
| 4740 | nfs4_schedule_lease_moved_recovery(clp); |
| 4741 | break; |
| 4742 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4743 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4744 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4745 | return; |
| 4746 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4747 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4748 | return; |
| 4749 | } |
| 4750 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4752 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | } |
| 4754 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4755 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4756 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4757 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4758 | }; |
| 4759 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4760 | 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] | 4761 | { |
| 4762 | struct rpc_message msg = { |
| 4763 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4764 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4765 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4767 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4769 | if (renew_flags == 0) |
| 4770 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4771 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4772 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4773 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4774 | if (data == NULL) |
| 4775 | return -ENOMEM; |
| 4776 | data->client = clp; |
| 4777 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4778 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4779 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4782 | 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] | 4783 | { |
| 4784 | struct rpc_message msg = { |
| 4785 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4786 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4787 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | }; |
| 4789 | unsigned long now = jiffies; |
| 4790 | int status; |
| 4791 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4792 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | if (status < 0) |
| 4794 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4795 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | return 0; |
| 4797 | } |
| 4798 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4799 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4800 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4801 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4804 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4805 | * 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] | 4806 | * the stack. |
| 4807 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4808 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4809 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4810 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4811 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4812 | { |
| 4813 | struct page *newpage, **spages; |
| 4814 | int rc = 0; |
| 4815 | size_t len; |
| 4816 | spages = pages; |
| 4817 | |
| 4818 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4819 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4820 | newpage = alloc_page(GFP_KERNEL); |
| 4821 | |
| 4822 | if (newpage == NULL) |
| 4823 | goto unwind; |
| 4824 | memcpy(page_address(newpage), buf, len); |
| 4825 | buf += len; |
| 4826 | buflen -= len; |
| 4827 | *pages++ = newpage; |
| 4828 | rc++; |
| 4829 | } while (buflen != 0); |
| 4830 | |
| 4831 | return rc; |
| 4832 | |
| 4833 | unwind: |
| 4834 | for(; rc > 0; rc--) |
| 4835 | __free_page(spages[rc-1]); |
| 4836 | return -ENOMEM; |
| 4837 | } |
| 4838 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4839 | struct nfs4_cached_acl { |
| 4840 | int cached; |
| 4841 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4842 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4843 | }; |
| 4844 | |
| 4845 | 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] | 4846 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4847 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4848 | |
| 4849 | spin_lock(&inode->i_lock); |
| 4850 | kfree(nfsi->nfs4_acl); |
| 4851 | nfsi->nfs4_acl = acl; |
| 4852 | spin_unlock(&inode->i_lock); |
| 4853 | } |
| 4854 | |
| 4855 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4856 | { |
| 4857 | nfs4_set_cached_acl(inode, NULL); |
| 4858 | } |
| 4859 | |
| 4860 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4861 | { |
| 4862 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4863 | struct nfs4_cached_acl *acl; |
| 4864 | int ret = -ENOENT; |
| 4865 | |
| 4866 | spin_lock(&inode->i_lock); |
| 4867 | acl = nfsi->nfs4_acl; |
| 4868 | if (acl == NULL) |
| 4869 | goto out; |
| 4870 | if (buf == NULL) /* user is just asking for length */ |
| 4871 | goto out_len; |
| 4872 | if (acl->cached == 0) |
| 4873 | goto out; |
| 4874 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4875 | if (acl->len > buflen) |
| 4876 | goto out; |
| 4877 | memcpy(buf, acl->data, acl->len); |
| 4878 | out_len: |
| 4879 | ret = acl->len; |
| 4880 | out: |
| 4881 | spin_unlock(&inode->i_lock); |
| 4882 | return ret; |
| 4883 | } |
| 4884 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4885 | 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] | 4886 | { |
| 4887 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4888 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4889 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4890 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4891 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4892 | if (acl == NULL) |
| 4893 | goto out; |
| 4894 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4895 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4896 | } else { |
| 4897 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4898 | if (acl == NULL) |
| 4899 | goto out; |
| 4900 | acl->cached = 0; |
| 4901 | } |
| 4902 | acl->len = acl_len; |
| 4903 | out: |
| 4904 | nfs4_set_cached_acl(inode, acl); |
| 4905 | } |
| 4906 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4907 | /* |
| 4908 | * The getxattr API returns the required buffer length when called with a |
| 4909 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4910 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4911 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4912 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4913 | * the cache. If not so, we throw away the page, and cache the required |
| 4914 | * length. The next getxattr call will then produce another round trip to |
| 4915 | * the server, this time with the input buf of the required size. |
| 4916 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4917 | 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] | 4918 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4919 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4920 | struct nfs_getaclargs args = { |
| 4921 | .fh = NFS_FH(inode), |
| 4922 | .acl_pages = pages, |
| 4923 | .acl_len = buflen, |
| 4924 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4925 | struct nfs_getaclres res = { |
| 4926 | .acl_len = buflen, |
| 4927 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4928 | struct rpc_message msg = { |
| 4929 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4930 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4931 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4932 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4933 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4934 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4935 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4936 | /* As long as we're doing a round trip to the server anyway, |
| 4937 | * let's be prepared for a page of acl data. */ |
| 4938 | if (npages == 0) |
| 4939 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4940 | if (npages > ARRAY_SIZE(pages)) |
| 4941 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4942 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4943 | for (i = 0; i < npages; i++) { |
| 4944 | pages[i] = alloc_page(GFP_KERNEL); |
| 4945 | if (!pages[i]) |
| 4946 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4947 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4948 | |
| 4949 | /* for decoding across pages */ |
| 4950 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4951 | if (!res.acl_scratch) |
| 4952 | goto out_free; |
| 4953 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4954 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4955 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4956 | 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] | 4957 | __func__, buf, buflen, npages, args.acl_len); |
| 4958 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4959 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4960 | if (ret) |
| 4961 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4962 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4963 | /* Handle the case where the passed-in buffer is too short */ |
| 4964 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4965 | /* Did the user only issue a request for the acl length? */ |
| 4966 | if (buf == NULL) |
| 4967 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4968 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4969 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4970 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4971 | 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] | 4972 | if (buf) { |
| 4973 | if (res.acl_len > buflen) { |
| 4974 | ret = -ERANGE; |
| 4975 | goto out_free; |
| 4976 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4977 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 4978 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4979 | out_ok: |
| 4980 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4981 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4982 | for (i = 0; i < npages; i++) |
| 4983 | if (pages[i]) |
| 4984 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 4985 | if (res.acl_scratch) |
| 4986 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4987 | return ret; |
| 4988 | } |
| 4989 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4990 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 4991 | { |
| 4992 | struct nfs4_exception exception = { }; |
| 4993 | ssize_t ret; |
| 4994 | do { |
| 4995 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4996 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4997 | if (ret >= 0) |
| 4998 | break; |
| 4999 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5000 | } while (exception.retry); |
| 5001 | return ret; |
| 5002 | } |
| 5003 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5004 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5005 | { |
| 5006 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5007 | int ret; |
| 5008 | |
| 5009 | if (!nfs4_server_supports_acls(server)) |
| 5010 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5011 | ret = nfs_revalidate_inode(server, inode); |
| 5012 | if (ret < 0) |
| 5013 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5014 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5015 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5016 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5017 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5018 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5019 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5020 | return ret; |
| 5021 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5024 | 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] | 5025 | { |
| 5026 | struct nfs_server *server = NFS_SERVER(inode); |
| 5027 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5028 | struct nfs_setaclargs arg = { |
| 5029 | .fh = NFS_FH(inode), |
| 5030 | .acl_pages = pages, |
| 5031 | .acl_len = buflen, |
| 5032 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5033 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5034 | struct rpc_message msg = { |
| 5035 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5036 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5037 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5038 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5039 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5040 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5041 | |
| 5042 | if (!nfs4_server_supports_acls(server)) |
| 5043 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5044 | if (npages > ARRAY_SIZE(pages)) |
| 5045 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5046 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5047 | if (i < 0) |
| 5048 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5049 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5050 | 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] | 5051 | |
| 5052 | /* |
| 5053 | * Free each page after tx, so the only ref left is |
| 5054 | * held by the network stack |
| 5055 | */ |
| 5056 | for (; i > 0; i--) |
| 5057 | put_page(pages[i-1]); |
| 5058 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5059 | /* |
| 5060 | * Acl update can result in inode attribute update. |
| 5061 | * so mark the attribute cache invalid. |
| 5062 | */ |
| 5063 | spin_lock(&inode->i_lock); |
| 5064 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5065 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5066 | nfs_access_zap_cache(inode); |
| 5067 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5068 | return ret; |
| 5069 | } |
| 5070 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5071 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5072 | { |
| 5073 | struct nfs4_exception exception = { }; |
| 5074 | int err; |
| 5075 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5076 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5077 | trace_nfs4_set_acl(inode, err); |
| 5078 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5079 | &exception); |
| 5080 | } while (exception.retry); |
| 5081 | return err; |
| 5082 | } |
| 5083 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5084 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5085 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5086 | size_t buflen) |
| 5087 | { |
| 5088 | struct nfs_server *server = NFS_SERVER(inode); |
| 5089 | struct nfs_fattr fattr; |
| 5090 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5091 | |
| 5092 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5093 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5094 | .fh = NFS_FH(inode), |
| 5095 | .bitmask = bitmask, |
| 5096 | }; |
| 5097 | struct nfs4_getattr_res res = { |
| 5098 | .fattr = &fattr, |
| 5099 | .label = &label, |
| 5100 | .server = server, |
| 5101 | }; |
| 5102 | struct rpc_message msg = { |
| 5103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5104 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5105 | .rpc_resp = &res, |
| 5106 | }; |
| 5107 | int ret; |
| 5108 | |
| 5109 | nfs_fattr_init(&fattr); |
| 5110 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5111 | 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] | 5112 | if (ret) |
| 5113 | return ret; |
| 5114 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5115 | return -ENOENT; |
| 5116 | if (buflen < label.len) |
| 5117 | return -ERANGE; |
| 5118 | return 0; |
| 5119 | } |
| 5120 | |
| 5121 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5122 | size_t buflen) |
| 5123 | { |
| 5124 | struct nfs4_exception exception = { }; |
| 5125 | int err; |
| 5126 | |
| 5127 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5128 | return -EOPNOTSUPP; |
| 5129 | |
| 5130 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5131 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5132 | trace_nfs4_get_security_label(inode, err); |
| 5133 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5134 | &exception); |
| 5135 | } while (exception.retry); |
| 5136 | return err; |
| 5137 | } |
| 5138 | |
| 5139 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5140 | struct nfs4_label *ilabel, |
| 5141 | struct nfs_fattr *fattr, |
| 5142 | struct nfs4_label *olabel) |
| 5143 | { |
| 5144 | |
| 5145 | struct iattr sattr = {0}; |
| 5146 | struct nfs_server *server = NFS_SERVER(inode); |
| 5147 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5148 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5149 | .fh = NFS_FH(inode), |
| 5150 | .iap = &sattr, |
| 5151 | .server = server, |
| 5152 | .bitmask = bitmask, |
| 5153 | .label = ilabel, |
| 5154 | }; |
| 5155 | struct nfs_setattrres res = { |
| 5156 | .fattr = fattr, |
| 5157 | .label = olabel, |
| 5158 | .server = server, |
| 5159 | }; |
| 5160 | struct rpc_message msg = { |
| 5161 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5162 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5163 | .rpc_resp = &res, |
| 5164 | }; |
| 5165 | int status; |
| 5166 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5167 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5168 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5169 | 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] | 5170 | if (status) |
| 5171 | dprintk("%s failed: %d\n", __func__, status); |
| 5172 | |
| 5173 | return status; |
| 5174 | } |
| 5175 | |
| 5176 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5177 | struct nfs4_label *ilabel, |
| 5178 | struct nfs_fattr *fattr, |
| 5179 | struct nfs4_label *olabel) |
| 5180 | { |
| 5181 | struct nfs4_exception exception = { }; |
| 5182 | int err; |
| 5183 | |
| 5184 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5185 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5186 | fattr, olabel); |
| 5187 | trace_nfs4_set_security_label(inode, err); |
| 5188 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5189 | &exception); |
| 5190 | } while (exception.retry); |
| 5191 | return err; |
| 5192 | } |
| 5193 | |
| 5194 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5195 | 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] | 5196 | { |
| 5197 | struct nfs4_label ilabel, *olabel = NULL; |
| 5198 | struct nfs_fattr fattr; |
| 5199 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5200 | int status; |
| 5201 | |
| 5202 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5203 | return -EOPNOTSUPP; |
| 5204 | |
| 5205 | nfs_fattr_init(&fattr); |
| 5206 | |
| 5207 | ilabel.pi = 0; |
| 5208 | ilabel.lfs = 0; |
| 5209 | ilabel.label = (char *)buf; |
| 5210 | ilabel.len = buflen; |
| 5211 | |
| 5212 | cred = rpc_lookup_cred(); |
| 5213 | if (IS_ERR(cred)) |
| 5214 | return PTR_ERR(cred); |
| 5215 | |
| 5216 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5217 | if (IS_ERR(olabel)) { |
| 5218 | status = -PTR_ERR(olabel); |
| 5219 | goto out; |
| 5220 | } |
| 5221 | |
| 5222 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5223 | if (status == 0) |
| 5224 | nfs_setsecurity(inode, &fattr, olabel); |
| 5225 | |
| 5226 | nfs4_label_free(olabel); |
| 5227 | out: |
| 5228 | put_rpccred(cred); |
| 5229 | return status; |
| 5230 | } |
| 5231 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5232 | |
| 5233 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5234 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5235 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5236 | { |
| 5237 | __be32 verf[2]; |
| 5238 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5239 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5240 | /* An impossible timestamp guarantees this value |
| 5241 | * will never match a generated boot time. */ |
| 5242 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5243 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5244 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5245 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5246 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5247 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5248 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5249 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5250 | } |
| 5251 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5252 | static int |
| 5253 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5254 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5255 | size_t len; |
| 5256 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5257 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5258 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5259 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5260 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5261 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5262 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5263 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5264 | 1 + |
| 5265 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5266 | 1; |
| 5267 | rcu_read_unlock(); |
| 5268 | |
| 5269 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5270 | return -EINVAL; |
| 5271 | |
| 5272 | /* |
| 5273 | * Since this string is allocated at mount time, and held until the |
| 5274 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5275 | * about a memory-reclaim deadlock. |
| 5276 | */ |
| 5277 | str = kmalloc(len, GFP_KERNEL); |
| 5278 | if (!str) |
| 5279 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5280 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5281 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5282 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5283 | clp->cl_ipaddr, |
| 5284 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5285 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5286 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5287 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5288 | clp->cl_owner_id = str; |
| 5289 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5290 | } |
| 5291 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5292 | static int |
| 5293 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5294 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5295 | size_t len; |
| 5296 | char *str; |
| 5297 | |
| 5298 | len = 10 + 10 + 1 + 10 + 1 + |
| 5299 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5300 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5301 | |
| 5302 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5303 | return -EINVAL; |
| 5304 | |
| 5305 | /* |
| 5306 | * Since this string is allocated at mount time, and held until the |
| 5307 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5308 | * about a memory-reclaim deadlock. |
| 5309 | */ |
| 5310 | str = kmalloc(len, GFP_KERNEL); |
| 5311 | if (!str) |
| 5312 | return -ENOMEM; |
| 5313 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5314 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5315 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5316 | nfs4_client_id_uniquifier, |
| 5317 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5318 | clp->cl_owner_id = str; |
| 5319 | return 0; |
| 5320 | } |
| 5321 | |
| 5322 | static int |
| 5323 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5324 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5325 | size_t len; |
| 5326 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5327 | |
| 5328 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5329 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5330 | |
| 5331 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5332 | return nfs4_init_uniquifier_client_string(clp); |
| 5333 | |
| 5334 | len = 10 + 10 + 1 + 10 + 1 + |
| 5335 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5336 | |
| 5337 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5338 | return -EINVAL; |
| 5339 | |
| 5340 | /* |
| 5341 | * Since this string is allocated at mount time, and held until the |
| 5342 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5343 | * about a memory-reclaim deadlock. |
| 5344 | */ |
| 5345 | str = kmalloc(len, GFP_KERNEL); |
| 5346 | if (!str) |
| 5347 | return -ENOMEM; |
| 5348 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5349 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5350 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5351 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5352 | clp->cl_owner_id = str; |
| 5353 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5354 | } |
| 5355 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5356 | /* |
| 5357 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5358 | * services. Advertise one based on the address family of the |
| 5359 | * clientaddr. |
| 5360 | */ |
| 5361 | static unsigned int |
| 5362 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5363 | { |
| 5364 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5365 | return scnprintf(buf, len, "tcp6"); |
| 5366 | else |
| 5367 | return scnprintf(buf, len, "tcp"); |
| 5368 | } |
| 5369 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5370 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5371 | { |
| 5372 | struct nfs4_setclientid *sc = calldata; |
| 5373 | |
| 5374 | if (task->tk_status == 0) |
| 5375 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5376 | } |
| 5377 | |
| 5378 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5379 | .rpc_call_done = nfs4_setclientid_done, |
| 5380 | }; |
| 5381 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5382 | /** |
| 5383 | * nfs4_proc_setclientid - Negotiate client ID |
| 5384 | * @clp: state data structure |
| 5385 | * @program: RPC program for NFSv4 callback service |
| 5386 | * @port: IP port number for NFS4 callback service |
| 5387 | * @cred: RPC credential to use for this call |
| 5388 | * @res: where to place the result |
| 5389 | * |
| 5390 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5391 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5392 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5393 | unsigned short port, struct rpc_cred *cred, |
| 5394 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | { |
| 5396 | nfs4_verifier sc_verifier; |
| 5397 | struct nfs4_setclientid setclientid = { |
| 5398 | .sc_verifier = &sc_verifier, |
| 5399 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5400 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | }; |
| 5402 | struct rpc_message msg = { |
| 5403 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5404 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5405 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5406 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5408 | struct rpc_task *task; |
| 5409 | struct rpc_task_setup task_setup_data = { |
| 5410 | .rpc_client = clp->cl_rpcclient, |
| 5411 | .rpc_message = &msg, |
| 5412 | .callback_ops = &nfs4_setclientid_ops, |
| 5413 | .callback_data = &setclientid, |
| 5414 | .flags = RPC_TASK_TIMEOUT, |
| 5415 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5416 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5418 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5419 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5420 | |
| 5421 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5422 | status = nfs4_init_uniform_client_string(clp); |
| 5423 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5424 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5425 | |
| 5426 | if (status) |
| 5427 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5428 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5429 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5430 | setclientid.sc_netid_len = |
| 5431 | nfs4_init_callback_netid(clp, |
| 5432 | setclientid.sc_netid, |
| 5433 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5434 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5435 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5437 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5438 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5439 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5440 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5441 | task = rpc_run_task(&task_setup_data); |
| 5442 | if (IS_ERR(task)) { |
| 5443 | status = PTR_ERR(task); |
| 5444 | goto out; |
| 5445 | } |
| 5446 | status = task->tk_status; |
| 5447 | if (setclientid.sc_cred) { |
| 5448 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5449 | put_rpccred(setclientid.sc_cred); |
| 5450 | } |
| 5451 | rpc_put_task(task); |
| 5452 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5453 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5454 | dprintk("NFS reply setclientid: %d\n", status); |
| 5455 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5458 | /** |
| 5459 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5460 | * @clp: state data structure |
| 5461 | * @res: result of a previous SETCLIENTID |
| 5462 | * @cred: RPC credential to use for this call |
| 5463 | * |
| 5464 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5465 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5466 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5467 | struct nfs4_setclientid_res *arg, |
| 5468 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | struct rpc_message msg = { |
| 5471 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5472 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5473 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | int status; |
| 5476 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5477 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5478 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5479 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5480 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5481 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5482 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | return status; |
| 5484 | } |
| 5485 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5486 | struct nfs4_delegreturndata { |
| 5487 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5488 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5489 | struct nfs_fh fh; |
| 5490 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5491 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5492 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5493 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5494 | struct inode *inode; |
| 5495 | bool roc; |
| 5496 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5497 | }; |
| 5498 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5499 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5500 | { |
| 5501 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5502 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5503 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5504 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5505 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5506 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5507 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5508 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5509 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5510 | case -NFS4ERR_ADMIN_REVOKED: |
| 5511 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5512 | case -NFS4ERR_EXPIRED: |
| 5513 | nfs4_free_revoked_stateid(data->res.server, |
| 5514 | data->args.stateid, |
| 5515 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5516 | case -NFS4ERR_BAD_STATEID: |
| 5517 | case -NFS4ERR_OLD_STATEID: |
| 5518 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5519 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5520 | if (data->roc) |
| 5521 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5522 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5523 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5524 | if (nfs4_async_handle_error(task, data->res.server, |
| 5525 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5526 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5527 | return; |
| 5528 | } |
| 5529 | } |
| 5530 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | static void nfs4_delegreturn_release(void *calldata) |
| 5534 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5535 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5536 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5537 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5538 | if (inode) { |
| 5539 | if (data->roc) |
| 5540 | pnfs_roc_release(inode); |
| 5541 | nfs_iput_and_deactive(inode); |
| 5542 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5543 | kfree(calldata); |
| 5544 | } |
| 5545 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5546 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5547 | { |
| 5548 | struct nfs4_delegreturndata *d_data; |
| 5549 | |
| 5550 | d_data = (struct nfs4_delegreturndata *)data; |
| 5551 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5552 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5553 | return; |
| 5554 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5555 | if (d_data->roc) |
| 5556 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5557 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5558 | nfs4_setup_sequence(d_data->res.server, |
| 5559 | &d_data->args.seq_args, |
| 5560 | &d_data->res.seq_res, |
| 5561 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5562 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5563 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5564 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5565 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5566 | .rpc_call_done = nfs4_delegreturn_done, |
| 5567 | .rpc_release = nfs4_delegreturn_release, |
| 5568 | }; |
| 5569 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5570 | 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] | 5571 | { |
| 5572 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5573 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5574 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5575 | struct rpc_message msg = { |
| 5576 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5577 | .rpc_cred = cred, |
| 5578 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5579 | struct rpc_task_setup task_setup_data = { |
| 5580 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5581 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5582 | .callback_ops = &nfs4_delegreturn_ops, |
| 5583 | .flags = RPC_TASK_ASYNC, |
| 5584 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5585 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5586 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5587 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5588 | if (data == NULL) |
| 5589 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5590 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5591 | |
| 5592 | nfs4_state_protect(server->nfs_client, |
| 5593 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5594 | &task_setup_data.rpc_client, &msg); |
| 5595 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5596 | data->args.fhandle = &data->fh; |
| 5597 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5598 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5599 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5600 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5601 | data->res.fattr = &data->fattr; |
| 5602 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5603 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5604 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5605 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5606 | data->inode = nfs_igrab_and_active(inode); |
| 5607 | if (data->inode) |
| 5608 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5609 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5610 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5611 | msg.rpc_argp = &data->args; |
| 5612 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5613 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5614 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5615 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5616 | if (!issync) |
| 5617 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5618 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5619 | if (status != 0) |
| 5620 | goto out; |
| 5621 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5622 | if (status == 0) |
| 5623 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5624 | else |
| 5625 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5626 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5627 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5628 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5631 | 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] | 5632 | { |
| 5633 | struct nfs_server *server = NFS_SERVER(inode); |
| 5634 | struct nfs4_exception exception = { }; |
| 5635 | int err; |
| 5636 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5637 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5638 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5639 | switch (err) { |
| 5640 | case -NFS4ERR_STALE_STATEID: |
| 5641 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | case 0: |
| 5643 | return 0; |
| 5644 | } |
| 5645 | err = nfs4_handle_exception(server, err, &exception); |
| 5646 | } while (exception.retry); |
| 5647 | return err; |
| 5648 | } |
| 5649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5651 | { |
| 5652 | struct inode *inode = state->inode; |
| 5653 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5654 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5655 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5657 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5658 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5659 | struct nfs_lockt_res res = { |
| 5660 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | }; |
| 5662 | struct rpc_message msg = { |
| 5663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5664 | .rpc_argp = &arg, |
| 5665 | .rpc_resp = &res, |
| 5666 | .rpc_cred = state->owner->so_cred, |
| 5667 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | struct nfs4_lock_state *lsp; |
| 5669 | int status; |
| 5670 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5671 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5672 | status = nfs4_set_lock_state(state, request); |
| 5673 | if (status != 0) |
| 5674 | goto out; |
| 5675 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5676 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5677 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5678 | 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] | 5679 | switch (status) { |
| 5680 | case 0: |
| 5681 | request->fl_type = F_UNLCK; |
| 5682 | break; |
| 5683 | case -NFS4ERR_DENIED: |
| 5684 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5686 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5687 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5688 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | return status; |
| 5690 | } |
| 5691 | |
| 5692 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5693 | { |
| 5694 | struct nfs4_exception exception = { }; |
| 5695 | int err; |
| 5696 | |
| 5697 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5698 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5699 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5700 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | &exception); |
| 5702 | } while (exception.retry); |
| 5703 | return err; |
| 5704 | } |
| 5705 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5706 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5707 | struct nfs_locku_args arg; |
| 5708 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5709 | struct nfs4_lock_state *lsp; |
| 5710 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5711 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5712 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5713 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5714 | }; |
| 5715 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5716 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5717 | struct nfs_open_context *ctx, |
| 5718 | struct nfs4_lock_state *lsp, |
| 5719 | struct nfs_seqid *seqid) |
| 5720 | { |
| 5721 | struct nfs4_unlockdata *p; |
| 5722 | struct inode *inode = lsp->ls_state->inode; |
| 5723 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5724 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5725 | if (p == NULL) |
| 5726 | return NULL; |
| 5727 | p->arg.fh = NFS_FH(inode); |
| 5728 | p->arg.fl = &p->fl; |
| 5729 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5730 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5731 | p->lsp = lsp; |
| 5732 | atomic_inc(&lsp->ls_count); |
| 5733 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5734 | p->ctx = get_nfs_open_context(ctx); |
| 5735 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5736 | p->server = NFS_SERVER(inode); |
| 5737 | return p; |
| 5738 | } |
| 5739 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5740 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5741 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5742 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5743 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5744 | nfs4_put_lock_state(calldata->lsp); |
| 5745 | put_nfs_open_context(calldata->ctx); |
| 5746 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5749 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5750 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5751 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5752 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5753 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5754 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5755 | switch (task->tk_status) { |
| 5756 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5757 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5758 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5759 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5760 | &calldata->res.stateid)) |
| 5761 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5762 | case -NFS4ERR_ADMIN_REVOKED: |
| 5763 | case -NFS4ERR_EXPIRED: |
| 5764 | nfs4_free_revoked_stateid(calldata->server, |
| 5765 | &calldata->arg.stateid, |
| 5766 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5767 | case -NFS4ERR_BAD_STATEID: |
| 5768 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5769 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5770 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5771 | &calldata->lsp->ls_stateid)) |
| 5772 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5773 | break; |
| 5774 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5775 | if (nfs4_async_handle_error(task, calldata->server, |
| 5776 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5777 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5778 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5779 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5782 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5783 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5784 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5786 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5787 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5788 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5789 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5790 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5791 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5792 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5793 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5794 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5795 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5796 | &calldata->res.seq_res, |
| 5797 | task) != 0) |
| 5798 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5799 | return; |
| 5800 | out_no_action: |
| 5801 | task->tk_action = NULL; |
| 5802 | out_wait: |
| 5803 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5806 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5807 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5808 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5809 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5810 | }; |
| 5811 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5812 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5813 | struct nfs_open_context *ctx, |
| 5814 | struct nfs4_lock_state *lsp, |
| 5815 | struct nfs_seqid *seqid) |
| 5816 | { |
| 5817 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5818 | struct rpc_message msg = { |
| 5819 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5820 | .rpc_cred = ctx->cred, |
| 5821 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5822 | struct rpc_task_setup task_setup_data = { |
| 5823 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5824 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5825 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5826 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5827 | .flags = RPC_TASK_ASYNC, |
| 5828 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5829 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5830 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5831 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5832 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5833 | /* Ensure this is an unlock - when canceling a lock, the |
| 5834 | * canceled lock is passed in, and it won't be an unlock. |
| 5835 | */ |
| 5836 | fl->fl_type = F_UNLCK; |
| 5837 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5838 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5839 | if (data == NULL) { |
| 5840 | nfs_free_seqid(seqid); |
| 5841 | return ERR_PTR(-ENOMEM); |
| 5842 | } |
| 5843 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5844 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5845 | msg.rpc_argp = &data->arg; |
| 5846 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5847 | task_setup_data.callback_data = data; |
| 5848 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5849 | } |
| 5850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5852 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5853 | struct inode *inode = state->inode; |
| 5854 | struct nfs4_state_owner *sp = state->owner; |
| 5855 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5856 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5857 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5858 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5859 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5860 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5861 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5863 | status = nfs4_set_lock_state(state, request); |
| 5864 | /* Unlock _before_ we do the RPC call */ |
| 5865 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5866 | /* Exclude nfs_delegation_claim_locks() */ |
| 5867 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5868 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5869 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5870 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5871 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5872 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5873 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5874 | } |
| 5875 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5876 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5877 | if (status != 0) |
| 5878 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5879 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5880 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5881 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5882 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5883 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5884 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5885 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5886 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5887 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5888 | 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] | 5889 | status = PTR_ERR(task); |
| 5890 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5891 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5892 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5893 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5894 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5895 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5896 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5897 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5900 | struct nfs4_lockdata { |
| 5901 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5902 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5903 | struct nfs4_lock_state *lsp; |
| 5904 | struct nfs_open_context *ctx; |
| 5905 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5906 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5907 | int rpc_status; |
| 5908 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5909 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5910 | }; |
| 5911 | |
| 5912 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5913 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5914 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5915 | { |
| 5916 | struct nfs4_lockdata *p; |
| 5917 | struct inode *inode = lsp->ls_state->inode; |
| 5918 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5919 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5920 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5921 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5922 | if (p == NULL) |
| 5923 | return NULL; |
| 5924 | |
| 5925 | p->arg.fh = NFS_FH(inode); |
| 5926 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5927 | 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] | 5928 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5929 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5930 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5931 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5932 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5933 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5934 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5935 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5936 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5937 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5938 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5939 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5940 | atomic_inc(&lsp->ls_count); |
| 5941 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5942 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5943 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5944 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5945 | out_free_seqid: |
| 5946 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5947 | out_free: |
| 5948 | kfree(p); |
| 5949 | return NULL; |
| 5950 | } |
| 5951 | |
| 5952 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5953 | { |
| 5954 | struct nfs4_lockdata *data = calldata; |
| 5955 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5956 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5957 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5958 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5959 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5960 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5961 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5962 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5963 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5964 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5965 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5966 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5967 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5968 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5969 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5970 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5971 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 5972 | &data->lsp->ls_stateid); |
| 5973 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5974 | if (!nfs4_valid_open_stateid(state)) { |
| 5975 | data->rpc_status = -EBADF; |
| 5976 | task->tk_action = NULL; |
| 5977 | goto out_release_open_seqid; |
| 5978 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5979 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5980 | if (nfs4_setup_sequence(data->server, |
| 5981 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5982 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5983 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5984 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 5985 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5986 | nfs_release_seqid(data->arg.open_seqid); |
| 5987 | out_release_lock_seqid: |
| 5988 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5989 | out_wait: |
| 5990 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5991 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5992 | } |
| 5993 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5994 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5995 | { |
| 5996 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 5997 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5998 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5999 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6000 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6001 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6002 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6003 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6004 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6005 | switch (task->tk_status) { |
| 6006 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6007 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6008 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6009 | if (data->arg.new_lock) { |
| 6010 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6011 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6012 | rpc_restart_call_prepare(task); |
| 6013 | break; |
| 6014 | } |
| 6015 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6016 | if (data->arg.new_lock_owner != 0) { |
| 6017 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6018 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6019 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6020 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6021 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6022 | break; |
| 6023 | case -NFS4ERR_BAD_STATEID: |
| 6024 | case -NFS4ERR_OLD_STATEID: |
| 6025 | case -NFS4ERR_STALE_STATEID: |
| 6026 | case -NFS4ERR_EXPIRED: |
| 6027 | if (data->arg.new_lock_owner != 0) { |
| 6028 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6029 | &lsp->ls_state->open_stateid)) |
| 6030 | rpc_restart_call_prepare(task); |
| 6031 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6032 | &lsp->ls_stateid)) |
| 6033 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6034 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6035 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | static void nfs4_lock_release(void *calldata) |
| 6039 | { |
| 6040 | struct nfs4_lockdata *data = calldata; |
| 6041 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6042 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6043 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6044 | if (data->cancelled != 0) { |
| 6045 | struct rpc_task *task; |
| 6046 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6047 | data->arg.lock_seqid); |
| 6048 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6049 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6050 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6051 | } else |
| 6052 | nfs_free_seqid(data->arg.lock_seqid); |
| 6053 | nfs4_put_lock_state(data->lsp); |
| 6054 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6055 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6056 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6057 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6061 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6062 | .rpc_call_done = nfs4_lock_done, |
| 6063 | .rpc_release = nfs4_lock_release, |
| 6064 | }; |
| 6065 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6066 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6067 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6068 | switch (error) { |
| 6069 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6070 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6071 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6072 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6073 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6074 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6075 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6076 | break; |
| 6077 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6078 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6079 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6080 | }; |
| 6081 | } |
| 6082 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6083 | 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] | 6084 | { |
| 6085 | struct nfs4_lockdata *data; |
| 6086 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6087 | struct rpc_message msg = { |
| 6088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6089 | .rpc_cred = state->owner->so_cred, |
| 6090 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6091 | struct rpc_task_setup task_setup_data = { |
| 6092 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6093 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6094 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6095 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6096 | .flags = RPC_TASK_ASYNC, |
| 6097 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6098 | int ret; |
| 6099 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6100 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6101 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6102 | fl->fl_u.nfs4_fl.owner, |
| 6103 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6104 | if (data == NULL) |
| 6105 | return -ENOMEM; |
| 6106 | if (IS_SETLKW(cmd)) |
| 6107 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6108 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6109 | msg.rpc_argp = &data->arg; |
| 6110 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6111 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6112 | if (recovery_type > NFS_LOCK_NEW) { |
| 6113 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6114 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6115 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6116 | } else |
| 6117 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6118 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6119 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6120 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6121 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6122 | if (ret == 0) { |
| 6123 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6124 | if (ret) |
| 6125 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6126 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6127 | } else |
| 6128 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6129 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6130 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6131 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6132 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6136 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6137 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6138 | struct nfs4_exception exception = { |
| 6139 | .inode = state->inode, |
| 6140 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6141 | int err; |
| 6142 | |
| 6143 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6144 | /* Cache the lock if possible... */ |
| 6145 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6146 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6147 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6148 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6149 | break; |
| 6150 | nfs4_handle_exception(server, err, &exception); |
| 6151 | } while (exception.retry); |
| 6152 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6156 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6157 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6158 | struct nfs4_exception exception = { |
| 6159 | .inode = state->inode, |
| 6160 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6161 | int err; |
| 6162 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6163 | err = nfs4_set_lock_state(state, request); |
| 6164 | if (err != 0) |
| 6165 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6166 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6167 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6168 | return 0; |
| 6169 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6170 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6171 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6172 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6173 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6174 | switch (err) { |
| 6175 | default: |
| 6176 | goto out; |
| 6177 | case -NFS4ERR_GRACE: |
| 6178 | case -NFS4ERR_DELAY: |
| 6179 | nfs4_handle_exception(server, err, &exception); |
| 6180 | err = 0; |
| 6181 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6182 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6183 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6184 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | } |
| 6186 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6187 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6188 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6189 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6190 | struct nfs4_lock_state *lsp; |
| 6191 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6192 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6193 | status = nfs4_set_lock_state(state, request); |
| 6194 | if (status != 0) |
| 6195 | return status; |
| 6196 | lsp = request->fl_u.nfs4_fl.owner; |
| 6197 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6198 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6199 | return 0; |
| 6200 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6201 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6202 | } |
| 6203 | #endif |
| 6204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6206 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6207 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6208 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6209 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6210 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6211 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6212 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6213 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6214 | if (status < 0) |
| 6215 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6216 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6217 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6218 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6219 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6220 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6221 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6222 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6223 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6224 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6225 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6226 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6227 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6228 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6229 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6230 | out: |
| 6231 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | return status; |
| 6233 | } |
| 6234 | |
| 6235 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6236 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6237 | struct nfs4_exception exception = { |
| 6238 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6239 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6240 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | int err; |
| 6242 | |
| 6243 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6244 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6245 | if (err == -NFS4ERR_DENIED) |
| 6246 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6248 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | } while (exception.retry); |
| 6250 | return err; |
| 6251 | } |
| 6252 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6253 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6254 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6255 | |
| 6256 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6257 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6258 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6259 | { |
| 6260 | int status = -ERESTARTSYS; |
| 6261 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6262 | |
| 6263 | while(!signalled()) { |
| 6264 | status = nfs4_proc_setlk(state, cmd, request); |
| 6265 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6266 | break; |
| 6267 | freezable_schedule_timeout_interruptible(timeout); |
| 6268 | timeout *= 2; |
| 6269 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6270 | status = -ERESTARTSYS; |
| 6271 | } |
| 6272 | return status; |
| 6273 | } |
| 6274 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6275 | #ifdef CONFIG_NFS_V4_1 |
| 6276 | struct nfs4_lock_waiter { |
| 6277 | struct task_struct *task; |
| 6278 | struct inode *inode; |
| 6279 | struct nfs_lowner *owner; |
| 6280 | bool notified; |
| 6281 | }; |
| 6282 | |
| 6283 | static int |
| 6284 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6285 | { |
| 6286 | int ret; |
| 6287 | struct cb_notify_lock_args *cbnl = key; |
| 6288 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6289 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6290 | *wowner = waiter->owner; |
| 6291 | |
| 6292 | /* Only wake if the callback was for the same owner */ |
| 6293 | if (lowner->clientid != wowner->clientid || |
| 6294 | lowner->id != wowner->id || |
| 6295 | lowner->s_dev != wowner->s_dev) |
| 6296 | return 0; |
| 6297 | |
| 6298 | /* Make sure it's for the right inode */ |
| 6299 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6300 | return 0; |
| 6301 | |
| 6302 | waiter->notified = true; |
| 6303 | |
| 6304 | /* override "private" so we can use default_wake_function */ |
| 6305 | wait->private = waiter->task; |
| 6306 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6307 | wait->private = waiter; |
| 6308 | return ret; |
| 6309 | } |
| 6310 | |
| 6311 | static int |
| 6312 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6313 | { |
| 6314 | int status = -ERESTARTSYS; |
| 6315 | unsigned long flags; |
| 6316 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6317 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6318 | struct nfs_client *clp = server->nfs_client; |
| 6319 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6320 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6321 | .id = lsp->ls_seqid.owner_id, |
| 6322 | .s_dev = server->s_dev }; |
| 6323 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6324 | .inode = state->inode, |
| 6325 | .owner = &owner, |
| 6326 | .notified = false }; |
| 6327 | wait_queue_t wait; |
| 6328 | |
| 6329 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6330 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6331 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6332 | |
| 6333 | init_wait(&wait); |
| 6334 | wait.private = &waiter; |
| 6335 | wait.func = nfs4_wake_lock_waiter; |
| 6336 | add_wait_queue(q, &wait); |
| 6337 | |
| 6338 | while(!signalled()) { |
| 6339 | status = nfs4_proc_setlk(state, cmd, request); |
| 6340 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6341 | break; |
| 6342 | |
| 6343 | status = -ERESTARTSYS; |
| 6344 | spin_lock_irqsave(&q->lock, flags); |
| 6345 | if (waiter.notified) { |
| 6346 | spin_unlock_irqrestore(&q->lock, flags); |
| 6347 | continue; |
| 6348 | } |
| 6349 | set_current_state(TASK_INTERRUPTIBLE); |
| 6350 | spin_unlock_irqrestore(&q->lock, flags); |
| 6351 | |
| 6352 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6353 | } |
| 6354 | |
| 6355 | finish_wait(q, &wait); |
| 6356 | return status; |
| 6357 | } |
| 6358 | #else /* !CONFIG_NFS_V4_1 */ |
| 6359 | static inline int |
| 6360 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6361 | { |
| 6362 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6363 | } |
| 6364 | #endif |
| 6365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | static int |
| 6367 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6368 | { |
| 6369 | struct nfs_open_context *ctx; |
| 6370 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6371 | int status; |
| 6372 | |
| 6373 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6374 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | state = ctx->state; |
| 6376 | |
| 6377 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6378 | return -EINVAL; |
| 6379 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6380 | if (IS_GETLK(cmd)) { |
| 6381 | if (state != NULL) |
| 6382 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6383 | return 0; |
| 6384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | |
| 6386 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6387 | return -EINVAL; |
| 6388 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6389 | if (request->fl_type == F_UNLCK) { |
| 6390 | if (state != NULL) |
| 6391 | return nfs4_proc_unlck(state, cmd, request); |
| 6392 | return 0; |
| 6393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6394 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6395 | if (state == NULL) |
| 6396 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6397 | |
| 6398 | if ((request->fl_flags & FL_POSIX) && |
| 6399 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6400 | return -ENOLCK; |
| 6401 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6402 | /* |
| 6403 | * Don't rely on the VFS having checked the file open mode, |
| 6404 | * since it won't do this for flock() locks. |
| 6405 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6406 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6407 | case F_RDLCK: |
| 6408 | if (!(filp->f_mode & FMODE_READ)) |
| 6409 | return -EBADF; |
| 6410 | break; |
| 6411 | case F_WRLCK: |
| 6412 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6413 | return -EBADF; |
| 6414 | } |
| 6415 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6416 | status = nfs4_set_lock_state(state, request); |
| 6417 | if (status != 0) |
| 6418 | return status; |
| 6419 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6420 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6421 | } |
| 6422 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6423 | 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] | 6424 | { |
| 6425 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6426 | int err; |
| 6427 | |
| 6428 | err = nfs4_set_lock_state(state, fl); |
| 6429 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6430 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6431 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6432 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6433 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6434 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6435 | struct nfs_release_lockowner_data { |
| 6436 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6437 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6438 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6439 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6440 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6441 | }; |
| 6442 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6443 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6444 | { |
| 6445 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6446 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6447 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6448 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6449 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6450 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6454 | { |
| 6455 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6456 | struct nfs_server *server = data->server; |
| 6457 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6458 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6459 | |
| 6460 | switch (task->tk_status) { |
| 6461 | case 0: |
| 6462 | renew_lease(server, data->timestamp); |
| 6463 | break; |
| 6464 | case -NFS4ERR_STALE_CLIENTID: |
| 6465 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6466 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6467 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6468 | case -NFS4ERR_LEASE_MOVED: |
| 6469 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6470 | if (nfs4_async_handle_error(task, server, |
| 6471 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6472 | rpc_restart_call_prepare(task); |
| 6473 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6474 | } |
| 6475 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6476 | static void nfs4_release_lockowner_release(void *calldata) |
| 6477 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6478 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6479 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6480 | kfree(calldata); |
| 6481 | } |
| 6482 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6483 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6484 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6485 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6486 | .rpc_release = nfs4_release_lockowner_release, |
| 6487 | }; |
| 6488 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6489 | static void |
| 6490 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6491 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6492 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6493 | struct rpc_message msg = { |
| 6494 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6495 | }; |
| 6496 | |
| 6497 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6498 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6499 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6500 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6501 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6502 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6503 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6504 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6505 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6506 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6507 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6508 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6509 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6510 | msg.rpc_resp = &data->res; |
| 6511 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6512 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6513 | } |
| 6514 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6515 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6516 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6517 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6518 | struct dentry *unused, struct inode *inode, |
| 6519 | const char *key, const void *buf, |
| 6520 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6521 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6522 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6525 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6526 | struct dentry *unused, struct inode *inode, |
| 6527 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6528 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6529 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6532 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6533 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6534 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6535 | } |
| 6536 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6537 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6538 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6539 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6540 | struct dentry *unused, struct inode *inode, |
| 6541 | const char *key, const void *buf, |
| 6542 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6543 | { |
| 6544 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6545 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6546 | |
| 6547 | return -EOPNOTSUPP; |
| 6548 | } |
| 6549 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6550 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6551 | struct dentry *unused, struct inode *inode, |
| 6552 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6553 | { |
| 6554 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6555 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6556 | return -EOPNOTSUPP; |
| 6557 | } |
| 6558 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6559 | static ssize_t |
| 6560 | 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] | 6561 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6562 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6563 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6564 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6565 | len = security_inode_listsecurity(inode, list, list_len); |
| 6566 | if (list_len && len > list_len) |
| 6567 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6568 | } |
| 6569 | return len; |
| 6570 | } |
| 6571 | |
| 6572 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6573 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6574 | .get = nfs4_xattr_get_nfs4_label, |
| 6575 | .set = nfs4_xattr_set_nfs4_label, |
| 6576 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6577 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6578 | #else |
| 6579 | |
| 6580 | static ssize_t |
| 6581 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6582 | { |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
| 6586 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6587 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6588 | /* |
| 6589 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6590 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6591 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6592 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6593 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6594 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6595 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6596 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6597 | return; |
| 6598 | |
| 6599 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6600 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6601 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6602 | fattr->nlink = 2; |
| 6603 | } |
| 6604 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6605 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6606 | const struct qstr *name, |
| 6607 | struct nfs4_fs_locations *fs_locations, |
| 6608 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6609 | { |
| 6610 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6611 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6612 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6613 | }; |
| 6614 | struct nfs4_fs_locations_arg args = { |
| 6615 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6616 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6617 | .page = page, |
| 6618 | .bitmask = bitmask, |
| 6619 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6620 | struct nfs4_fs_locations_res res = { |
| 6621 | .fs_locations = fs_locations, |
| 6622 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6623 | struct rpc_message msg = { |
| 6624 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6625 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6626 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6627 | }; |
| 6628 | int status; |
| 6629 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6630 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6631 | |
| 6632 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6633 | * is not supported */ |
| 6634 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6635 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6636 | else |
| 6637 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6638 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6639 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6640 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6641 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6642 | 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] | 6643 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6644 | return status; |
| 6645 | } |
| 6646 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6647 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6648 | const struct qstr *name, |
| 6649 | struct nfs4_fs_locations *fs_locations, |
| 6650 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6651 | { |
| 6652 | struct nfs4_exception exception = { }; |
| 6653 | int err; |
| 6654 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6655 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6656 | fs_locations, page); |
| 6657 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6658 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6659 | &exception); |
| 6660 | } while (exception.retry); |
| 6661 | return err; |
| 6662 | } |
| 6663 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6664 | /* |
| 6665 | * This operation also signals the server that this client is |
| 6666 | * performing migration recovery. The server can stop returning |
| 6667 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6668 | * appended to this compound to identify the client ID which is |
| 6669 | * performing recovery. |
| 6670 | */ |
| 6671 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6672 | struct nfs4_fs_locations *locations, |
| 6673 | struct page *page, struct rpc_cred *cred) |
| 6674 | { |
| 6675 | struct nfs_server *server = NFS_SERVER(inode); |
| 6676 | struct rpc_clnt *clnt = server->client; |
| 6677 | u32 bitmask[2] = { |
| 6678 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6679 | }; |
| 6680 | struct nfs4_fs_locations_arg args = { |
| 6681 | .clientid = server->nfs_client->cl_clientid, |
| 6682 | .fh = NFS_FH(inode), |
| 6683 | .page = page, |
| 6684 | .bitmask = bitmask, |
| 6685 | .migration = 1, /* skip LOOKUP */ |
| 6686 | .renew = 1, /* append RENEW */ |
| 6687 | }; |
| 6688 | struct nfs4_fs_locations_res res = { |
| 6689 | .fs_locations = locations, |
| 6690 | .migration = 1, |
| 6691 | .renew = 1, |
| 6692 | }; |
| 6693 | struct rpc_message msg = { |
| 6694 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6695 | .rpc_argp = &args, |
| 6696 | .rpc_resp = &res, |
| 6697 | .rpc_cred = cred, |
| 6698 | }; |
| 6699 | unsigned long now = jiffies; |
| 6700 | int status; |
| 6701 | |
| 6702 | nfs_fattr_init(&locations->fattr); |
| 6703 | locations->server = server; |
| 6704 | locations->nlocations = 0; |
| 6705 | |
| 6706 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6707 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6708 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6709 | &args.seq_args, &res.seq_res); |
| 6710 | if (status) |
| 6711 | return status; |
| 6712 | |
| 6713 | renew_lease(server, now); |
| 6714 | return 0; |
| 6715 | } |
| 6716 | |
| 6717 | #ifdef CONFIG_NFS_V4_1 |
| 6718 | |
| 6719 | /* |
| 6720 | * This operation also signals the server that this client is |
| 6721 | * performing migration recovery. The server can stop asserting |
| 6722 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6723 | * performing this operation is identified in the SEQUENCE |
| 6724 | * operation in this compound. |
| 6725 | * |
| 6726 | * When the client supports GETATTR(fs_locations_info), it can |
| 6727 | * be plumbed in here. |
| 6728 | */ |
| 6729 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6730 | struct nfs4_fs_locations *locations, |
| 6731 | struct page *page, struct rpc_cred *cred) |
| 6732 | { |
| 6733 | struct nfs_server *server = NFS_SERVER(inode); |
| 6734 | struct rpc_clnt *clnt = server->client; |
| 6735 | u32 bitmask[2] = { |
| 6736 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6737 | }; |
| 6738 | struct nfs4_fs_locations_arg args = { |
| 6739 | .fh = NFS_FH(inode), |
| 6740 | .page = page, |
| 6741 | .bitmask = bitmask, |
| 6742 | .migration = 1, /* skip LOOKUP */ |
| 6743 | }; |
| 6744 | struct nfs4_fs_locations_res res = { |
| 6745 | .fs_locations = locations, |
| 6746 | .migration = 1, |
| 6747 | }; |
| 6748 | struct rpc_message msg = { |
| 6749 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6750 | .rpc_argp = &args, |
| 6751 | .rpc_resp = &res, |
| 6752 | .rpc_cred = cred, |
| 6753 | }; |
| 6754 | int status; |
| 6755 | |
| 6756 | nfs_fattr_init(&locations->fattr); |
| 6757 | locations->server = server; |
| 6758 | locations->nlocations = 0; |
| 6759 | |
| 6760 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6761 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6762 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6763 | &args.seq_args, &res.seq_res); |
| 6764 | if (status == NFS4_OK && |
| 6765 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6766 | status = -NFS4ERR_LEASE_MOVED; |
| 6767 | return status; |
| 6768 | } |
| 6769 | |
| 6770 | #endif /* CONFIG_NFS_V4_1 */ |
| 6771 | |
| 6772 | /** |
| 6773 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6774 | * @inode: inode on FSID that is migrating |
| 6775 | * @locations: result of query |
| 6776 | * @page: buffer |
| 6777 | * @cred: credential to use for this operation |
| 6778 | * |
| 6779 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6780 | * operation failed, or a negative errno if a local error occurred. |
| 6781 | * |
| 6782 | * On success, "locations" is filled in, but if the server has |
| 6783 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6784 | * asserted. |
| 6785 | * |
| 6786 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6787 | * from this client that require migration recovery. |
| 6788 | */ |
| 6789 | int nfs4_proc_get_locations(struct inode *inode, |
| 6790 | struct nfs4_fs_locations *locations, |
| 6791 | struct page *page, struct rpc_cred *cred) |
| 6792 | { |
| 6793 | struct nfs_server *server = NFS_SERVER(inode); |
| 6794 | struct nfs_client *clp = server->nfs_client; |
| 6795 | const struct nfs4_mig_recovery_ops *ops = |
| 6796 | clp->cl_mvops->mig_recovery_ops; |
| 6797 | struct nfs4_exception exception = { }; |
| 6798 | int status; |
| 6799 | |
| 6800 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6801 | (unsigned long long)server->fsid.major, |
| 6802 | (unsigned long long)server->fsid.minor, |
| 6803 | clp->cl_hostname); |
| 6804 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6805 | |
| 6806 | do { |
| 6807 | status = ops->get_locations(inode, locations, page, cred); |
| 6808 | if (status != -NFS4ERR_DELAY) |
| 6809 | break; |
| 6810 | nfs4_handle_exception(server, status, &exception); |
| 6811 | } while (exception.retry); |
| 6812 | return status; |
| 6813 | } |
| 6814 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6815 | /* |
| 6816 | * This operation also signals the server that this client is |
| 6817 | * performing "lease moved" recovery. The server can stop |
| 6818 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6819 | * is appended to this compound to identify the client ID which is |
| 6820 | * performing recovery. |
| 6821 | */ |
| 6822 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6823 | { |
| 6824 | struct nfs_server *server = NFS_SERVER(inode); |
| 6825 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6826 | struct rpc_clnt *clnt = server->client; |
| 6827 | struct nfs4_fsid_present_arg args = { |
| 6828 | .fh = NFS_FH(inode), |
| 6829 | .clientid = clp->cl_clientid, |
| 6830 | .renew = 1, /* append RENEW */ |
| 6831 | }; |
| 6832 | struct nfs4_fsid_present_res res = { |
| 6833 | .renew = 1, |
| 6834 | }; |
| 6835 | struct rpc_message msg = { |
| 6836 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6837 | .rpc_argp = &args, |
| 6838 | .rpc_resp = &res, |
| 6839 | .rpc_cred = cred, |
| 6840 | }; |
| 6841 | unsigned long now = jiffies; |
| 6842 | int status; |
| 6843 | |
| 6844 | res.fh = nfs_alloc_fhandle(); |
| 6845 | if (res.fh == NULL) |
| 6846 | return -ENOMEM; |
| 6847 | |
| 6848 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6849 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6850 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6851 | &args.seq_args, &res.seq_res); |
| 6852 | nfs_free_fhandle(res.fh); |
| 6853 | if (status) |
| 6854 | return status; |
| 6855 | |
| 6856 | do_renew_lease(clp, now); |
| 6857 | return 0; |
| 6858 | } |
| 6859 | |
| 6860 | #ifdef CONFIG_NFS_V4_1 |
| 6861 | |
| 6862 | /* |
| 6863 | * This operation also signals the server that this client is |
| 6864 | * performing "lease moved" recovery. The server can stop asserting |
| 6865 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6866 | * this operation is identified in the SEQUENCE operation in this |
| 6867 | * compound. |
| 6868 | */ |
| 6869 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6870 | { |
| 6871 | struct nfs_server *server = NFS_SERVER(inode); |
| 6872 | struct rpc_clnt *clnt = server->client; |
| 6873 | struct nfs4_fsid_present_arg args = { |
| 6874 | .fh = NFS_FH(inode), |
| 6875 | }; |
| 6876 | struct nfs4_fsid_present_res res = { |
| 6877 | }; |
| 6878 | struct rpc_message msg = { |
| 6879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6880 | .rpc_argp = &args, |
| 6881 | .rpc_resp = &res, |
| 6882 | .rpc_cred = cred, |
| 6883 | }; |
| 6884 | int status; |
| 6885 | |
| 6886 | res.fh = nfs_alloc_fhandle(); |
| 6887 | if (res.fh == NULL) |
| 6888 | return -ENOMEM; |
| 6889 | |
| 6890 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6891 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6892 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6893 | &args.seq_args, &res.seq_res); |
| 6894 | nfs_free_fhandle(res.fh); |
| 6895 | if (status == NFS4_OK && |
| 6896 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6897 | status = -NFS4ERR_LEASE_MOVED; |
| 6898 | return status; |
| 6899 | } |
| 6900 | |
| 6901 | #endif /* CONFIG_NFS_V4_1 */ |
| 6902 | |
| 6903 | /** |
| 6904 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6905 | * @inode: inode on FSID to check |
| 6906 | * @cred: credential to use for this operation |
| 6907 | * |
| 6908 | * Server indicates whether the FSID is present, moved, or not |
| 6909 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6910 | * condition for this client ID. |
| 6911 | * |
| 6912 | * Returns NFS4_OK if the FSID is present on this server, |
| 6913 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6914 | * NFS4ERR code if some error occurred on the server, or a |
| 6915 | * negative errno if a local failure occurred. |
| 6916 | */ |
| 6917 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6918 | { |
| 6919 | struct nfs_server *server = NFS_SERVER(inode); |
| 6920 | struct nfs_client *clp = server->nfs_client; |
| 6921 | const struct nfs4_mig_recovery_ops *ops = |
| 6922 | clp->cl_mvops->mig_recovery_ops; |
| 6923 | struct nfs4_exception exception = { }; |
| 6924 | int status; |
| 6925 | |
| 6926 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6927 | (unsigned long long)server->fsid.major, |
| 6928 | (unsigned long long)server->fsid.minor, |
| 6929 | clp->cl_hostname); |
| 6930 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6931 | |
| 6932 | do { |
| 6933 | status = ops->fsid_present(inode, cred); |
| 6934 | if (status != -NFS4ERR_DELAY) |
| 6935 | break; |
| 6936 | nfs4_handle_exception(server, status, &exception); |
| 6937 | } while (exception.retry); |
| 6938 | return status; |
| 6939 | } |
| 6940 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6941 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6942 | * If 'use_integrity' is true and the state managment nfs_client |
| 6943 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6944 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6945 | * Considerations sections. Otherwise, just use the user cred with the |
| 6946 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6947 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6948 | 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] | 6949 | { |
| 6950 | int status; |
| 6951 | struct nfs4_secinfo_arg args = { |
| 6952 | .dir_fh = NFS_FH(dir), |
| 6953 | .name = name, |
| 6954 | }; |
| 6955 | struct nfs4_secinfo_res res = { |
| 6956 | .flavors = flavors, |
| 6957 | }; |
| 6958 | struct rpc_message msg = { |
| 6959 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6960 | .rpc_argp = &args, |
| 6961 | .rpc_resp = &res, |
| 6962 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6963 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6964 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6965 | |
| 6966 | if (use_integrity) { |
| 6967 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6968 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 6969 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6970 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6971 | |
| 6972 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 6973 | |
| 6974 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 6975 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 6976 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6977 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 6978 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6979 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6980 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6981 | if (cred) |
| 6982 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6983 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6984 | return status; |
| 6985 | } |
| 6986 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 6987 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 6988 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6989 | { |
| 6990 | struct nfs4_exception exception = { }; |
| 6991 | int err; |
| 6992 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6993 | err = -NFS4ERR_WRONGSEC; |
| 6994 | |
| 6995 | /* try to use integrity protection with machine cred */ |
| 6996 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 6997 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 6998 | |
| 6999 | /* |
| 7000 | * if unable to use integrity protection, or SECINFO with |
| 7001 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7002 | * disallowed by spec, but exists in deployed servers) use |
| 7003 | * the current filesystem's rpc_client and the user cred. |
| 7004 | */ |
| 7005 | if (err == -NFS4ERR_WRONGSEC) |
| 7006 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7007 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7008 | trace_nfs4_secinfo(dir, name, err); |
| 7009 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7010 | &exception); |
| 7011 | } while (exception.retry); |
| 7012 | return err; |
| 7013 | } |
| 7014 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7015 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7016 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7017 | * Check the exchange flags returned by the server for invalid flags, having |
| 7018 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7019 | * DS flags set. |
| 7020 | */ |
| 7021 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7022 | { |
| 7023 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7024 | goto out_inval; |
| 7025 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7026 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7027 | goto out_inval; |
| 7028 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7029 | goto out_inval; |
| 7030 | return NFS_OK; |
| 7031 | out_inval: |
| 7032 | return -NFS4ERR_INVAL; |
| 7033 | } |
| 7034 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7035 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7036 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7037 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7038 | { |
| 7039 | if (a->server_scope_sz == b->server_scope_sz && |
| 7040 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7041 | return true; |
| 7042 | |
| 7043 | return false; |
| 7044 | } |
| 7045 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7046 | static void |
| 7047 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7048 | { |
| 7049 | } |
| 7050 | |
| 7051 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7052 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7053 | }; |
| 7054 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7055 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7056 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7057 | * |
| 7058 | * The 4.1 client currently uses the same TCP connection for the |
| 7059 | * fore and backchannel. |
| 7060 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7061 | static |
| 7062 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7063 | struct rpc_xprt *xprt, |
| 7064 | struct nfs_client *clp, |
| 7065 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7066 | { |
| 7067 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7068 | struct nfs41_bind_conn_to_session_args args = { |
| 7069 | .client = clp, |
| 7070 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7071 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7072 | struct nfs41_bind_conn_to_session_res res; |
| 7073 | struct rpc_message msg = { |
| 7074 | .rpc_proc = |
| 7075 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7076 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7077 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7078 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7079 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7080 | struct rpc_task_setup task_setup_data = { |
| 7081 | .rpc_client = clnt, |
| 7082 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7083 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7084 | .rpc_message = &msg, |
| 7085 | .flags = RPC_TASK_TIMEOUT, |
| 7086 | }; |
| 7087 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7088 | |
| 7089 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7090 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7091 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7092 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7093 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7094 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7095 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7096 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7097 | args.dir = NFS4_CDFC4_FORE; |
| 7098 | |
| 7099 | task = rpc_run_task(&task_setup_data); |
| 7100 | if (!IS_ERR(task)) { |
| 7101 | status = task->tk_status; |
| 7102 | rpc_put_task(task); |
| 7103 | } else |
| 7104 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7105 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7106 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7107 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7108 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7109 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7110 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7111 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7112 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7113 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7114 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7115 | __func__); |
| 7116 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7117 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7118 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7119 | 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] | 7120 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7121 | __func__); |
| 7122 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7123 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7124 | } |
| 7125 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7126 | out: |
| 7127 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7128 | return status; |
| 7129 | } |
| 7130 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7131 | struct rpc_bind_conn_calldata { |
| 7132 | struct nfs_client *clp; |
| 7133 | struct rpc_cred *cred; |
| 7134 | }; |
| 7135 | |
| 7136 | static int |
| 7137 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7138 | struct rpc_xprt *xprt, |
| 7139 | void *calldata) |
| 7140 | { |
| 7141 | struct rpc_bind_conn_calldata *p = calldata; |
| 7142 | |
| 7143 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7144 | } |
| 7145 | |
| 7146 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7147 | { |
| 7148 | struct rpc_bind_conn_calldata data = { |
| 7149 | .clp = clp, |
| 7150 | .cred = cred, |
| 7151 | }; |
| 7152 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7153 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7154 | } |
| 7155 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7156 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7157 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7158 | * 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] | 7159 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7160 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7161 | .how = SP4_MACH_CRED, |
| 7162 | .enforce.u.words = { |
| 7163 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7164 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7165 | 1 << (OP_CREATE_SESSION - 32) | |
| 7166 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7167 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7168 | }, |
| 7169 | .allow.u.words = { |
| 7170 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7171 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7172 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7173 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7174 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7175 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7176 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7177 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7178 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7179 | 1 << (OP_FREE_STATEID - 32) | |
| 7180 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7181 | } |
| 7182 | }; |
| 7183 | |
| 7184 | /* |
| 7185 | * Select the state protection mode for client `clp' given the server results |
| 7186 | * from exchange_id in `sp'. |
| 7187 | * |
| 7188 | * Returns 0 on success, negative errno otherwise. |
| 7189 | */ |
| 7190 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7191 | struct nfs41_state_protection *sp) |
| 7192 | { |
| 7193 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7194 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7195 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7196 | 1 << (OP_CREATE_SESSION - 32) | |
| 7197 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7198 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7199 | }; |
| 7200 | unsigned int i; |
| 7201 | |
| 7202 | if (sp->how == SP4_MACH_CRED) { |
| 7203 | /* Print state protect result */ |
| 7204 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7205 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7206 | if (test_bit(i, sp->enforce.u.longs)) |
| 7207 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7208 | if (test_bit(i, sp->allow.u.longs)) |
| 7209 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7210 | } |
| 7211 | |
| 7212 | /* make sure nothing is on enforce list that isn't supported */ |
| 7213 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7214 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7215 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7216 | return -EINVAL; |
| 7217 | } |
| 7218 | } |
| 7219 | |
| 7220 | /* |
| 7221 | * Minimal mode - state operations are allowed to use machine |
| 7222 | * credential. Note this already happens by default, so the |
| 7223 | * client doesn't have to do anything more than the negotiation. |
| 7224 | * |
| 7225 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7226 | * we're already using the machine cred for exchange_id |
| 7227 | * and will never use a different cred. |
| 7228 | */ |
| 7229 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7230 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7231 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7232 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7233 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7234 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7235 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7236 | } else { |
| 7237 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7238 | return -EINVAL; |
| 7239 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7240 | |
| 7241 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7242 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7243 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7244 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7245 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7246 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7247 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7248 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7249 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7250 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7251 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7252 | &clp->cl_sp4_flags); |
| 7253 | } |
| 7254 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7255 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7256 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7257 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7258 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7259 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7260 | |
| 7261 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7262 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7263 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7264 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7265 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7266 | |
| 7267 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7268 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7269 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7270 | } |
| 7271 | |
| 7272 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7273 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7274 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7275 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7276 | } |
| 7277 | |
| 7278 | return 0; |
| 7279 | } |
| 7280 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7281 | struct nfs41_exchange_id_data { |
| 7282 | struct nfs41_exchange_id_res res; |
| 7283 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7284 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7285 | int rpc_status; |
| 7286 | }; |
| 7287 | |
| 7288 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7289 | { |
| 7290 | struct nfs41_exchange_id_data *cdata = |
| 7291 | (struct nfs41_exchange_id_data *)data; |
| 7292 | struct nfs_client *clp = cdata->args.client; |
| 7293 | int status = task->tk_status; |
| 7294 | |
| 7295 | trace_nfs4_exchange_id(clp, status); |
| 7296 | |
| 7297 | if (status == 0) |
| 7298 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7299 | |
| 7300 | if (cdata->xprt && status == 0) { |
| 7301 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7302 | cdata->xprt); |
| 7303 | goto out; |
| 7304 | } |
| 7305 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7306 | if (status == 0) |
| 7307 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7308 | |
| 7309 | if (status == 0) { |
| 7310 | clp->cl_clientid = cdata->res.clientid; |
| 7311 | clp->cl_exchange_flags = cdata->res.flags; |
| 7312 | /* Client ID is not confirmed */ |
| 7313 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7314 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7315 | &clp->cl_session->session_state); |
| 7316 | clp->cl_seqid = cdata->res.seqid; |
| 7317 | } |
| 7318 | |
| 7319 | kfree(clp->cl_serverowner); |
| 7320 | clp->cl_serverowner = cdata->res.server_owner; |
| 7321 | cdata->res.server_owner = NULL; |
| 7322 | |
| 7323 | /* use the most recent implementation id */ |
| 7324 | kfree(clp->cl_implid); |
| 7325 | clp->cl_implid = cdata->res.impl_id; |
| 7326 | cdata->res.impl_id = NULL; |
| 7327 | |
| 7328 | if (clp->cl_serverscope != NULL && |
| 7329 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7330 | cdata->res.server_scope)) { |
| 7331 | dprintk("%s: server_scope mismatch detected\n", |
| 7332 | __func__); |
| 7333 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7334 | kfree(clp->cl_serverscope); |
| 7335 | clp->cl_serverscope = NULL; |
| 7336 | } |
| 7337 | |
| 7338 | if (clp->cl_serverscope == NULL) { |
| 7339 | clp->cl_serverscope = cdata->res.server_scope; |
| 7340 | cdata->res.server_scope = NULL; |
| 7341 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7342 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7343 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7344 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7345 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7346 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7347 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7348 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7349 | } |
| 7350 | |
| 7351 | static void nfs4_exchange_id_release(void *data) |
| 7352 | { |
| 7353 | struct nfs41_exchange_id_data *cdata = |
| 7354 | (struct nfs41_exchange_id_data *)data; |
| 7355 | |
| 7356 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7357 | if (cdata->xprt) { |
| 7358 | xprt_put(cdata->xprt); |
| 7359 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7360 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7361 | kfree(cdata->res.impl_id); |
| 7362 | kfree(cdata->res.server_scope); |
| 7363 | kfree(cdata->res.server_owner); |
| 7364 | kfree(cdata); |
| 7365 | } |
| 7366 | |
| 7367 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7368 | .rpc_call_done = nfs4_exchange_id_done, |
| 7369 | .rpc_release = nfs4_exchange_id_release, |
| 7370 | }; |
| 7371 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7372 | /* |
| 7373 | * _nfs4_proc_exchange_id() |
| 7374 | * |
| 7375 | * Wrapper for EXCHANGE_ID operation. |
| 7376 | */ |
| 7377 | 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] | 7378 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7379 | { |
| 7380 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7381 | struct rpc_message msg = { |
| 7382 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7383 | .rpc_cred = cred, |
| 7384 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7385 | struct rpc_task_setup task_setup_data = { |
| 7386 | .rpc_client = clp->cl_rpcclient, |
| 7387 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7388 | .rpc_message = &msg, |
| 7389 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7390 | }; |
| 7391 | struct nfs41_exchange_id_data *calldata; |
| 7392 | struct rpc_task *task; |
| 7393 | int status = -EIO; |
| 7394 | |
| 7395 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7396 | goto out; |
| 7397 | |
| 7398 | status = -ENOMEM; |
| 7399 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7400 | if (!calldata) |
| 7401 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7402 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7403 | if (!xprt) |
| 7404 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7405 | |
| 7406 | status = nfs4_init_uniform_client_string(clp); |
| 7407 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7408 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7409 | |
| 7410 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7411 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7412 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7413 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7414 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7415 | GFP_NOFS); |
| 7416 | status = -ENOMEM; |
| 7417 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7418 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7419 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7420 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7421 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7422 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7423 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7424 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7425 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7426 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7427 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7428 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7429 | switch (sp4_how) { |
| 7430 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7431 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7432 | break; |
| 7433 | |
| 7434 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7435 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7436 | break; |
| 7437 | |
| 7438 | default: |
| 7439 | /* unsupported! */ |
| 7440 | WARN_ON_ONCE(1); |
| 7441 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7442 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7443 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7444 | if (xprt) { |
| 7445 | calldata->xprt = xprt; |
| 7446 | task_setup_data.rpc_xprt = xprt; |
| 7447 | task_setup_data.flags = |
| 7448 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7449 | calldata->args.verifier = &clp->cl_confirm; |
| 7450 | } else { |
| 7451 | calldata->args.verifier = &verifier; |
| 7452 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7453 | calldata->args.client = clp; |
| 7454 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7455 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7456 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7457 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7458 | #else |
| 7459 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7460 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7461 | #endif |
| 7462 | msg.rpc_argp = &calldata->args; |
| 7463 | msg.rpc_resp = &calldata->res; |
| 7464 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7465 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7466 | task = rpc_run_task(&task_setup_data); |
| 7467 | if (IS_ERR(task)) { |
| 7468 | status = PTR_ERR(task); |
| 7469 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7470 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7471 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7472 | if (!xprt) { |
| 7473 | status = rpc_wait_for_completion_task(task); |
| 7474 | if (!status) |
| 7475 | status = calldata->rpc_status; |
| 7476 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7477 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7478 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7479 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7480 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7481 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7482 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7483 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7484 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7485 | clp->cl_implid->date.seconds, |
| 7486 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7487 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7488 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7489 | |
| 7490 | out_impl_id: |
| 7491 | kfree(calldata->res.impl_id); |
| 7492 | out_server_scope: |
| 7493 | kfree(calldata->res.server_scope); |
| 7494 | out_server_owner: |
| 7495 | kfree(calldata->res.server_owner); |
| 7496 | out_calldata: |
| 7497 | kfree(calldata); |
| 7498 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7499 | } |
| 7500 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7501 | /* |
| 7502 | * nfs4_proc_exchange_id() |
| 7503 | * |
| 7504 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7505 | * |
| 7506 | * Since the clientid has expired, all compounds using sessions |
| 7507 | * associated with the stale clientid will be returning |
| 7508 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7509 | * be in some phase of session reset. |
| 7510 | * |
| 7511 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7512 | */ |
| 7513 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7514 | { |
| 7515 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7516 | int status; |
| 7517 | |
| 7518 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7519 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7520 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7521 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7522 | if (!status) |
| 7523 | return 0; |
| 7524 | } |
| 7525 | |
| 7526 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7527 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7528 | } |
| 7529 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7530 | /** |
| 7531 | * nfs4_test_session_trunk |
| 7532 | * |
| 7533 | * This is an add_xprt_test() test function called from |
| 7534 | * rpc_clnt_setup_test_and_add_xprt. |
| 7535 | * |
| 7536 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7537 | * and is dereferrenced in nfs4_exchange_id_release |
| 7538 | * |
| 7539 | * Upon success, add the new transport to the rpc_clnt |
| 7540 | * |
| 7541 | * @clnt: struct rpc_clnt to get new transport |
| 7542 | * @xprt: the rpc_xprt to test |
| 7543 | * @data: call data for _nfs4_proc_exchange_id. |
| 7544 | */ |
| 7545 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7546 | void *data) |
| 7547 | { |
| 7548 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7549 | u32 sp4_how; |
| 7550 | |
| 7551 | dprintk("--> %s try %s\n", __func__, |
| 7552 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7553 | |
| 7554 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7555 | |
| 7556 | /* Test connection for session trunking. Async exchange_id call */ |
| 7557 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7558 | } |
| 7559 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7560 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7561 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7562 | struct rpc_cred *cred) |
| 7563 | { |
| 7564 | struct rpc_message msg = { |
| 7565 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7566 | .rpc_argp = clp, |
| 7567 | .rpc_cred = cred, |
| 7568 | }; |
| 7569 | int status; |
| 7570 | |
| 7571 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7572 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7573 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7574 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7575 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7576 | return status; |
| 7577 | } |
| 7578 | |
| 7579 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7580 | struct rpc_cred *cred) |
| 7581 | { |
| 7582 | unsigned int loop; |
| 7583 | int ret; |
| 7584 | |
| 7585 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7586 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7587 | switch (ret) { |
| 7588 | case -NFS4ERR_DELAY: |
| 7589 | case -NFS4ERR_CLIENTID_BUSY: |
| 7590 | ssleep(1); |
| 7591 | break; |
| 7592 | default: |
| 7593 | return ret; |
| 7594 | } |
| 7595 | } |
| 7596 | return 0; |
| 7597 | } |
| 7598 | |
| 7599 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7600 | { |
| 7601 | struct rpc_cred *cred; |
| 7602 | int ret = 0; |
| 7603 | |
| 7604 | if (clp->cl_mvops->minor_version < 1) |
| 7605 | goto out; |
| 7606 | if (clp->cl_exchange_flags == 0) |
| 7607 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7608 | if (clp->cl_preserve_clid) |
| 7609 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7610 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7611 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7612 | if (cred) |
| 7613 | put_rpccred(cred); |
| 7614 | switch (ret) { |
| 7615 | case 0: |
| 7616 | case -NFS4ERR_STALE_CLIENTID: |
| 7617 | clp->cl_exchange_flags = 0; |
| 7618 | } |
| 7619 | out: |
| 7620 | return ret; |
| 7621 | } |
| 7622 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7623 | struct nfs4_get_lease_time_data { |
| 7624 | struct nfs4_get_lease_time_args *args; |
| 7625 | struct nfs4_get_lease_time_res *res; |
| 7626 | struct nfs_client *clp; |
| 7627 | }; |
| 7628 | |
| 7629 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7630 | void *calldata) |
| 7631 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7632 | struct nfs4_get_lease_time_data *data = |
| 7633 | (struct nfs4_get_lease_time_data *)calldata; |
| 7634 | |
| 7635 | dprintk("--> %s\n", __func__); |
| 7636 | /* just setup sequence, do not trigger session recovery |
| 7637 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7638 | nfs41_setup_sequence(data->clp->cl_session, |
| 7639 | &data->args->la_seq_args, |
| 7640 | &data->res->lr_seq_res, |
| 7641 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7642 | dprintk("<-- %s\n", __func__); |
| 7643 | } |
| 7644 | |
| 7645 | /* |
| 7646 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7647 | * from sequence operation or clientid errors. |
| 7648 | */ |
| 7649 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7650 | { |
| 7651 | struct nfs4_get_lease_time_data *data = |
| 7652 | (struct nfs4_get_lease_time_data *)calldata; |
| 7653 | |
| 7654 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7655 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7656 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7657 | switch (task->tk_status) { |
| 7658 | case -NFS4ERR_DELAY: |
| 7659 | case -NFS4ERR_GRACE: |
| 7660 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7661 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7662 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7663 | /* fall through */ |
| 7664 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7665 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7666 | return; |
| 7667 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7668 | dprintk("<-- %s\n", __func__); |
| 7669 | } |
| 7670 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7671 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7672 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7673 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7674 | }; |
| 7675 | |
| 7676 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7677 | { |
| 7678 | struct rpc_task *task; |
| 7679 | struct nfs4_get_lease_time_args args; |
| 7680 | struct nfs4_get_lease_time_res res = { |
| 7681 | .lr_fsinfo = fsinfo, |
| 7682 | }; |
| 7683 | struct nfs4_get_lease_time_data data = { |
| 7684 | .args = &args, |
| 7685 | .res = &res, |
| 7686 | .clp = clp, |
| 7687 | }; |
| 7688 | struct rpc_message msg = { |
| 7689 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7690 | .rpc_argp = &args, |
| 7691 | .rpc_resp = &res, |
| 7692 | }; |
| 7693 | struct rpc_task_setup task_setup = { |
| 7694 | .rpc_client = clp->cl_rpcclient, |
| 7695 | .rpc_message = &msg, |
| 7696 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7697 | .callback_data = &data, |
| 7698 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7699 | }; |
| 7700 | int status; |
| 7701 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7702 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7703 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7704 | dprintk("--> %s\n", __func__); |
| 7705 | task = rpc_run_task(&task_setup); |
| 7706 | |
| 7707 | if (IS_ERR(task)) |
| 7708 | status = PTR_ERR(task); |
| 7709 | else { |
| 7710 | status = task->tk_status; |
| 7711 | rpc_put_task(task); |
| 7712 | } |
| 7713 | dprintk("<-- %s return %d\n", __func__, status); |
| 7714 | |
| 7715 | return status; |
| 7716 | } |
| 7717 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7718 | /* |
| 7719 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7720 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7721 | * use them. |
| 7722 | * |
| 7723 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7724 | * always set csa_cachethis to FALSE because the current implementation |
| 7725 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7726 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7727 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7728 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7729 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7730 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7731 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7732 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7733 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7734 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7735 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7736 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7737 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7738 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7739 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7740 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7741 | |
| 7742 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7743 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7744 | __func__, |
| 7745 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7746 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7747 | |
| 7748 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7749 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7750 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7751 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7752 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7753 | 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] | 7754 | |
| 7755 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7756 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7757 | __func__, |
| 7758 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7759 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7760 | args->bc_attrs.max_reqs); |
| 7761 | } |
| 7762 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7763 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7764 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7765 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7766 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7767 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7768 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7769 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7770 | return -EINVAL; |
| 7771 | /* |
| 7772 | * Our requested max_ops is the minimum we need; we're not |
| 7773 | * prepared to break up compounds into smaller pieces than that. |
| 7774 | * So, no point even trying to continue if the server won't |
| 7775 | * cooperate: |
| 7776 | */ |
| 7777 | if (rcvd->max_ops < sent->max_ops) |
| 7778 | return -EINVAL; |
| 7779 | if (rcvd->max_reqs == 0) |
| 7780 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7781 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7782 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7783 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7784 | } |
| 7785 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7786 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7787 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7788 | { |
| 7789 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7790 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7791 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7792 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7793 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7794 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7795 | return -EINVAL; |
| 7796 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7797 | return -EINVAL; |
| 7798 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7799 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7800 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7801 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7802 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7803 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7804 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7805 | return 0; |
| 7806 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7807 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7808 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7809 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7810 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7811 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7812 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7813 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7814 | if (ret) |
| 7815 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7816 | return nfs4_verify_back_channel_attrs(args, res); |
| 7817 | } |
| 7818 | |
| 7819 | static void nfs4_update_session(struct nfs4_session *session, |
| 7820 | struct nfs41_create_session_res *res) |
| 7821 | { |
| 7822 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7823 | /* Mark client id and session as being confirmed */ |
| 7824 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7825 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7826 | session->flags = res->flags; |
| 7827 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7828 | if (res->flags & SESSION4_BACK_CHAN) |
| 7829 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7830 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7831 | } |
| 7832 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7833 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7834 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7835 | { |
| 7836 | struct nfs4_session *session = clp->cl_session; |
| 7837 | struct nfs41_create_session_args args = { |
| 7838 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7839 | .clientid = clp->cl_clientid, |
| 7840 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7841 | .cb_program = NFS4_CALLBACK, |
| 7842 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7843 | struct nfs41_create_session_res res; |
| 7844 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7845 | struct rpc_message msg = { |
| 7846 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7847 | .rpc_argp = &args, |
| 7848 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7849 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7850 | }; |
| 7851 | int status; |
| 7852 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7853 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7854 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7855 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7856 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7857 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7858 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7859 | switch (status) { |
| 7860 | case -NFS4ERR_STALE_CLIENTID: |
| 7861 | case -NFS4ERR_DELAY: |
| 7862 | case -ETIMEDOUT: |
| 7863 | case -EACCES: |
| 7864 | case -EAGAIN: |
| 7865 | goto out; |
| 7866 | }; |
| 7867 | |
| 7868 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7869 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7870 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7871 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7872 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7873 | if (status) |
| 7874 | goto out; |
| 7875 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7876 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7877 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7878 | return status; |
| 7879 | } |
| 7880 | |
| 7881 | /* |
| 7882 | * Issues a CREATE_SESSION operation to the server. |
| 7883 | * It is the responsibility of the caller to verify the session is |
| 7884 | * expired before calling this routine. |
| 7885 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7886 | 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] | 7887 | { |
| 7888 | int status; |
| 7889 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7890 | struct nfs4_session *session = clp->cl_session; |
| 7891 | |
| 7892 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7893 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7894 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7895 | if (status) |
| 7896 | goto out; |
| 7897 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7898 | /* Init or reset the session slot tables */ |
| 7899 | status = nfs4_setup_session_slot_tables(session); |
| 7900 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7901 | if (status) |
| 7902 | goto out; |
| 7903 | |
| 7904 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7905 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7906 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7907 | out: |
| 7908 | dprintk("<-- %s\n", __func__); |
| 7909 | return status; |
| 7910 | } |
| 7911 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7912 | /* |
| 7913 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7914 | * The caller must serialize access to this routine. |
| 7915 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7916 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7917 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7918 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7919 | struct rpc_message msg = { |
| 7920 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7921 | .rpc_argp = session, |
| 7922 | .rpc_cred = cred, |
| 7923 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7924 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7925 | |
| 7926 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7927 | |
| 7928 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7929 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7930 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7931 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7932 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7933 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7934 | |
| 7935 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7936 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7937 | "Session has been destroyed regardless...\n", status); |
| 7938 | |
| 7939 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7940 | return status; |
| 7941 | } |
| 7942 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7943 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7944 | * Renew the cl_session lease. |
| 7945 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7946 | struct nfs4_sequence_data { |
| 7947 | struct nfs_client *clp; |
| 7948 | struct nfs4_sequence_args args; |
| 7949 | struct nfs4_sequence_res res; |
| 7950 | }; |
| 7951 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7952 | static void nfs41_sequence_release(void *data) |
| 7953 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7954 | struct nfs4_sequence_data *calldata = data; |
| 7955 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7956 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7957 | if (atomic_read(&clp->cl_count) > 1) |
| 7958 | nfs4_schedule_state_renewal(clp); |
| 7959 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7960 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7961 | } |
| 7962 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7963 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7964 | { |
| 7965 | switch(task->tk_status) { |
| 7966 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7967 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 7968 | return -EAGAIN; |
| 7969 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 7970 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7971 | } |
| 7972 | return 0; |
| 7973 | } |
| 7974 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7975 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7976 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7977 | struct nfs4_sequence_data *calldata = data; |
| 7978 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7979 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7980 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 7981 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7982 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7983 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7984 | if (task->tk_status < 0) { |
| 7985 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7986 | if (atomic_read(&clp->cl_count) == 1) |
| 7987 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7988 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7989 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 7990 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7991 | return; |
| 7992 | } |
| 7993 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7994 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7995 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7996 | dprintk("<-- %s\n", __func__); |
| 7997 | } |
| 7998 | |
| 7999 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8000 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8001 | struct nfs4_sequence_data *calldata = data; |
| 8002 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8003 | struct nfs4_sequence_args *args; |
| 8004 | struct nfs4_sequence_res *res; |
| 8005 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8006 | args = task->tk_msg.rpc_argp; |
| 8007 | res = task->tk_msg.rpc_resp; |
| 8008 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8009 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8013 | .rpc_call_done = nfs41_sequence_call_done, |
| 8014 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8015 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8016 | }; |
| 8017 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8018 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8019 | struct rpc_cred *cred, |
| 8020 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8021 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8022 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8023 | struct rpc_message msg = { |
| 8024 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8025 | .rpc_cred = cred, |
| 8026 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8027 | struct rpc_task_setup task_setup_data = { |
| 8028 | .rpc_client = clp->cl_rpcclient, |
| 8029 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8030 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8031 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8032 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8033 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8034 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8035 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8036 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8037 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8038 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8039 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8040 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8041 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8042 | if (is_privileged) |
| 8043 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8044 | msg.rpc_argp = &calldata->args; |
| 8045 | msg.rpc_resp = &calldata->res; |
| 8046 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8047 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8048 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8049 | return rpc_run_task(&task_setup_data); |
| 8050 | } |
| 8051 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8052 | 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] | 8053 | { |
| 8054 | struct rpc_task *task; |
| 8055 | int ret = 0; |
| 8056 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8057 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8058 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8059 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8060 | if (IS_ERR(task)) |
| 8061 | ret = PTR_ERR(task); |
| 8062 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8063 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8064 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8065 | return ret; |
| 8066 | } |
| 8067 | |
| 8068 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8069 | { |
| 8070 | struct rpc_task *task; |
| 8071 | int ret; |
| 8072 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8073 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8074 | if (IS_ERR(task)) { |
| 8075 | ret = PTR_ERR(task); |
| 8076 | goto out; |
| 8077 | } |
| 8078 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8079 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8080 | ret = task->tk_status; |
| 8081 | rpc_put_task(task); |
| 8082 | out: |
| 8083 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8084 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8085 | } |
| 8086 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8087 | struct nfs4_reclaim_complete_data { |
| 8088 | struct nfs_client *clp; |
| 8089 | struct nfs41_reclaim_complete_args arg; |
| 8090 | struct nfs41_reclaim_complete_res res; |
| 8091 | }; |
| 8092 | |
| 8093 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8094 | { |
| 8095 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8096 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8097 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8098 | &calldata->arg.seq_args, |
| 8099 | &calldata->res.seq_res, |
| 8100 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8101 | } |
| 8102 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8103 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8104 | { |
| 8105 | switch(task->tk_status) { |
| 8106 | case 0: |
| 8107 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8108 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8109 | break; |
| 8110 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8111 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8112 | /* fall through */ |
| 8113 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8114 | return -EAGAIN; |
| 8115 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8116 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8117 | } |
| 8118 | return 0; |
| 8119 | } |
| 8120 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8121 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8122 | { |
| 8123 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8124 | struct nfs_client *clp = calldata->clp; |
| 8125 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8126 | |
| 8127 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8128 | if (!nfs41_sequence_done(task, res)) |
| 8129 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8130 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8131 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8132 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8133 | rpc_restart_call_prepare(task); |
| 8134 | return; |
| 8135 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8136 | dprintk("<-- %s\n", __func__); |
| 8137 | } |
| 8138 | |
| 8139 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8140 | { |
| 8141 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8142 | |
| 8143 | kfree(calldata); |
| 8144 | } |
| 8145 | |
| 8146 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8147 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8148 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8149 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8150 | }; |
| 8151 | |
| 8152 | /* |
| 8153 | * Issue a global reclaim complete. |
| 8154 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8155 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8156 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8157 | { |
| 8158 | struct nfs4_reclaim_complete_data *calldata; |
| 8159 | struct rpc_task *task; |
| 8160 | struct rpc_message msg = { |
| 8161 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8162 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8163 | }; |
| 8164 | struct rpc_task_setup task_setup_data = { |
| 8165 | .rpc_client = clp->cl_rpcclient, |
| 8166 | .rpc_message = &msg, |
| 8167 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8168 | .flags = RPC_TASK_ASYNC, |
| 8169 | }; |
| 8170 | int status = -ENOMEM; |
| 8171 | |
| 8172 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8173 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8174 | if (calldata == NULL) |
| 8175 | goto out; |
| 8176 | calldata->clp = clp; |
| 8177 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8178 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8179 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8180 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8181 | msg.rpc_argp = &calldata->arg; |
| 8182 | msg.rpc_resp = &calldata->res; |
| 8183 | task_setup_data.callback_data = calldata; |
| 8184 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8185 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8186 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8187 | goto out; |
| 8188 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8189 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8190 | if (status == 0) |
| 8191 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8192 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8193 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8194 | out: |
| 8195 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8196 | return status; |
| 8197 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8198 | |
| 8199 | static void |
| 8200 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8201 | { |
| 8202 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8203 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8204 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8205 | |
| 8206 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8207 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8208 | &lgp->res.seq_res, task); |
| 8209 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8213 | { |
| 8214 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8215 | |
| 8216 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8217 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8218 | dprintk("<-- %s\n", __func__); |
| 8219 | } |
| 8220 | |
| 8221 | static int |
| 8222 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8223 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8224 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8225 | struct inode *inode = lgp->args.inode; |
| 8226 | struct nfs_server *server = NFS_SERVER(inode); |
| 8227 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8228 | int nfs4err = task->tk_status; |
| 8229 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8230 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8231 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8232 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8233 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8234 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8235 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8236 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8237 | |
| 8238 | /* |
| 8239 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8240 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8241 | * retry go inband. |
| 8242 | */ |
| 8243 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8244 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8245 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8246 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8247 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8248 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8249 | */ |
| 8250 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8251 | status = -EOVERFLOW; |
| 8252 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8253 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8254 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8255 | * (or clients) writing to the same RAID stripe except when |
| 8256 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8257 | * |
| 8258 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8259 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8260 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8261 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8262 | if (lgp->args.minlength == 0) { |
| 8263 | status = -EOVERFLOW; |
| 8264 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8265 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8266 | status = -EBUSY; |
| 8267 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8268 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8269 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8270 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame^] | 8271 | case -NFS4ERR_DELEG_REVOKED: |
| 8272 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8273 | case -NFS4ERR_EXPIRED: |
| 8274 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8275 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8276 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8277 | lo = NFS_I(inode)->layout; |
| 8278 | /* If the open stateid was bad, then recover it. */ |
| 8279 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8280 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8281 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8282 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8283 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame^] | 8284 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8285 | break; |
| 8286 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8287 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8288 | /* |
| 8289 | * Mark the bad layout state as invalid, then retry |
| 8290 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8291 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8292 | spin_unlock(&inode->i_lock); |
| 8293 | pnfs_free_lseg_list(&head); |
| 8294 | status = -EAGAIN; |
| 8295 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8296 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8297 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8298 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8299 | if (!status) { |
| 8300 | if (exception->retry) |
| 8301 | status = -EAGAIN; |
| 8302 | else |
| 8303 | status = err; |
| 8304 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8305 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8306 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8307 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8308 | } |
| 8309 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8310 | static size_t max_response_pages(struct nfs_server *server) |
| 8311 | { |
| 8312 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8313 | return nfs_page_array_len(0, max_resp_sz); |
| 8314 | } |
| 8315 | |
| 8316 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8317 | { |
| 8318 | int i; |
| 8319 | |
| 8320 | if (!pages) |
| 8321 | return; |
| 8322 | |
| 8323 | for (i = 0; i < size; i++) { |
| 8324 | if (!pages[i]) |
| 8325 | break; |
| 8326 | __free_page(pages[i]); |
| 8327 | } |
| 8328 | kfree(pages); |
| 8329 | } |
| 8330 | |
| 8331 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8332 | { |
| 8333 | struct page **pages; |
| 8334 | int i; |
| 8335 | |
| 8336 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8337 | if (!pages) { |
| 8338 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8339 | return NULL; |
| 8340 | } |
| 8341 | |
| 8342 | for (i = 0; i < size; i++) { |
| 8343 | pages[i] = alloc_page(gfp_flags); |
| 8344 | if (!pages[i]) { |
| 8345 | dprintk("%s: failed to allocate page\n", __func__); |
| 8346 | nfs4_free_pages(pages, size); |
| 8347 | return NULL; |
| 8348 | } |
| 8349 | } |
| 8350 | |
| 8351 | return pages; |
| 8352 | } |
| 8353 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8354 | static void nfs4_layoutget_release(void *calldata) |
| 8355 | { |
| 8356 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8357 | struct inode *inode = lgp->args.inode; |
| 8358 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8359 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8360 | |
| 8361 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8362 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8363 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8364 | put_nfs_open_context(lgp->args.ctx); |
| 8365 | kfree(calldata); |
| 8366 | dprintk("<-- %s\n", __func__); |
| 8367 | } |
| 8368 | |
| 8369 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8370 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8371 | .rpc_call_done = nfs4_layoutget_done, |
| 8372 | .rpc_release = nfs4_layoutget_release, |
| 8373 | }; |
| 8374 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8375 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8376 | 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] | 8377 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8378 | struct inode *inode = lgp->args.inode; |
| 8379 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8380 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8381 | struct rpc_task *task; |
| 8382 | struct rpc_message msg = { |
| 8383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8384 | .rpc_argp = &lgp->args, |
| 8385 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8386 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8387 | }; |
| 8388 | struct rpc_task_setup task_setup_data = { |
| 8389 | .rpc_client = server->client, |
| 8390 | .rpc_message = &msg, |
| 8391 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8392 | .callback_data = lgp, |
| 8393 | .flags = RPC_TASK_ASYNC, |
| 8394 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8395 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8396 | struct nfs4_exception exception = { |
| 8397 | .inode = inode, |
| 8398 | .timeout = *timeout, |
| 8399 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8400 | int status = 0; |
| 8401 | |
| 8402 | dprintk("--> %s\n", __func__); |
| 8403 | |
Peng Tao | 4bd5a980 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8404 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8405 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8406 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8407 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8408 | if (!lgp->args.layout.pages) { |
| 8409 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8410 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8411 | } |
| 8412 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8413 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8414 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8415 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8416 | 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] | 8417 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8418 | task = rpc_run_task(&task_setup_data); |
| 8419 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8420 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8421 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8422 | if (status == 0) { |
| 8423 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8424 | *timeout = exception.timeout; |
| 8425 | } |
| 8426 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8427 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8428 | &lgp->args.range, |
| 8429 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8430 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8431 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8432 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8433 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8434 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8435 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8436 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8437 | rpc_put_task(task); |
| 8438 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8439 | if (status) |
| 8440 | return ERR_PTR(status); |
| 8441 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8442 | } |
| 8443 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8444 | static void |
| 8445 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8446 | { |
| 8447 | struct nfs4_layoutreturn *lrp = calldata; |
| 8448 | |
| 8449 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8450 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8451 | &lrp->args.seq_args, |
| 8452 | &lrp->res.seq_res, |
| 8453 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8454 | } |
| 8455 | |
| 8456 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8457 | { |
| 8458 | struct nfs4_layoutreturn *lrp = calldata; |
| 8459 | struct nfs_server *server; |
| 8460 | |
| 8461 | dprintk("--> %s\n", __func__); |
| 8462 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8463 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8464 | return; |
| 8465 | |
| 8466 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8467 | switch (task->tk_status) { |
| 8468 | default: |
| 8469 | task->tk_status = 0; |
| 8470 | case 0: |
| 8471 | break; |
| 8472 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8473 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8474 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8475 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8476 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8477 | return; |
| 8478 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8479 | dprintk("<-- %s\n", __func__); |
| 8480 | } |
| 8481 | |
| 8482 | static void nfs4_layoutreturn_release(void *calldata) |
| 8483 | { |
| 8484 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8485 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8486 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8487 | |
| 8488 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8489 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8490 | if (lrp->res.lrs_present) { |
| 8491 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8492 | &lrp->args.range, |
| 8493 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8494 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8495 | } else |
| 8496 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8497 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8498 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8499 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8500 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8501 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8502 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8503 | kfree(calldata); |
| 8504 | dprintk("<-- %s\n", __func__); |
| 8505 | } |
| 8506 | |
| 8507 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8508 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8509 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8510 | .rpc_release = nfs4_layoutreturn_release, |
| 8511 | }; |
| 8512 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8513 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8514 | { |
| 8515 | struct rpc_task *task; |
| 8516 | struct rpc_message msg = { |
| 8517 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8518 | .rpc_argp = &lrp->args, |
| 8519 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8520 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8521 | }; |
| 8522 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8523 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8524 | .rpc_message = &msg, |
| 8525 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8526 | .callback_data = lrp, |
| 8527 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8528 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8529 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8530 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8531 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8532 | &task_setup_data.rpc_client, &msg); |
| 8533 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8534 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8535 | if (!sync) { |
| 8536 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8537 | if (!lrp->inode) { |
| 8538 | nfs4_layoutreturn_release(lrp); |
| 8539 | return -EAGAIN; |
| 8540 | } |
| 8541 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8542 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8543 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8544 | task = rpc_run_task(&task_setup_data); |
| 8545 | if (IS_ERR(task)) |
| 8546 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8547 | if (sync) |
| 8548 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8549 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8550 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8551 | rpc_put_task(task); |
| 8552 | return status; |
| 8553 | } |
| 8554 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8555 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8556 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8557 | struct pnfs_device *pdev, |
| 8558 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8559 | { |
| 8560 | struct nfs4_getdeviceinfo_args args = { |
| 8561 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8562 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8563 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8564 | }; |
| 8565 | struct nfs4_getdeviceinfo_res res = { |
| 8566 | .pdev = pdev, |
| 8567 | }; |
| 8568 | struct rpc_message msg = { |
| 8569 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8570 | .rpc_argp = &args, |
| 8571 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8572 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8573 | }; |
| 8574 | int status; |
| 8575 | |
| 8576 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8577 | 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] | 8578 | if (res.notification & ~args.notify_types) |
| 8579 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8580 | if (res.notification != args.notify_types) |
| 8581 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8582 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8583 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8584 | |
| 8585 | return status; |
| 8586 | } |
| 8587 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8588 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8589 | struct pnfs_device *pdev, |
| 8590 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8591 | { |
| 8592 | struct nfs4_exception exception = { }; |
| 8593 | int err; |
| 8594 | |
| 8595 | do { |
| 8596 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8597 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8598 | &exception); |
| 8599 | } while (exception.retry); |
| 8600 | return err; |
| 8601 | } |
| 8602 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8603 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8604 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8605 | { |
| 8606 | struct nfs4_layoutcommit_data *data = calldata; |
| 8607 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8608 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8609 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8610 | nfs41_setup_sequence(session, |
| 8611 | &data->args.seq_args, |
| 8612 | &data->res.seq_res, |
| 8613 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8614 | } |
| 8615 | |
| 8616 | static void |
| 8617 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8618 | { |
| 8619 | struct nfs4_layoutcommit_data *data = calldata; |
| 8620 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8621 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8622 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8623 | return; |
| 8624 | |
| 8625 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8626 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8627 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8628 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8629 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8630 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8631 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8632 | break; |
| 8633 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8634 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8635 | rpc_restart_call_prepare(task); |
| 8636 | return; |
| 8637 | } |
| 8638 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8639 | } |
| 8640 | |
| 8641 | static void nfs4_layoutcommit_release(void *calldata) |
| 8642 | { |
| 8643 | struct nfs4_layoutcommit_data *data = calldata; |
| 8644 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8645 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8646 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8647 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8648 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8649 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8650 | kfree(data); |
| 8651 | } |
| 8652 | |
| 8653 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8654 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8655 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8656 | .rpc_release = nfs4_layoutcommit_release, |
| 8657 | }; |
| 8658 | |
| 8659 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8660 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8661 | { |
| 8662 | struct rpc_message msg = { |
| 8663 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8664 | .rpc_argp = &data->args, |
| 8665 | .rpc_resp = &data->res, |
| 8666 | .rpc_cred = data->cred, |
| 8667 | }; |
| 8668 | struct rpc_task_setup task_setup_data = { |
| 8669 | .task = &data->task, |
| 8670 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8671 | .rpc_message = &msg, |
| 8672 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8673 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8674 | }; |
| 8675 | struct rpc_task *task; |
| 8676 | int status = 0; |
| 8677 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8678 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8679 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8680 | data->args.lastbytewritten, |
| 8681 | data->args.inode->i_ino); |
| 8682 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8683 | if (!sync) { |
| 8684 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8685 | if (data->inode == NULL) { |
| 8686 | nfs4_layoutcommit_release(data); |
| 8687 | return -EAGAIN; |
| 8688 | } |
| 8689 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8690 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8691 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8692 | task = rpc_run_task(&task_setup_data); |
| 8693 | if (IS_ERR(task)) |
| 8694 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8695 | if (sync) |
| 8696 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8697 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8698 | dprintk("%s: status %d\n", __func__, status); |
| 8699 | rpc_put_task(task); |
| 8700 | return status; |
| 8701 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8702 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8703 | /** |
| 8704 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8705 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8706 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8707 | static int |
| 8708 | _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] | 8709 | struct nfs_fsinfo *info, |
| 8710 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8711 | { |
| 8712 | struct nfs41_secinfo_no_name_args args = { |
| 8713 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8714 | }; |
| 8715 | struct nfs4_secinfo_res res = { |
| 8716 | .flavors = flavors, |
| 8717 | }; |
| 8718 | struct rpc_message msg = { |
| 8719 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8720 | .rpc_argp = &args, |
| 8721 | .rpc_resp = &res, |
| 8722 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8723 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8724 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8725 | int status; |
| 8726 | |
| 8727 | if (use_integrity) { |
| 8728 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8729 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8730 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8731 | } |
| 8732 | |
| 8733 | dprintk("--> %s\n", __func__); |
| 8734 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8735 | &res.seq_res, 0); |
| 8736 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8737 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8738 | if (cred) |
| 8739 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8740 | |
| 8741 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8742 | } |
| 8743 | |
| 8744 | static int |
| 8745 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8746 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8747 | { |
| 8748 | struct nfs4_exception exception = { }; |
| 8749 | int err; |
| 8750 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8751 | /* first try using integrity protection */ |
| 8752 | err = -NFS4ERR_WRONGSEC; |
| 8753 | |
| 8754 | /* try to use integrity protection with machine cred */ |
| 8755 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8756 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8757 | flavors, true); |
| 8758 | |
| 8759 | /* |
| 8760 | * if unable to use integrity protection, or SECINFO with |
| 8761 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8762 | * disallowed by spec, but exists in deployed servers) use |
| 8763 | * the current filesystem's rpc_client and the user cred. |
| 8764 | */ |
| 8765 | if (err == -NFS4ERR_WRONGSEC) |
| 8766 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8767 | flavors, false); |
| 8768 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8769 | switch (err) { |
| 8770 | case 0: |
| 8771 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8772 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8773 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8774 | default: |
| 8775 | err = nfs4_handle_exception(server, err, &exception); |
| 8776 | } |
| 8777 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8778 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8779 | return err; |
| 8780 | } |
| 8781 | |
| 8782 | static int |
| 8783 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8784 | struct nfs_fsinfo *info) |
| 8785 | { |
| 8786 | int err; |
| 8787 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8788 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8789 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8790 | struct nfs4_secinfo4 *secinfo; |
| 8791 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8792 | |
| 8793 | page = alloc_page(GFP_KERNEL); |
| 8794 | if (!page) { |
| 8795 | err = -ENOMEM; |
| 8796 | goto out; |
| 8797 | } |
| 8798 | |
| 8799 | flavors = page_address(page); |
| 8800 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8801 | |
| 8802 | /* |
| 8803 | * Fall back on "guess and check" method if |
| 8804 | * the server doesn't support SECINFO_NO_NAME |
| 8805 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8806 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8807 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8808 | goto out_freepage; |
| 8809 | } |
| 8810 | if (err) |
| 8811 | goto out_freepage; |
| 8812 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8813 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8814 | secinfo = &flavors->flavors[i]; |
| 8815 | |
| 8816 | switch (secinfo->flavor) { |
| 8817 | case RPC_AUTH_NULL: |
| 8818 | case RPC_AUTH_UNIX: |
| 8819 | case RPC_AUTH_GSS: |
| 8820 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8821 | &secinfo->flavor_info); |
| 8822 | break; |
| 8823 | default: |
| 8824 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8825 | break; |
| 8826 | } |
| 8827 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8828 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8829 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8830 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8831 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8832 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8833 | info, flavor); |
| 8834 | if (!err) |
| 8835 | break; |
| 8836 | } |
| 8837 | } |
| 8838 | |
| 8839 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8840 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8841 | |
| 8842 | out_freepage: |
| 8843 | put_page(page); |
| 8844 | if (err == -EACCES) |
| 8845 | return -EPERM; |
| 8846 | out: |
| 8847 | return err; |
| 8848 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8849 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8850 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8851 | nfs4_stateid *stateid, |
| 8852 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8853 | { |
| 8854 | int status; |
| 8855 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8856 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8857 | }; |
| 8858 | struct nfs41_test_stateid_res res; |
| 8859 | struct rpc_message msg = { |
| 8860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8861 | .rpc_argp = &args, |
| 8862 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8863 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8864 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8865 | struct rpc_clnt *rpc_client = server->client; |
| 8866 | |
| 8867 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8868 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8869 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8870 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8871 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8872 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8873 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8874 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8875 | if (status != NFS_OK) { |
| 8876 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8877 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8878 | } |
| 8879 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8880 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8881 | } |
| 8882 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8883 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8884 | int err, struct nfs4_exception *exception) |
| 8885 | { |
| 8886 | exception->retry = 0; |
| 8887 | switch(err) { |
| 8888 | case -NFS4ERR_DELAY: |
| 8889 | nfs4_handle_exception(server, err, exception); |
| 8890 | break; |
| 8891 | case -NFS4ERR_BADSESSION: |
| 8892 | case -NFS4ERR_BADSLOT: |
| 8893 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8894 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8895 | case -NFS4ERR_DEADSESSION: |
| 8896 | nfs4_do_handle_exception(server, err, exception); |
| 8897 | } |
| 8898 | } |
| 8899 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8900 | /** |
| 8901 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8902 | * |
| 8903 | * @server: server / transport on which to perform the operation |
| 8904 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8905 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8906 | * |
| 8907 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8908 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8909 | * failed or the state ID is not currently valid. |
| 8910 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8911 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8912 | nfs4_stateid *stateid, |
| 8913 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8914 | { |
| 8915 | struct nfs4_exception exception = { }; |
| 8916 | int err; |
| 8917 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8918 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8919 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8920 | } while (exception.retry); |
| 8921 | return err; |
| 8922 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8923 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8924 | struct nfs_free_stateid_data { |
| 8925 | struct nfs_server *server; |
| 8926 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8927 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8928 | }; |
| 8929 | |
| 8930 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8931 | { |
| 8932 | struct nfs_free_stateid_data *data = calldata; |
| 8933 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8934 | &data->args.seq_args, |
| 8935 | &data->res.seq_res, |
| 8936 | task); |
| 8937 | } |
| 8938 | |
| 8939 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8940 | { |
| 8941 | struct nfs_free_stateid_data *data = calldata; |
| 8942 | |
| 8943 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8944 | |
| 8945 | switch (task->tk_status) { |
| 8946 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8947 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8948 | rpc_restart_call_prepare(task); |
| 8949 | } |
| 8950 | } |
| 8951 | |
| 8952 | static void nfs41_free_stateid_release(void *calldata) |
| 8953 | { |
| 8954 | kfree(calldata); |
| 8955 | } |
| 8956 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8957 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8958 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8959 | .rpc_call_done = nfs41_free_stateid_done, |
| 8960 | .rpc_release = nfs41_free_stateid_release, |
| 8961 | }; |
| 8962 | |
| 8963 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 8964 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8965 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8966 | bool privileged) |
| 8967 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8968 | struct rpc_message msg = { |
| 8969 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8970 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8971 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8972 | struct rpc_task_setup task_setup = { |
| 8973 | .rpc_client = server->client, |
| 8974 | .rpc_message = &msg, |
| 8975 | .callback_ops = &nfs41_free_stateid_ops, |
| 8976 | .flags = RPC_TASK_ASYNC, |
| 8977 | }; |
| 8978 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8979 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8980 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8981 | &task_setup.rpc_client, &msg); |
| 8982 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8983 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8984 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 8985 | if (!data) |
| 8986 | return ERR_PTR(-ENOMEM); |
| 8987 | data->server = server; |
| 8988 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 8989 | |
| 8990 | task_setup.callback_data = data; |
| 8991 | |
| 8992 | msg.rpc_argp = &data->args; |
| 8993 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8994 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8995 | if (privileged) |
| 8996 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 8997 | |
| 8998 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8999 | } |
| 9000 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9001 | /** |
| 9002 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9003 | * |
| 9004 | * @server: server / transport on which to perform the operation |
| 9005 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9006 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9007 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9008 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9009 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9010 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9011 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9012 | const nfs4_stateid *stateid, |
| 9013 | struct rpc_cred *cred, |
| 9014 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9015 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9016 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9017 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9018 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9019 | if (IS_ERR(task)) |
| 9020 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9021 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9022 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9023 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9024 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9025 | static void |
| 9026 | 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] | 9027 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9028 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9029 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9030 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9031 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9032 | } |
| 9033 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9034 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9035 | const nfs4_stateid *s2) |
| 9036 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9037 | if (s1->type != s2->type) |
| 9038 | return false; |
| 9039 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9040 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9041 | return false; |
| 9042 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9043 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9044 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9045 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9046 | return true; |
| 9047 | |
| 9048 | return false; |
| 9049 | } |
| 9050 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9051 | #endif /* CONFIG_NFS_V4_1 */ |
| 9052 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9053 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9054 | const nfs4_stateid *s2) |
| 9055 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9056 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9057 | } |
| 9058 | |
| 9059 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9060 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9061 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9062 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9063 | .recover_open = nfs4_open_reclaim, |
| 9064 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9065 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9066 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9067 | }; |
| 9068 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9069 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9070 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9071 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9072 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9073 | .recover_open = nfs4_open_reclaim, |
| 9074 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9075 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9076 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9077 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9078 | }; |
| 9079 | #endif /* CONFIG_NFS_V4_1 */ |
| 9080 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9081 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9082 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9083 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9084 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9085 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9086 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9087 | }; |
| 9088 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9089 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9090 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9091 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9092 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9093 | .recover_open = nfs41_open_expired, |
| 9094 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9095 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9096 | }; |
| 9097 | #endif /* CONFIG_NFS_V4_1 */ |
| 9098 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9099 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9100 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9101 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9102 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9103 | }; |
| 9104 | |
| 9105 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9106 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9107 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9108 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9109 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9110 | }; |
| 9111 | #endif |
| 9112 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9113 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9114 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9115 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9116 | }; |
| 9117 | |
| 9118 | #if defined(CONFIG_NFS_V4_1) |
| 9119 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9120 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9121 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9122 | }; |
| 9123 | #endif /* CONFIG_NFS_V4_1 */ |
| 9124 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9125 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9126 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9127 | .init_caps = NFS_CAP_READDIRPLUS |
| 9128 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9129 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9130 | .init_client = nfs40_init_client, |
| 9131 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9132 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9133 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9134 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9135 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9136 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9137 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9138 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9139 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9140 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9141 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9142 | }; |
| 9143 | |
| 9144 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9145 | static struct nfs_seqid * |
| 9146 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9147 | { |
| 9148 | return NULL; |
| 9149 | } |
| 9150 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9151 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9152 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9153 | .init_caps = NFS_CAP_READDIRPLUS |
| 9154 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9155 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9156 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9157 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9158 | .init_client = nfs41_init_client, |
| 9159 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9160 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9161 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9162 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9163 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9164 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9165 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9166 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9167 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9168 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9169 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9170 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9171 | }; |
| 9172 | #endif |
| 9173 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9174 | #if defined(CONFIG_NFS_V4_2) |
| 9175 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9176 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9177 | .init_caps = NFS_CAP_READDIRPLUS |
| 9178 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9179 | | NFS_CAP_POSIX_LOCK |
| 9180 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9181 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9182 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9183 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9184 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9185 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9186 | | NFS_CAP_LAYOUTSTATS |
| 9187 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9188 | .init_client = nfs41_init_client, |
| 9189 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9190 | .match_stateid = nfs41_match_stateid, |
| 9191 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9192 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9193 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9194 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9195 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9196 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9197 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9198 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9199 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9200 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9201 | }; |
| 9202 | #endif |
| 9203 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9204 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9205 | [0] = &nfs_v4_0_minor_ops, |
| 9206 | #if defined(CONFIG_NFS_V4_1) |
| 9207 | [1] = &nfs_v4_1_minor_ops, |
| 9208 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9209 | #if defined(CONFIG_NFS_V4_2) |
| 9210 | [2] = &nfs_v4_2_minor_ops, |
| 9211 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9212 | }; |
| 9213 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9214 | 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] | 9215 | { |
| 9216 | ssize_t error, error2; |
| 9217 | |
| 9218 | error = generic_listxattr(dentry, list, size); |
| 9219 | if (error < 0) |
| 9220 | return error; |
| 9221 | if (list) { |
| 9222 | list += error; |
| 9223 | size -= error; |
| 9224 | } |
| 9225 | |
| 9226 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9227 | if (error2 < 0) |
| 9228 | return error2; |
| 9229 | return error + error2; |
| 9230 | } |
| 9231 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9232 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9233 | .create = nfs_create, |
| 9234 | .lookup = nfs_lookup, |
| 9235 | .atomic_open = nfs_atomic_open, |
| 9236 | .link = nfs_link, |
| 9237 | .unlink = nfs_unlink, |
| 9238 | .symlink = nfs_symlink, |
| 9239 | .mkdir = nfs_mkdir, |
| 9240 | .rmdir = nfs_rmdir, |
| 9241 | .mknod = nfs_mknod, |
| 9242 | .rename = nfs_rename, |
| 9243 | .permission = nfs_permission, |
| 9244 | .getattr = nfs_getattr, |
| 9245 | .setattr = nfs_setattr, |
| 9246 | .getxattr = generic_getxattr, |
| 9247 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9248 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9249 | .removexattr = generic_removexattr, |
| 9250 | }; |
| 9251 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9252 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9253 | .permission = nfs_permission, |
| 9254 | .getattr = nfs_getattr, |
| 9255 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9256 | .getxattr = generic_getxattr, |
| 9257 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9258 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9259 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9260 | }; |
| 9261 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9262 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9263 | .version = 4, /* protocol version */ |
| 9264 | .dentry_ops = &nfs4_dentry_operations, |
| 9265 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9266 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9267 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9268 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9269 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9270 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9271 | .getattr = nfs4_proc_getattr, |
| 9272 | .setattr = nfs4_proc_setattr, |
| 9273 | .lookup = nfs4_proc_lookup, |
| 9274 | .access = nfs4_proc_access, |
| 9275 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9276 | .create = nfs4_proc_create, |
| 9277 | .remove = nfs4_proc_remove, |
| 9278 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9279 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9280 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9281 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9282 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9283 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9284 | .link = nfs4_proc_link, |
| 9285 | .symlink = nfs4_proc_symlink, |
| 9286 | .mkdir = nfs4_proc_mkdir, |
| 9287 | .rmdir = nfs4_proc_remove, |
| 9288 | .readdir = nfs4_proc_readdir, |
| 9289 | .mknod = nfs4_proc_mknod, |
| 9290 | .statfs = nfs4_proc_statfs, |
| 9291 | .fsinfo = nfs4_proc_fsinfo, |
| 9292 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9293 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9294 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9295 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9296 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9297 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9298 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9299 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9300 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9301 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9302 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9303 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9304 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9305 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9306 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9307 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9308 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9309 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9310 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9311 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9312 | .create_server = nfs4_create_server, |
| 9313 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9314 | }; |
| 9315 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9316 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9317 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9318 | .list = nfs4_xattr_list_nfs4_acl, |
| 9319 | .get = nfs4_xattr_get_nfs4_acl, |
| 9320 | .set = nfs4_xattr_set_nfs4_acl, |
| 9321 | }; |
| 9322 | |
| 9323 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9324 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9325 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9326 | &nfs4_xattr_nfs4_label_handler, |
| 9327 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9328 | NULL |
| 9329 | }; |
| 9330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9331 | /* |
| 9332 | * Local variables: |
| 9333 | * c-basic-offset: 8 |
| 9334 | * End: |
| 9335 | */ |