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 | 035168ab | 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 | 035168ab | 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 | 035168ab | 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 | 035168ab | 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 | 6926afd1 | 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 | 6926afd1 | 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 | 6926afd1 | 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, |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1402 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 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)) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1407 | nfs4_stateid_copy(freeme, &state->open_stateid); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1408 | nfs_test_and_clear_all_open_stateid(state); |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1409 | return true; |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1410 | } |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1411 | if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) |
| 1412 | return true; |
| 1413 | return false; |
| 1414 | } |
| 1415 | |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1416 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) |
| 1417 | { |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1418 | if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) |
| 1419 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1420 | if (state->n_wronly) |
| 1421 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1422 | if (state->n_rdonly) |
| 1423 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1424 | if (state->n_rdwr) |
| 1425 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 3c38cbe | 2015-07-22 13:46:13 -0400 | [diff] [blame] | 1426 | set_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1427 | } |
| 1428 | |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1429 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1430 | nfs4_stateid *arg_stateid, |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1431 | nfs4_stateid *stateid, fmode_t fmode) |
| 1432 | { |
| 1433 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1434 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { |
| 1435 | case FMODE_WRITE: |
| 1436 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1437 | break; |
| 1438 | case FMODE_READ: |
| 1439 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1440 | break; |
| 1441 | case 0: |
| 1442 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1443 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1444 | clear_bit(NFS_OPEN_STATE, &state->flags); |
| 1445 | } |
| 1446 | if (stateid == NULL) |
| 1447 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1448 | /* Handle races with OPEN */ |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1449 | if (!nfs4_stateid_match_other(arg_stateid, &state->open_stateid) || |
| 1450 | (nfs4_stateid_match_other(stateid, &state->open_stateid) && |
| 1451 | !nfs4_stateid_is_newer(stateid, &state->open_stateid))) { |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1452 | nfs_resync_open_stateid_locked(state); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1453 | return; |
Trond Myklebust | f95549c | 2015-01-23 18:06:09 -0500 | [diff] [blame] | 1454 | } |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1455 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1456 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1457 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1458 | } |
| 1459 | |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1460 | static void nfs_clear_open_stateid(struct nfs4_state *state, |
| 1461 | nfs4_stateid *arg_stateid, |
| 1462 | nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1463 | { |
| 1464 | write_seqlock(&state->seqlock); |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 1465 | nfs_clear_open_stateid_locked(state, arg_stateid, stateid, fmode); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1466 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1467 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
| 1468 | nfs4_schedule_state_manager(state->owner->so_server->nfs_client); |
Trond Myklebust | 226056c | 2014-02-11 10:41:07 -0500 | [diff] [blame] | 1469 | } |
| 1470 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1471 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
| 1472 | const nfs4_stateid *stateid, fmode_t fmode, |
| 1473 | nfs4_stateid *freeme) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1474 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1475 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1476 | case FMODE_READ: |
| 1477 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1478 | break; |
| 1479 | case FMODE_WRITE: |
| 1480 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1481 | break; |
| 1482 | case FMODE_READ|FMODE_WRITE: |
| 1483 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1484 | } |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1485 | if (!nfs_need_update_open_stateid(state, stateid, freeme)) |
Trond Myklebust | e999e80 | 2014-02-10 18:20:47 -0500 | [diff] [blame] | 1486 | return; |
| 1487 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1488 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1489 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1490 | } |
| 1491 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1492 | static void __update_open_stateid(struct nfs4_state *state, |
| 1493 | const nfs4_stateid *open_stateid, |
| 1494 | const nfs4_stateid *deleg_stateid, |
| 1495 | fmode_t fmode, |
| 1496 | nfs4_stateid *freeme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1498 | /* |
| 1499 | * Protect the call to nfs4_state_set_mode_locked and |
| 1500 | * serialise the stateid update |
| 1501 | */ |
Andrew Elble | 361cad3 | 2015-12-02 09:20:57 -0500 | [diff] [blame] | 1502 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1503 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1504 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1505 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1506 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1507 | } |
| 1508 | if (open_stateid != NULL) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1509 | nfs_set_open_stateid_locked(state, open_stateid, fmode, freeme); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1510 | write_sequnlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1511 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1512 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1515 | static int update_open_stateid(struct nfs4_state *state, |
| 1516 | const nfs4_stateid *open_stateid, |
| 1517 | const nfs4_stateid *delegation, |
| 1518 | fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1519 | { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1520 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1521 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1522 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1523 | struct nfs_delegation *deleg_cur; |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1524 | nfs4_stateid freeme = {0}; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1525 | int ret = 0; |
| 1526 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1527 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1528 | |
| 1529 | rcu_read_lock(); |
| 1530 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1531 | if (deleg_cur == NULL) |
| 1532 | goto no_delegation; |
| 1533 | |
| 1534 | spin_lock(&deleg_cur->lock); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 1535 | if (rcu_dereference(nfsi->delegation) != deleg_cur || |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 1536 | test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1537 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1538 | goto no_delegation_unlock; |
| 1539 | |
| 1540 | if (delegation == NULL) |
| 1541 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1542 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1543 | goto no_delegation_unlock; |
| 1544 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1545 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1546 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, |
| 1547 | fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1548 | ret = 1; |
| 1549 | no_delegation_unlock: |
| 1550 | spin_unlock(&deleg_cur->lock); |
| 1551 | no_delegation: |
| 1552 | rcu_read_unlock(); |
| 1553 | |
| 1554 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1555 | __update_open_stateid(state, open_stateid, NULL, fmode, &freeme); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1556 | ret = 1; |
| 1557 | } |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1558 | if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) |
Trond Myklebust | 1393d96 | 2016-09-22 13:39:13 -0400 | [diff] [blame^] | 1559 | nfs4_schedule_state_manager(clp); |
| 1560 | if (freeme.type != 0) |
| 1561 | nfs4_test_and_free_stateid(server, &freeme, |
| 1562 | state->owner->so_cred); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1563 | |
| 1564 | return ret; |
| 1565 | } |
| 1566 | |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 1567 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, |
| 1568 | const nfs4_stateid *stateid) |
| 1569 | { |
| 1570 | struct nfs4_state *state = lsp->ls_state; |
| 1571 | bool ret = false; |
| 1572 | |
| 1573 | spin_lock(&state->state_lock); |
| 1574 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) |
| 1575 | goto out_noupdate; |
| 1576 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) |
| 1577 | goto out_noupdate; |
| 1578 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); |
| 1579 | ret = true; |
| 1580 | out_noupdate: |
| 1581 | spin_unlock(&state->state_lock); |
| 1582 | return ret; |
| 1583 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1584 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1585 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1586 | { |
| 1587 | struct nfs_delegation *delegation; |
| 1588 | |
| 1589 | rcu_read_lock(); |
| 1590 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1591 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1592 | rcu_read_unlock(); |
| 1593 | return; |
| 1594 | } |
| 1595 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1596 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1597 | } |
| 1598 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1599 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1600 | { |
| 1601 | struct nfs4_state *state = opendata->state; |
| 1602 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1603 | struct nfs_delegation *delegation; |
Trond Myklebust | f448bad | 2013-05-29 15:36:40 -0400 | [diff] [blame] | 1604 | int open_mode = opendata->o_arg.open_flags; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1605 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1606 | enum open_claim_type4 claim = opendata->o_arg.claim; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1607 | nfs4_stateid stateid; |
| 1608 | int ret = -EAGAIN; |
| 1609 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1610 | for (;;) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1611 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1612 | if (can_open_cached(state, fmode, open_mode)) { |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1613 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1614 | spin_unlock(&state->owner->so_lock); |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1615 | goto out_return_state; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1616 | } |
Anna Schumaker | 61beef7 | 2014-09-03 14:15:40 -0400 | [diff] [blame] | 1617 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1618 | rcu_read_lock(); |
| 1619 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 1620 | if (!can_open_delegated(delegation, fmode, claim)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1621 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1622 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1623 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1624 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1625 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1626 | rcu_read_unlock(); |
Trond Myklebust | fa33294 | 2013-04-09 12:56:52 -0400 | [diff] [blame] | 1627 | nfs_release_seqid(opendata->o_arg.seqid); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 1628 | if (!opendata->is_recover) { |
| 1629 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
| 1630 | if (ret != 0) |
| 1631 | goto out; |
| 1632 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1633 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1634 | |
| 1635 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1636 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1637 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1638 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1639 | out: |
| 1640 | return ERR_PTR(ret); |
| 1641 | out_return_state: |
| 1642 | atomic_inc(&state->count); |
| 1643 | return state; |
| 1644 | } |
| 1645 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1646 | static void |
| 1647 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1648 | { |
| 1649 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1650 | struct nfs_delegation *delegation; |
| 1651 | int delegation_flags = 0; |
| 1652 | |
| 1653 | rcu_read_lock(); |
| 1654 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1655 | if (delegation) |
| 1656 | delegation_flags = delegation->flags; |
| 1657 | rcu_read_unlock(); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1658 | switch (data->o_arg.claim) { |
| 1659 | default: |
| 1660 | break; |
| 1661 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1662 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1663 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1664 | "returning a delegation for " |
| 1665 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1666 | clp->cl_hostname); |
Trond Myklebust | 72d79ff | 2015-10-02 11:44:54 -0400 | [diff] [blame] | 1667 | return; |
| 1668 | } |
| 1669 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1670 | nfs_inode_set_delegation(state->inode, |
| 1671 | data->owner->so_cred, |
| 1672 | &data->o_res); |
| 1673 | else |
| 1674 | nfs_inode_reclaim_delegation(state->inode, |
| 1675 | data->owner->so_cred, |
| 1676 | &data->o_res); |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1681 | * and update the nfs4_state. |
| 1682 | */ |
| 1683 | static struct nfs4_state * |
| 1684 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1685 | { |
| 1686 | struct inode *inode = data->state->inode; |
| 1687 | struct nfs4_state *state = data->state; |
| 1688 | int ret; |
| 1689 | |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1690 | if (!data->rpc_done) { |
| 1691 | if (data->rpc_status) { |
| 1692 | ret = data->rpc_status; |
| 1693 | goto err; |
| 1694 | } |
| 1695 | /* cached opens have already been processed */ |
| 1696 | goto update; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1697 | } |
| 1698 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1699 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1700 | if (ret) |
| 1701 | goto err; |
| 1702 | |
| 1703 | if (data->o_res.delegation_type != 0) |
| 1704 | nfs4_opendata_check_deleg(data, state); |
Weston Andros Adamson | d2bfda2 | 2013-10-21 13:10:13 -0400 | [diff] [blame] | 1705 | update: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1706 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1707 | data->o_arg.fmode); |
Trond Myklebust | d49f042 | 2013-10-28 14:57:12 -0400 | [diff] [blame] | 1708 | atomic_inc(&state->count); |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1709 | |
| 1710 | return state; |
| 1711 | err: |
| 1712 | return ERR_PTR(ret); |
| 1713 | |
| 1714 | } |
| 1715 | |
| 1716 | static struct nfs4_state * |
| 1717 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1718 | { |
| 1719 | struct inode *inode; |
| 1720 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1721 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1722 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1723 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1724 | state = nfs4_try_open_cached(data); |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 1725 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1726 | goto out; |
| 1727 | } |
| 1728 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1729 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1730 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1731 | goto err; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1732 | 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] | 1733 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1734 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1735 | goto err; |
| 1736 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1737 | state = nfs4_get_open_state(inode, data->owner); |
| 1738 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1739 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1740 | if (data->o_res.delegation_type != 0) |
| 1741 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1742 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1743 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1744 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1745 | out: |
Trond Myklebust | 7aa262b5 | 2013-02-28 16:19:59 -0800 | [diff] [blame] | 1746 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1747 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1748 | err_put_inode: |
| 1749 | iput(inode); |
| 1750 | err: |
| 1751 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1754 | static struct nfs4_state * |
| 1755 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1756 | { |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1757 | struct nfs4_state *ret; |
| 1758 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1759 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 1760 | ret =_nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1761 | else |
| 1762 | ret = _nfs4_opendata_to_nfs4_state(data); |
| 1763 | nfs4_sequence_free_slot(&data->o_res.seq_res); |
| 1764 | return ret; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1765 | } |
| 1766 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1767 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1768 | { |
| 1769 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1770 | struct nfs_open_context *ctx; |
| 1771 | |
| 1772 | spin_lock(&state->inode->i_lock); |
| 1773 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1774 | if (ctx->state != state) |
| 1775 | continue; |
| 1776 | get_nfs_open_context(ctx); |
| 1777 | spin_unlock(&state->inode->i_lock); |
| 1778 | return ctx; |
| 1779 | } |
| 1780 | spin_unlock(&state->inode->i_lock); |
| 1781 | return ERR_PTR(-ENOENT); |
| 1782 | } |
| 1783 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1784 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
| 1785 | struct nfs4_state *state, enum open_claim_type4 claim) |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1786 | { |
| 1787 | struct nfs4_opendata *opendata; |
| 1788 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1789 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 1790 | NULL, NULL, claim, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1791 | if (opendata == NULL) |
| 1792 | return ERR_PTR(-ENOMEM); |
| 1793 | opendata->state = state; |
| 1794 | atomic_inc(&state->count); |
| 1795 | return opendata; |
| 1796 | } |
| 1797 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1798 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
| 1799 | fmode_t fmode) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1800 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1801 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1802 | int ret; |
| 1803 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1804 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
NeilBrown | 39f897f | 2015-06-29 14:28:54 +1000 | [diff] [blame] | 1805 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1806 | opendata->o_arg.open_flags = 0; |
| 1807 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | be36e18 | 2015-02-27 17:04:17 -0500 | [diff] [blame] | 1808 | opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
| 1809 | NFS_SB(opendata->dentry->d_sb), |
| 1810 | fmode, 0); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1811 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1812 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1813 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1814 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1815 | if (ret != 0) |
| 1816 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1817 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1818 | if (IS_ERR(newstate)) |
| 1819 | return PTR_ERR(newstate); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1820 | if (newstate != opendata->state) |
| 1821 | ret = -ESTALE; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1822 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1823 | return ret; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1827 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1828 | int ret; |
| 1829 | |
Trond Myklebust | 4f14c19 | 2014-02-12 19:15:06 -0500 | [diff] [blame] | 1830 | /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
| 1831 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1832 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1833 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1834 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1835 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 1836 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1837 | smp_rmb(); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1838 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1839 | if (ret != 0) |
| 1840 | return ret; |
| 1841 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1842 | if (ret != 0) |
| 1843 | return ret; |
| 1844 | ret = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1845 | if (ret != 0) |
| 1846 | return ret; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1847 | /* |
| 1848 | * We may have performed cached opens for all three recoveries. |
| 1849 | * Check if we need to update the current stateid. |
| 1850 | */ |
| 1851 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1852 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1853 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1854 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1855 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1856 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1857 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1858 | return 0; |
| 1859 | } |
| 1860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | /* |
| 1862 | * OPEN_RECLAIM: |
| 1863 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1865 | 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] | 1866 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1867 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1868 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1869 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | int status; |
| 1871 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 1872 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1873 | NFS4_OPEN_CLAIM_PREVIOUS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1874 | if (IS_ERR(opendata)) |
| 1875 | return PTR_ERR(opendata); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1876 | rcu_read_lock(); |
| 1877 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1878 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1879 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1880 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1881 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1882 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1883 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | return status; |
| 1885 | } |
| 1886 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1887 | 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] | 1888 | { |
| 1889 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1890 | struct nfs4_exception exception = { }; |
| 1891 | int err; |
| 1892 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1893 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 1894 | trace_nfs4_open_reclaim(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 1895 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 1896 | continue; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1897 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | } while (exception.retry); |
| 1901 | return err; |
| 1902 | } |
| 1903 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1904 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1905 | { |
| 1906 | struct nfs_open_context *ctx; |
| 1907 | int ret; |
| 1908 | |
| 1909 | ctx = nfs4_state_find_open_context(state); |
| 1910 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 1911 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1912 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1913 | put_nfs_open_context(ctx); |
| 1914 | return ret; |
| 1915 | } |
| 1916 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1917 | 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] | 1918 | { |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1919 | switch (err) { |
| 1920 | default: |
| 1921 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 1922 | "%d.\n", __func__, err); |
| 1923 | case 0: |
| 1924 | case -ENOENT: |
Trond Myklebust | 8eee52a | 2015-06-04 13:51:13 -0400 | [diff] [blame] | 1925 | case -EAGAIN: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1926 | case -ESTALE: |
| 1927 | break; |
| 1928 | case -NFS4ERR_BADSESSION: |
| 1929 | case -NFS4ERR_BADSLOT: |
| 1930 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1931 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1932 | case -NFS4ERR_DEADSESSION: |
| 1933 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1934 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
| 1935 | return -EAGAIN; |
| 1936 | case -NFS4ERR_STALE_CLIENTID: |
| 1937 | case -NFS4ERR_STALE_STATEID: |
| 1938 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1939 | /* Don't recall a delegation if it was lost */ |
| 1940 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 1941 | return -EAGAIN; |
Chuck Lever | 352297b | 2013-10-17 14:13:24 -0400 | [diff] [blame] | 1942 | case -NFS4ERR_MOVED: |
| 1943 | nfs4_schedule_migration_recovery(server); |
| 1944 | return -EAGAIN; |
Chuck Lever | 8ef2f8d | 2013-10-17 14:13:41 -0400 | [diff] [blame] | 1945 | case -NFS4ERR_LEASE_MOVED: |
| 1946 | nfs4_schedule_lease_moved_recovery(server->nfs_client); |
| 1947 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1948 | case -NFS4ERR_DELEG_REVOKED: |
| 1949 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | 404ea356 | 2016-09-22 13:39:08 -0400 | [diff] [blame] | 1950 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1951 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1952 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1953 | nfs_inode_find_state_and_recover(state->inode, |
| 1954 | stateid); |
| 1955 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 1956 | return -EAGAIN; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1957 | case -NFS4ERR_DELAY: |
| 1958 | case -NFS4ERR_GRACE: |
| 1959 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1960 | ssleep(1); |
| 1961 | return -EAGAIN; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1962 | case -ENOMEM: |
| 1963 | case -NFS4ERR_DENIED: |
| 1964 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1965 | return 0; |
Trond Myklebust | be76b5b | 2013-04-01 15:40:44 -0400 | [diff] [blame] | 1966 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | return err; |
| 1968 | } |
| 1969 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1970 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, |
| 1971 | struct nfs4_state *state, const nfs4_stateid *stateid, |
| 1972 | fmode_t type) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1973 | { |
| 1974 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1975 | struct nfs4_opendata *opendata; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1976 | int err = 0; |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1977 | |
| 1978 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
| 1979 | NFS4_OPEN_CLAIM_DELEG_CUR_FH); |
| 1980 | if (IS_ERR(opendata)) |
| 1981 | return PTR_ERR(opendata); |
| 1982 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Jeff Layton | 5e99b53 | 2015-10-02 13:14:37 -0400 | [diff] [blame] | 1983 | write_seqlock(&state->seqlock); |
| 1984 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1985 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 1986 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1987 | switch (type & (FMODE_READ|FMODE_WRITE)) { |
| 1988 | case FMODE_READ|FMODE_WRITE: |
| 1989 | case FMODE_WRITE: |
| 1990 | err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
| 1991 | if (err) |
| 1992 | break; |
| 1993 | err = nfs4_open_recover_helper(opendata, FMODE_WRITE); |
| 1994 | if (err) |
| 1995 | break; |
| 1996 | case FMODE_READ: |
| 1997 | err = nfs4_open_recover_helper(opendata, FMODE_READ); |
| 1998 | } |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 1999 | nfs4_opendata_put(opendata); |
| 2000 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
| 2001 | } |
| 2002 | |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2003 | static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) |
| 2004 | { |
| 2005 | struct nfs4_opendata *data = calldata; |
| 2006 | |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 2007 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 2008 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2009 | } |
| 2010 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2011 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 2012 | { |
| 2013 | struct nfs4_opendata *data = calldata; |
| 2014 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2015 | nfs40_sequence_done(task, &data->c_res.seq_res); |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2016 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2017 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2018 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2019 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 2020 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2021 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2022 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2023 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | static void nfs4_open_confirm_release(void *calldata) |
| 2027 | { |
| 2028 | struct nfs4_opendata *data = calldata; |
| 2029 | struct nfs4_state *state = NULL; |
| 2030 | |
| 2031 | /* If this request hasn't been cancelled, do nothing */ |
| 2032 | if (data->cancelled == 0) |
| 2033 | goto out_free; |
| 2034 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2035 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2036 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2037 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2038 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2039 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2040 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2041 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Chuck Lever | be05c86 | 2013-08-09 12:49:47 -0400 | [diff] [blame] | 2045 | .rpc_call_prepare = nfs4_open_confirm_prepare, |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2046 | .rpc_call_done = nfs4_open_confirm_done, |
| 2047 | .rpc_release = nfs4_open_confirm_release, |
| 2048 | }; |
| 2049 | |
| 2050 | /* |
| 2051 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 2052 | */ |
| 2053 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 2054 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2055 | struct nfs_server *server = NFS_SERVER(d_inode(data->dir)); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2056 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2057 | struct rpc_message msg = { |
| 2058 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 2059 | .rpc_argp = &data->c_arg, |
| 2060 | .rpc_resp = &data->c_res, |
| 2061 | .rpc_cred = data->owner->so_cred, |
| 2062 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2063 | struct rpc_task_setup task_setup_data = { |
| 2064 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2065 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2066 | .callback_ops = &nfs4_open_confirm_ops, |
| 2067 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2068 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2069 | .flags = RPC_TASK_ASYNC, |
| 2070 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | int status; |
| 2072 | |
Trond Myklebust | 17ead6c | 2014-02-01 14:53:23 -0500 | [diff] [blame] | 2073 | 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] | 2074 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2075 | data->rpc_done = 0; |
| 2076 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2077 | data->timestamp = jiffies; |
Benjamin Coddington | e92c1e0 | 2015-10-01 09:17:33 -0400 | [diff] [blame] | 2078 | if (data->is_recover) |
| 2079 | nfs4_set_sequence_privileged(&data->c_arg.seq_args); |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2080 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 2081 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2082 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2083 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2084 | if (status != 0) { |
| 2085 | data->cancelled = 1; |
| 2086 | smp_wmb(); |
| 2087 | } else |
| 2088 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 2089 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | return status; |
| 2091 | } |
| 2092 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2093 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2095 | struct nfs4_opendata *data = calldata; |
| 2096 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2097 | struct nfs_client *clp = sp->so_server->nfs_client; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2098 | enum open_claim_type4 claim = data->o_arg.claim; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2099 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2100 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2101 | goto out_wait; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2102 | /* |
| 2103 | * Check if we still need to send an OPEN call, or if we can use |
| 2104 | * a delegation instead. |
| 2105 | */ |
| 2106 | if (data->state != NULL) { |
| 2107 | struct nfs_delegation *delegation; |
| 2108 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2109 | 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] | 2110 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2111 | rcu_read_lock(); |
| 2112 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2113 | if (can_open_delegated(delegation, data->o_arg.fmode, claim)) |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2114 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2115 | rcu_read_unlock(); |
| 2116 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 2117 | /* Update client id. */ |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2118 | data->o_arg.clientid = clp->cl_clientid; |
Trond Myklebust | 2a60618 | 2015-08-19 22:30:00 -0500 | [diff] [blame] | 2119 | switch (claim) { |
| 2120 | default: |
| 2121 | break; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2122 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 2123 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 2124 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 2125 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 8188df1 | 2013-04-23 14:31:19 -0400 | [diff] [blame] | 2126 | case NFS4_OPEN_CLAIM_FH: |
| 2127 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2128 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 2129 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2130 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2131 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2132 | &data->o_arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 2133 | &data->o_res.seq_res, |
| 2134 | task) != 0) |
| 2135 | nfs_release_seqid(data->o_arg.seqid); |
Trond Myklebust | 549b19c | 2013-04-16 18:42:34 -0400 | [diff] [blame] | 2136 | |
| 2137 | /* Set the create mode (note dependency on the session type) */ |
| 2138 | data->o_arg.createmode = NFS4_CREATE_UNCHECKED; |
| 2139 | if (data->o_arg.open_flags & O_EXCL) { |
| 2140 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE; |
| 2141 | if (nfs4_has_persistent_session(clp)) |
| 2142 | data->o_arg.createmode = NFS4_CREATE_GUARDED; |
| 2143 | else if (clp->cl_mvops->minor_version > 0) |
| 2144 | data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1; |
| 2145 | } |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2146 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2147 | unlock_no_action: |
Olga Kornievskaia | 9759b0f | 2015-11-24 13:29:42 -0500 | [diff] [blame] | 2148 | trace_nfs4_cached_open(data->state); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 2149 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 2150 | out_no_action: |
| 2151 | task->tk_action = NULL; |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 2152 | out_wait: |
Trond Myklebust | b75ad4c | 2012-11-29 17:27:47 -0500 | [diff] [blame] | 2153 | nfs4_sequence_done(task, &data->o_res.seq_res); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2154 | } |
| 2155 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2156 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 2157 | { |
| 2158 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2160 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2161 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 2162 | if (!nfs4_sequence_process(task, &data->o_res.seq_res)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2163 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 2164 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2165 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2166 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 2167 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2168 | case S_IFREG: |
| 2169 | break; |
| 2170 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2171 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2172 | break; |
| 2173 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2174 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2175 | break; |
| 2176 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2177 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 2178 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2179 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2180 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 2181 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 2182 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2183 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2184 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2185 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 2186 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2187 | static void nfs4_open_release(void *calldata) |
| 2188 | { |
| 2189 | struct nfs4_opendata *data = calldata; |
| 2190 | struct nfs4_state *state = NULL; |
| 2191 | |
| 2192 | /* If this request hasn't been cancelled, do nothing */ |
| 2193 | if (data->cancelled == 0) |
| 2194 | goto out_free; |
| 2195 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2196 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2197 | goto out_free; |
| 2198 | /* In case we need an open_confirm, no cleanup! */ |
| 2199 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 2200 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2201 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2202 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2203 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2204 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2205 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | static const struct rpc_call_ops nfs4_open_ops = { |
| 2209 | .rpc_call_prepare = nfs4_open_prepare, |
| 2210 | .rpc_call_done = nfs4_open_done, |
| 2211 | .rpc_release = nfs4_open_release, |
| 2212 | }; |
| 2213 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2214 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2215 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2216 | struct inode *dir = d_inode(data->dir); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2217 | struct nfs_server *server = NFS_SERVER(dir); |
| 2218 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2219 | struct nfs_openres *o_res = &data->o_res; |
| 2220 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2221 | struct rpc_message msg = { |
| 2222 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 2223 | .rpc_argp = o_arg, |
| 2224 | .rpc_resp = o_res, |
| 2225 | .rpc_cred = data->owner->so_cred, |
| 2226 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2227 | struct rpc_task_setup task_setup_data = { |
| 2228 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2229 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2230 | .callback_ops = &nfs4_open_ops, |
| 2231 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2232 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2233 | .flags = RPC_TASK_ASYNC, |
| 2234 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2235 | int status; |
| 2236 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 2237 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2238 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 2239 | data->rpc_done = 0; |
| 2240 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 2241 | data->cancelled = 0; |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2242 | data->is_recover = 0; |
| 2243 | if (isrecover) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 2244 | nfs4_set_sequence_privileged(&o_arg->seq_args); |
Trond Myklebust | bdeca1b | 2013-04-23 14:52:44 -0400 | [diff] [blame] | 2245 | data->is_recover = 1; |
| 2246 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2247 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2248 | if (IS_ERR(task)) |
| 2249 | return PTR_ERR(task); |
| 2250 | status = nfs4_wait_for_completion_rpc_task(task); |
| 2251 | if (status != 0) { |
| 2252 | data->cancelled = 1; |
| 2253 | smp_wmb(); |
| 2254 | } else |
| 2255 | status = data->rpc_status; |
| 2256 | rpc_put_task(task); |
| 2257 | |
| 2258 | return status; |
| 2259 | } |
| 2260 | |
| 2261 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 2262 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2263 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2264 | struct nfs_openres *o_res = &data->o_res; |
| 2265 | int status; |
| 2266 | |
| 2267 | status = nfs4_run_open_task(data, 1); |
| 2268 | if (status != 0 || !data->rpc_done) |
| 2269 | return status; |
| 2270 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2271 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 2272 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2273 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 2274 | status = _nfs4_proc_open_confirm(data); |
| 2275 | if (status != 0) |
| 2276 | return status; |
| 2277 | } |
| 2278 | |
| 2279 | return status; |
| 2280 | } |
| 2281 | |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2282 | /* |
| 2283 | * Additional permission checks in order to distinguish between an |
| 2284 | * open for read, and an open for execute. This works around the |
| 2285 | * fact that NFSv4 OPEN treats read and execute permissions as being |
| 2286 | * the same. |
| 2287 | * Note that in the non-execute case, we want to turn off permission |
| 2288 | * checking if we just created a new file (POSIX open() semantics). |
| 2289 | */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2290 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 2291 | struct nfs4_opendata *opendata, |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2292 | struct nfs4_state *state, fmode_t fmode, |
| 2293 | int openflags) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2294 | { |
| 2295 | struct nfs_access_entry cache; |
| 2296 | u32 mask; |
| 2297 | |
| 2298 | /* access call failed or for some reason the server doesn't |
| 2299 | * support any access modes -- defer access call until later */ |
| 2300 | if (opendata->o_res.access_supported == 0) |
| 2301 | return 0; |
| 2302 | |
| 2303 | mask = 0; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2304 | /* |
| 2305 | * Use openflags to check for exec, because fmode won't |
| 2306 | * always have FMODE_EXEC set when file open for exec. |
| 2307 | */ |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2308 | if (openflags & __FMODE_EXEC) { |
| 2309 | /* ONLY check for exec rights */ |
| 2310 | mask = MAY_EXEC; |
Trond Myklebust | f3792d6 | 2014-07-10 08:54:32 -0400 | [diff] [blame] | 2311 | } else if ((fmode & FMODE_READ) && !opendata->file_created) |
Weston Andros Adamson | f8d9a89 | 2013-01-03 16:42:29 -0500 | [diff] [blame] | 2312 | mask = MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2313 | |
| 2314 | cache.cred = cred; |
| 2315 | cache.jiffies = jiffies; |
| 2316 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 2317 | nfs_access_add_cache(state->inode, &cache); |
| 2318 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 2319 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2320 | return 0; |
| 2321 | |
| 2322 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 2323 | nfs4_close_state(state, fmode); |
Weston Andros Adamson | 998f40b | 2012-11-02 18:00:56 -0400 | [diff] [blame] | 2324 | return -EACCES; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2325 | } |
| 2326 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2327 | /* |
| 2328 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 2329 | */ |
| 2330 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 2331 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2332 | struct inode *dir = d_inode(data->dir); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 2333 | struct nfs_server *server = NFS_SERVER(dir); |
| 2334 | struct nfs_openargs *o_arg = &data->o_arg; |
| 2335 | struct nfs_openres *o_res = &data->o_res; |
| 2336 | int status; |
| 2337 | |
| 2338 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2339 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2340 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2341 | if (status != 0) { |
| 2342 | if (status == -NFS4ERR_BADNAME && |
| 2343 | !(o_arg->open_flags & O_CREAT)) |
| 2344 | return -ENOENT; |
| 2345 | return status; |
| 2346 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2347 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 2348 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 2349 | |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2350 | if (o_arg->open_flags & O_CREAT) { |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 2351 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2352 | if (o_arg->open_flags & O_EXCL) |
| 2353 | data->file_created = 1; |
| 2354 | else if (o_res->cinfo.before != o_res->cinfo.after) |
| 2355 | data->file_created = 1; |
| 2356 | } |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2357 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 2358 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 2360 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2362 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | } |
| 2364 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Andy Adamson | 8935ef6 | 2014-05-23 06:22:59 -0700 | [diff] [blame] | 2365 | 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] | 2366 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 2369 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 2370 | { |
| 2371 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 2372 | } |
| 2373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | /* |
| 2375 | * OPEN_EXPIRED: |
| 2376 | * reclaim state on the server after a network partition. |
| 2377 | * Assumes caller holds the appropriate lock |
| 2378 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2379 | 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] | 2380 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2381 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2382 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2384 | opendata = nfs4_open_recoverdata_alloc(ctx, state, |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2385 | NFS4_OPEN_CLAIM_FH); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 2386 | if (IS_ERR(opendata)) |
| 2387 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2388 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 2389 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2390 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2391 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2392 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2395 | 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] | 2396 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2397 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2398 | struct nfs4_exception exception = { }; |
| 2399 | int err; |
| 2400 | |
| 2401 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2402 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2403 | trace_nfs4_open_expired(ctx, 0, err); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2404 | if (nfs4_clear_cap_atomic_open_v1(server, err, &exception)) |
| 2405 | continue; |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2406 | switch (err) { |
| 2407 | default: |
| 2408 | goto out; |
| 2409 | case -NFS4ERR_GRACE: |
| 2410 | case -NFS4ERR_DELAY: |
| 2411 | nfs4_handle_exception(server, err, &exception); |
| 2412 | err = 0; |
| 2413 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2414 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 2415 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2416 | return err; |
| 2417 | } |
| 2418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2420 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2422 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2424 | ctx = nfs4_state_find_open_context(state); |
| 2425 | if (IS_ERR(ctx)) |
Trond Myklebust | 91876b1 | 2013-03-28 14:01:33 -0400 | [diff] [blame] | 2426 | return -EAGAIN; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 2427 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 2428 | put_nfs_open_context(ctx); |
| 2429 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2432 | static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, |
| 2433 | const nfs4_stateid *stateid) |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2434 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2435 | nfs_remove_bad_delegation(state->inode, stateid); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2436 | write_seqlock(&state->seqlock); |
| 2437 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 2438 | write_sequnlock(&state->seqlock); |
| 2439 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 2440 | } |
| 2441 | |
| 2442 | static void nfs40_clear_delegation_stateid(struct nfs4_state *state) |
| 2443 | { |
| 2444 | if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2445 | nfs_finish_clear_delegation_stateid(state, NULL); |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2449 | { |
| 2450 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
| 2451 | nfs40_clear_delegation_stateid(state); |
| 2452 | return nfs4_open_expired(sp, state); |
| 2453 | } |
| 2454 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 2455 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
| 2456 | nfs4_stateid *stateid, |
| 2457 | struct rpc_cred *cred) |
| 2458 | { |
| 2459 | return -NFS4ERR_BAD_STATEID; |
| 2460 | } |
| 2461 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2462 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2463 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
| 2464 | nfs4_stateid *stateid, |
| 2465 | struct rpc_cred *cred) |
| 2466 | { |
| 2467 | int status; |
| 2468 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2469 | switch (stateid->type) { |
| 2470 | default: |
| 2471 | break; |
| 2472 | case NFS4_INVALID_STATEID_TYPE: |
| 2473 | case NFS4_SPECIAL_STATEID_TYPE: |
| 2474 | return -NFS4ERR_BAD_STATEID; |
| 2475 | case NFS4_REVOKED_STATEID_TYPE: |
| 2476 | goto out_free; |
| 2477 | } |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2478 | |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2479 | status = nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2480 | switch (status) { |
| 2481 | case -NFS4ERR_EXPIRED: |
| 2482 | case -NFS4ERR_ADMIN_REVOKED: |
| 2483 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2484 | break; |
| 2485 | default: |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2486 | return status; |
| 2487 | } |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2488 | out_free: |
| 2489 | /* Ack the revoked state to the server */ |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 2490 | nfs41_free_stateid(server, stateid, cred, true); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2491 | return -NFS4ERR_EXPIRED; |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2492 | } |
| 2493 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2494 | static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2495 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2496 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2497 | nfs4_stateid stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2498 | struct nfs_delegation *delegation; |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2499 | struct rpc_cred *cred; |
| 2500 | int status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2501 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2502 | /* Get the delegation credential for use by test/free_stateid */ |
| 2503 | rcu_read_lock(); |
| 2504 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2505 | if (delegation == NULL) { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2506 | rcu_read_unlock(); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2507 | return; |
| 2508 | } |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2509 | |
| 2510 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2511 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
| 2512 | rcu_read_unlock(); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2513 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | 4c8e544 | 2016-09-22 13:38:55 -0400 | [diff] [blame] | 2514 | return; |
| 2515 | } |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2516 | |
Trond Myklebust | 63d63cb | 2016-09-22 13:39:01 -0400 | [diff] [blame] | 2517 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { |
| 2518 | rcu_read_unlock(); |
| 2519 | return; |
| 2520 | } |
| 2521 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2522 | cred = get_rpccred(delegation->cred); |
| 2523 | rcu_read_unlock(); |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2524 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2525 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2526 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 2527 | nfs_finish_clear_delegation_stateid(state, &stateid); |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2528 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2529 | put_rpccred(cred); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /** |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2533 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 2534 | * |
| 2535 | * @state: NFSv4 state for an inode |
| 2536 | * |
| 2537 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2538 | * Otherwise a negative NFS4ERR value is returned. |
| 2539 | */ |
| 2540 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
| 2541 | { |
| 2542 | int status, ret = NFS_OK; |
| 2543 | struct nfs4_lock_state *lsp; |
| 2544 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2545 | |
| 2546 | if (!test_bit(LK_STATE_IN_USE, &state->flags)) |
| 2547 | goto out; |
| 2548 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
| 2549 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
| 2550 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
| 2551 | |
| 2552 | status = nfs41_test_and_free_expired_stateid(server, |
| 2553 | &lsp->ls_stateid, |
| 2554 | cred); |
| 2555 | trace_nfs4_test_lock_stateid(state, lsp, status); |
| 2556 | if (status == -NFS4ERR_EXPIRED || |
| 2557 | status == -NFS4ERR_BAD_STATEID) { |
| 2558 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 2559 | if (!recover_lost_locks) |
| 2560 | set_bit(NFS_LOCK_LOST, &lsp->ls_flags); |
| 2561 | } else if (status != NFS_OK) { |
| 2562 | ret = status; |
| 2563 | break; |
| 2564 | } |
| 2565 | } |
| 2566 | }; |
| 2567 | out: |
| 2568 | return ret; |
| 2569 | } |
| 2570 | |
| 2571 | /** |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2572 | * nfs41_check_open_stateid - possibly free an open stateid |
| 2573 | * |
| 2574 | * @state: NFSv4 state for an inode |
| 2575 | * |
| 2576 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 2577 | * Otherwise a negative NFS4ERR value is returned. |
| 2578 | */ |
| 2579 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 2580 | { |
| 2581 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 2582 | nfs4_stateid *stateid = &state->open_stateid; |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 2583 | struct rpc_cred *cred = state->owner->so_cred; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2584 | int status; |
| 2585 | |
| 2586 | /* If a state reset has been done, test_stateid is unneeded */ |
| 2587 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 2588 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 2589 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 2590 | return -NFS4ERR_BAD_STATEID; |
| 2591 | |
Trond Myklebust | 4586f6e | 2016-09-22 13:38:57 -0400 | [diff] [blame] | 2592 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
Trond Myklebust | 08cb47f | 2013-08-20 21:59:40 -0400 | [diff] [blame] | 2593 | trace_nfs4_test_open_stateid(state, NULL, status); |
Trond Myklebust | f7a62ad | 2016-09-22 13:39:02 -0400 | [diff] [blame] | 2594 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2595 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2596 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2597 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | fd068b2 | 2013-04-22 11:29:51 -0400 | [diff] [blame] | 2598 | clear_bit(NFS_OPEN_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2599 | } |
| 2600 | return status; |
| 2601 | } |
| 2602 | |
| 2603 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 2604 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2605 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 2606 | |
Trond Myklebust | 0c116ca | 2014-11-12 14:44:49 -0500 | [diff] [blame] | 2607 | nfs41_check_delegation_stateid(state); |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 2608 | status = nfs41_check_expired_locks(state); |
| 2609 | if (status != NFS_OK) |
| 2610 | return status; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 2611 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 2612 | if (status != NFS_OK) |
| 2613 | status = nfs4_open_expired(sp, state); |
| 2614 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 2615 | } |
| 2616 | #endif |
| 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2619 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 2620 | * fields corresponding to attributes that were used to store the verifier. |
| 2621 | * Make sure we clobber those fields in the later setattr call |
| 2622 | */ |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2623 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, |
| 2624 | struct iattr *sattr, struct nfs4_label **label) |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2625 | { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2626 | const u32 *attrset = opendata->o_res.attrset; |
| 2627 | |
| 2628 | if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2629 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 2630 | sattr->ia_valid |= ATTR_ATIME; |
| 2631 | |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2632 | if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2633 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 2634 | sattr->ia_valid |= ATTR_MTIME; |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2635 | |
| 2636 | /* Except MODE, it seems harmless of setting twice. */ |
| 2637 | if ((attrset[1] & FATTR4_WORD1_MODE)) |
| 2638 | sattr->ia_valid &= ~ATTR_MODE; |
| 2639 | |
| 2640 | if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 2641 | *label = NULL; |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2644 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
| 2645 | fmode_t fmode, |
| 2646 | int flags, |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2647 | struct nfs_open_context *ctx) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2648 | { |
| 2649 | struct nfs4_state_owner *sp = opendata->owner; |
| 2650 | struct nfs_server *server = sp->so_server; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2651 | struct dentry *dentry; |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2652 | struct nfs4_state *state; |
| 2653 | unsigned int seq; |
| 2654 | int ret; |
| 2655 | |
| 2656 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
| 2657 | |
| 2658 | ret = _nfs4_proc_open(opendata); |
Trond Myklebust | dca78001 | 2014-10-23 19:23:03 +0300 | [diff] [blame] | 2659 | if (ret != 0) |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2660 | goto out; |
| 2661 | |
| 2662 | state = nfs4_opendata_to_nfs4_state(opendata); |
| 2663 | ret = PTR_ERR(state); |
| 2664 | if (IS_ERR(state)) |
| 2665 | goto out; |
| 2666 | if (server->caps & NFS_CAP_POSIX_LOCK) |
| 2667 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Jeff Layton | a8ce377 | 2016-09-17 18:17:35 -0400 | [diff] [blame] | 2668 | if (opendata->o_res.rflags & NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK) |
| 2669 | set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2670 | |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2671 | dentry = opendata->dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2672 | if (d_really_is_negative(dentry)) { |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2673 | struct dentry *alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2674 | d_drop(dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2675 | alias = d_exact_alias(dentry, state->inode); |
| 2676 | if (!alias) |
| 2677 | alias = d_splice_alias(igrab(state->inode), dentry); |
| 2678 | /* d_splice_alias() can't fail here - it's a non-directory */ |
| 2679 | if (alias) { |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2680 | dput(ctx->dentry); |
Al Viro | 668d0cd | 2016-03-08 12:44:17 -0500 | [diff] [blame] | 2681 | ctx->dentry = dentry = alias; |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2682 | } |
| 2683 | nfs_set_verifier(dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2684 | nfs_save_change_attribute(d_inode(opendata->dir))); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2687 | ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
| 2688 | if (ret != 0) |
| 2689 | goto out; |
| 2690 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2691 | ctx->state = state; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2692 | if (d_inode(dentry) == state->inode) { |
Trond Myklebust | c45ffdd | 2013-05-29 13:34:46 -0400 | [diff] [blame] | 2693 | nfs_inode_attach_open_context(ctx); |
| 2694 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 2695 | nfs4_schedule_stateid_recovery(server, state); |
| 2696 | } |
Trond Myklebust | c21443c | 2013-02-07 14:26:21 -0500 | [diff] [blame] | 2697 | out: |
| 2698 | return ret; |
| 2699 | } |
| 2700 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2701 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2702 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2704 | static int _nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2705 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2706 | int flags, |
| 2707 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2708 | struct nfs4_label *label, |
| 2709 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | { |
| 2711 | struct nfs4_state_owner *sp; |
| 2712 | struct nfs4_state *state = NULL; |
| 2713 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2714 | struct nfs4_opendata *opendata; |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2715 | struct dentry *dentry = ctx->dentry; |
| 2716 | struct rpc_cred *cred = ctx->cred; |
| 2717 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
| 2718 | fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2719 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2720 | struct nfs4_label *olabel = NULL; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2721 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | |
| 2723 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 2725 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 2726 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 2728 | goto out_err; |
| 2729 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2730 | status = nfs4_recover_expired_lease(server); |
| 2731 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 2732 | goto err_put_state_owner; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2733 | if (d_really_is_positive(dentry)) |
| 2734 | nfs4_return_incompatible_delegation(d_inode(dentry), fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 2735 | status = -ENOMEM; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2736 | if (d_really_is_positive(dentry)) |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2737 | claim = NFS4_OPEN_CLAIM_FH; |
Trond Myklebust | 4a1c089 | 2013-03-15 14:57:33 -0400 | [diff] [blame] | 2738 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2739 | label, claim, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2740 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 2741 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2743 | if (label) { |
| 2744 | olabel = nfs4_label_alloc(server, GFP_KERNEL); |
| 2745 | if (IS_ERR(olabel)) { |
| 2746 | status = PTR_ERR(olabel); |
| 2747 | goto err_opendata_put; |
| 2748 | } |
| 2749 | } |
| 2750 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2751 | if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 2752 | if (!opendata->f_attr.mdsthreshold) { |
| 2753 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 2754 | if (!opendata->f_attr.mdsthreshold) |
| 2755 | goto err_free_label; |
| 2756 | } |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 2757 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2758 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2759 | if (d_really_is_positive(dentry)) |
| 2760 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2761 | |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2762 | status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2763 | if (status != 0) |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2764 | goto err_free_label; |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2765 | state = ctx->state; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2766 | |
NeilBrown | efcbc04 | 2015-07-30 13:00:56 +1000 | [diff] [blame] | 2767 | 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] | 2768 | (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { |
Kinglong Mee | 5334c5b | 2015-08-26 21:13:37 +0800 | [diff] [blame] | 2769 | nfs4_exclusive_attrset(opendata, sattr, &label); |
Tigran Mkrtchyan | a1d1c4f | 2016-05-12 11:16:38 +0200 | [diff] [blame] | 2770 | /* |
| 2771 | * send create attributes which was not set by open |
| 2772 | * with an extra setattr. |
| 2773 | */ |
| 2774 | if (sattr->ia_valid & NFS4_VALID_ATTRS) { |
| 2775 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2776 | status = nfs4_do_setattr(state->inode, cred, |
| 2777 | opendata->o_res.f_attr, sattr, |
| 2778 | state, label, olabel); |
| 2779 | if (status == 0) { |
| 2780 | nfs_setattr_update_inode(state->inode, sattr, |
| 2781 | opendata->o_res.f_attr); |
| 2782 | nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); |
| 2783 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2784 | } |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2785 | } |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 2786 | if (opened && opendata->file_created) |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2787 | *opened |= FILE_CREATED; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2788 | |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2789 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2790 | *ctx_th = opendata->f_attr.mdsthreshold; |
Trond Myklebust | e911b81 | 2014-03-26 13:24:37 -0700 | [diff] [blame] | 2791 | opendata->f_attr.mdsthreshold = NULL; |
| 2792 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2793 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2794 | nfs4_label_free(olabel); |
| 2795 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2796 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | return 0; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 2799 | err_free_label: |
| 2800 | nfs4_label_free(olabel); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2801 | err_opendata_put: |
| 2802 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2803 | err_put_state_owner: |
| 2804 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | return status; |
| 2807 | } |
| 2808 | |
| 2809 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2810 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
Trond Myklebust | 4197a05 | 2013-05-29 12:37:49 -0400 | [diff] [blame] | 2811 | struct nfs_open_context *ctx, |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2812 | int flags, |
| 2813 | struct iattr *sattr, |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2814 | struct nfs4_label *label, |
| 2815 | int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | { |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2817 | struct nfs_server *server = NFS_SERVER(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | struct nfs4_exception exception = { }; |
| 2819 | struct nfs4_state *res; |
| 2820 | int status; |
| 2821 | |
| 2822 | do { |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 2823 | status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); |
Trond Myklebust | 3efb972 | 2013-05-29 13:17:04 -0400 | [diff] [blame] | 2824 | res = ctx->state; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 2825 | trace_nfs4_open_file(ctx, flags, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | if (status == 0) |
| 2827 | break; |
| 2828 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2829 | * book-keeping w.r.t. state-changing operations |
| 2830 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2831 | * It is actually a sign of a bug on the client or on the server. |
| 2832 | * |
| 2833 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2834 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | * have unhashed the old state_owner for us, and that we can |
| 2836 | * therefore safely retry using a new one. We should still warn |
| 2837 | * the user though... |
| 2838 | */ |
| 2839 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2840 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2841 | " returned a bad sequence-id error!\n", |
| 2842 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | exception.retry = 1; |
| 2844 | continue; |
| 2845 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2846 | /* |
| 2847 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2848 | * state before it received the OPEN_CONFIRM. |
| 2849 | * Recover by retrying the request as per the discussion |
| 2850 | * on Page 181 of RFC3530. |
| 2851 | */ |
| 2852 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2853 | exception.retry = 1; |
| 2854 | continue; |
| 2855 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2856 | if (status == -EAGAIN) { |
| 2857 | /* We must have found a delegation */ |
| 2858 | exception.retry = 1; |
| 2859 | continue; |
| 2860 | } |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 2861 | if (nfs4_clear_cap_atomic_open_v1(server, status, &exception)) |
| 2862 | continue; |
| 2863 | res = ERR_PTR(nfs4_handle_exception(server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | status, &exception)); |
| 2865 | } while (exception.retry); |
| 2866 | return res; |
| 2867 | } |
| 2868 | |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2869 | static int _nfs4_do_setattr(struct inode *inode, |
| 2870 | struct nfs_setattrargs *arg, |
| 2871 | struct nfs_setattrres *res, |
| 2872 | struct rpc_cred *cred, |
| 2873 | struct nfs4_state *state) |
| 2874 | { |
| 2875 | struct nfs_server *server = NFS_SERVER(inode); |
| 2876 | struct rpc_message msg = { |
| 2877 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2878 | .rpc_argp = arg, |
| 2879 | .rpc_resp = res, |
| 2880 | .rpc_cred = cred, |
| 2881 | }; |
| 2882 | struct rpc_cred *delegation_cred = NULL; |
| 2883 | unsigned long timestamp = jiffies; |
| 2884 | fmode_t fmode; |
| 2885 | bool truncate; |
| 2886 | int status; |
| 2887 | |
| 2888 | nfs_fattr_init(res->fattr); |
| 2889 | |
| 2890 | /* Servers should only apply open mode checks for file size changes */ |
| 2891 | truncate = (arg->iap->ia_valid & ATTR_SIZE) ? true : false; |
| 2892 | fmode = truncate ? FMODE_WRITE : FMODE_READ; |
| 2893 | |
| 2894 | if (nfs4_copy_delegation_stateid(inode, fmode, &arg->stateid, &delegation_cred)) { |
| 2895 | /* Use that stateid */ |
| 2896 | } else if (truncate && state != NULL) { |
| 2897 | struct nfs_lockowner lockowner = { |
| 2898 | .l_owner = current->files, |
| 2899 | .l_pid = current->tgid, |
| 2900 | }; |
| 2901 | if (!nfs4_valid_open_stateid(state)) |
| 2902 | return -EBADF; |
| 2903 | if (nfs4_select_rw_stateid(state, FMODE_WRITE, &lockowner, |
| 2904 | &arg->stateid, &delegation_cred) == -EIO) |
| 2905 | return -EBADF; |
| 2906 | } else |
| 2907 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
| 2908 | if (delegation_cred) |
| 2909 | msg.rpc_cred = delegation_cred; |
| 2910 | |
| 2911 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
| 2912 | |
| 2913 | put_rpccred(delegation_cred); |
| 2914 | if (status == 0 && state != NULL) |
| 2915 | renew_lease(server, timestamp); |
| 2916 | trace_nfs4_setattr(inode, &arg->stateid, status); |
| 2917 | return status; |
| 2918 | } |
| 2919 | |
| 2920 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2921 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2922 | struct nfs4_state *state, struct nfs4_label *ilabel, |
| 2923 | struct nfs4_label *olabel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2925 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2927 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | .iap = sattr, |
| 2929 | .server = server, |
| 2930 | .bitmask = server->attr_bitmask, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2931 | .label = ilabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | }; |
| 2933 | struct nfs_setattrres res = { |
| 2934 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 2935 | .label = olabel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | .server = server, |
| 2937 | }; |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2938 | struct nfs4_exception exception = { |
| 2939 | .state = state, |
| 2940 | .inode = inode, |
| 2941 | .stateid = &arg.stateid, |
| 2942 | }; |
| 2943 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 2945 | arg.bitmask = nfs4_bitmask(server, ilabel); |
| 2946 | if (ilabel) |
| 2947 | arg.bitmask = nfs4_bitmask(server, olabel); |
| 2948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | do { |
Trond Myklebust | 8487c47 | 2016-06-26 08:44:35 -0400 | [diff] [blame] | 2950 | err = _nfs4_do_setattr(inode, &arg, &res, cred, state); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2951 | switch (err) { |
| 2952 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 721ccfb | 2013-04-29 11:11:58 -0400 | [diff] [blame] | 2953 | if (!(sattr->ia_valid & ATTR_SIZE)) { |
| 2954 | pr_warn_once("NFSv4: server %s is incorrectly " |
| 2955 | "applying open mode checks to " |
| 2956 | "a SETATTR that is not " |
| 2957 | "changing file size.\n", |
| 2958 | server->nfs_client->cl_hostname); |
| 2959 | } |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2960 | if (state && !(state->state & FMODE_WRITE)) { |
| 2961 | err = -EBADF; |
| 2962 | if (sattr->ia_valid & ATTR_OPEN) |
| 2963 | err = -EACCES; |
| 2964 | goto out; |
| 2965 | } |
| 2966 | } |
| 2967 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2969 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | return err; |
| 2971 | } |
| 2972 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 2973 | static bool |
| 2974 | nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) |
| 2975 | { |
| 2976 | if (inode == NULL || !nfs_have_layout(inode)) |
| 2977 | return false; |
| 2978 | |
| 2979 | return pnfs_wait_on_layoutreturn(inode, task); |
| 2980 | } |
| 2981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | struct nfs4_closedata { |
| 2983 | struct inode *inode; |
| 2984 | struct nfs4_state *state; |
| 2985 | struct nfs_closeargs arg; |
| 2986 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2987 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2988 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2989 | bool roc; |
| 2990 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | }; |
| 2992 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2993 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2994 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2995 | struct nfs4_closedata *calldata = data; |
| 2996 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2997 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2998 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2999 | if (calldata->roc) |
| 3000 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3001 | nfs4_put_open_state(calldata->state); |
| 3002 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3003 | nfs4_put_state_owner(sp); |
Trond Myklebust | 322b2b9 | 2013-01-11 16:39:51 -0500 | [diff] [blame] | 3004 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3005 | kfree(calldata); |
| 3006 | } |
| 3007 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3008 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3010 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3013 | nfs4_stateid *res_stateid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3015 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3016 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3017 | return; |
Trond Myklebust | 42113a7 | 2013-08-12 16:19:27 -0400 | [diff] [blame] | 3018 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | /* hmm. we are done with the inode, and in the process of freeing |
| 3020 | * the state_owner. we keep this around to process errors |
| 3021 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | switch (task->tk_status) { |
| 3023 | case 0: |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3024 | res_stateid = &calldata->res.stateid; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3025 | if (calldata->roc) |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 3026 | pnfs_roc_set_barrier(state->inode, |
| 3027 | calldata->roc_barrier); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3028 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 412f6c4 | 2014-08-25 22:09:08 -0400 | [diff] [blame] | 3029 | break; |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3030 | case -NFS4ERR_ADMIN_REVOKED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 3032 | case -NFS4ERR_EXPIRED: |
| 3033 | nfs4_free_revoked_stateid(server, |
| 3034 | &calldata->arg.stateid, |
| 3035 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3036 | case -NFS4ERR_OLD_STATEID: |
| 3037 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3038 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3039 | &state->open_stateid)) { |
Trond Myklebust | 566fcec | 2015-01-23 15:32:46 -0500 | [diff] [blame] | 3040 | rpc_restart_call_prepare(task); |
| 3041 | goto out_release; |
| 3042 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3043 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3044 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 3046 | if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3047 | rpc_restart_call_prepare(task); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3048 | goto out_release; |
| 3049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | } |
Trond Myklebust | 4a1e2fe | 2015-08-30 18:37:59 -0700 | [diff] [blame] | 3051 | nfs_clear_open_stateid(state, &calldata->arg.stateid, |
| 3052 | res_stateid, calldata->arg.fmode); |
Trond Myklebust | 69794ad | 2013-11-20 12:57:19 -0500 | [diff] [blame] | 3053 | out_release: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 3054 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3055 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3056 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3059 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3061 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3062 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3063 | struct inode *inode = calldata->inode; |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3064 | bool is_rdonly, is_wronly, is_rdwr; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3065 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3066 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3067 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3068 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3069 | goto out_wait; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3070 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3071 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3072 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | aee7af3 | 2014-08-25 22:33:12 -0400 | [diff] [blame] | 3073 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 3074 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 3075 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
Anna Schumaker | 369d6b7 | 2015-03-02 16:46:09 -0500 | [diff] [blame] | 3076 | nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 3077 | /* Calculate the change in open mode */ |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3078 | calldata->arg.fmode = 0; |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 3079 | if (state->n_rdwr == 0) { |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3080 | if (state->n_rdonly == 0) |
| 3081 | call_close |= is_rdonly; |
| 3082 | else if (is_rdonly) |
| 3083 | calldata->arg.fmode |= FMODE_READ; |
| 3084 | if (state->n_wronly == 0) |
| 3085 | call_close |= is_wronly; |
| 3086 | else if (is_wronly) |
| 3087 | calldata->arg.fmode |= FMODE_WRITE; |
Trond Myklebust | e547f26 | 2016-06-25 19:19:28 -0400 | [diff] [blame] | 3088 | if (calldata->arg.fmode != (FMODE_READ|FMODE_WRITE)) |
| 3089 | call_close |= is_rdwr; |
Trond Myklebust | cd9288f | 2014-09-18 11:51:32 -0400 | [diff] [blame] | 3090 | } else if (is_rdwr) |
| 3091 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
| 3092 | |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 3093 | if (!nfs4_valid_open_stateid(state)) |
| 3094 | call_close = 0; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 3095 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3096 | |
| 3097 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3098 | /* Note: exit _without_ calling nfs4_close_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3099 | goto out_no_action; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3100 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3101 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 3102 | if (nfs4_wait_on_layoutreturn(inode, task)) { |
| 3103 | nfs_release_seqid(calldata->arg.seqid); |
| 3104 | goto out_wait; |
| 3105 | } |
| 3106 | |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3107 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3108 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Trond Myklebust | 3c13cb5 | 2015-08-18 23:45:13 -0500 | [diff] [blame] | 3109 | if (calldata->roc) |
| 3110 | pnfs_roc_get_barrier(inode, &calldata->roc_barrier); |
| 3111 | |
Trond Myklebust | 6ae3733 | 2015-01-30 14:21:14 -0500 | [diff] [blame] | 3112 | calldata->arg.share_access = |
| 3113 | nfs4_map_atomic_open_share(NFS_SERVER(inode), |
| 3114 | calldata->arg.fmode, 0); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 3115 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3116 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3117 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 3118 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3119 | &calldata->arg.seq_args, |
| 3120 | &calldata->res.seq_res, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 3121 | task) != 0) |
| 3122 | nfs_release_seqid(calldata->arg.seqid); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 3123 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 3124 | return; |
| 3125 | out_no_action: |
| 3126 | task->tk_action = NULL; |
| 3127 | out_wait: |
| 3128 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3131 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3132 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3133 | .rpc_call_done = nfs4_close_done, |
| 3134 | .rpc_release = nfs4_free_closedata, |
| 3135 | }; |
| 3136 | |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3137 | static bool nfs4_roc(struct inode *inode) |
| 3138 | { |
Trond Myklebust | 40dd4b7 | 2015-01-24 13:54:37 -0500 | [diff] [blame] | 3139 | if (!nfs_have_layout(inode)) |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3140 | return false; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3141 | return pnfs_roc(inode); |
| 3142 | } |
| 3143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | /* |
| 3145 | * It is possible for data to be read/written from a mem-mapped file |
| 3146 | * after the sys_close call (which hits the vfs layer as a flush). |
| 3147 | * This means that we can't safely call nfsv4 close on a file until |
| 3148 | * the inode is cleared. This in turn means that we are not good |
| 3149 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 3150 | * share state even when we are done with one of the three share |
| 3151 | * stateid's in the inode. |
| 3152 | * |
| 3153 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 3154 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 3155 | 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] | 3156 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3157 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3158 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3160 | struct nfs4_state_owner *sp = state->owner; |
| 3161 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3162 | struct rpc_message msg = { |
| 3163 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 3164 | .rpc_cred = state->owner->so_cred, |
| 3165 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3166 | struct rpc_task_setup task_setup_data = { |
| 3167 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3168 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3169 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3170 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3171 | .flags = RPC_TASK_ASYNC, |
| 3172 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3173 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 3175 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP, |
| 3176 | &task_setup_data.rpc_client, &msg); |
| 3177 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3178 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3180 | goto out; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3181 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3182 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 3184 | calldata->arg.fh = NFS_FH(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | /* Serialization for the sequence id */ |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 3186 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 3187 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 3188 | if (IS_ERR(calldata->arg.seqid)) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3189 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 3190 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3191 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3192 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3193 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 3194 | calldata->res.server = server; |
Peng Tao | fe08c54 | 2014-07-03 13:05:01 +0800 | [diff] [blame] | 3195 | calldata->roc = nfs4_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3196 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3197 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3198 | msg.rpc_argp = &calldata->arg; |
| 3199 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3200 | task_setup_data.callback_data = calldata; |
| 3201 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3202 | if (IS_ERR(task)) |
| 3203 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3204 | status = 0; |
| 3205 | if (wait) |
| 3206 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3207 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 3208 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3209 | out_free_calldata: |
| 3210 | kfree(calldata); |
| 3211 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 3212 | nfs4_put_open_state(state); |
| 3213 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 3214 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3217 | static struct inode * |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3218 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, |
| 3219 | int open_flags, struct iattr *attr, int *opened) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | struct nfs4_state *state; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3222 | struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
| 3223 | |
| 3224 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 3226 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | 5bc2afc | 2013-09-23 18:01:28 -0400 | [diff] [blame] | 3227 | state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3228 | |
| 3229 | nfs4_label_release_security(label); |
| 3230 | |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 3231 | if (IS_ERR(state)) |
| 3232 | return ERR_CAST(state); |
Trond Myklebust | 275bb30 | 2013-05-29 13:11:28 -0400 | [diff] [blame] | 3233 | return state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 3236 | 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] | 3237 | { |
| 3238 | if (ctx->state == NULL) |
| 3239 | return; |
| 3240 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3241 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3242 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 3243 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 3244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3246 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
| 3247 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
J. Bruce Fields | 999e568 | 2014-06-03 17:33:35 -0400 | [diff] [blame] | 3248 | #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL) |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 3251 | { |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3252 | u32 bitmask[3] = {}, minorversion = server->nfs_client->cl_minorversion; |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3253 | struct nfs4_server_caps_arg args = { |
| 3254 | .fhandle = fhandle, |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3255 | .bitmask = bitmask, |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3256 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | struct nfs4_server_caps_res res = {}; |
| 3258 | struct rpc_message msg = { |
| 3259 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 3260 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | .rpc_resp = &res, |
| 3262 | }; |
| 3263 | int status; |
| 3264 | |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3265 | bitmask[0] = FATTR4_WORD0_SUPPORTED_ATTRS | |
| 3266 | FATTR4_WORD0_FH_EXPIRE_TYPE | |
| 3267 | FATTR4_WORD0_LINK_SUPPORT | |
| 3268 | FATTR4_WORD0_SYMLINK_SUPPORT | |
| 3269 | FATTR4_WORD0_ACLSUPPORT; |
| 3270 | if (minorversion) |
| 3271 | bitmask[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT; |
| 3272 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3273 | 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] | 3274 | if (status == 0) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3275 | /* Sanity check the server answers */ |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3276 | switch (minorversion) { |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3277 | case 0: |
| 3278 | res.attr_bitmask[1] &= FATTR4_WORD1_NFS40_MASK; |
| 3279 | res.attr_bitmask[2] = 0; |
| 3280 | break; |
| 3281 | case 1: |
| 3282 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS41_MASK; |
| 3283 | break; |
| 3284 | case 2: |
| 3285 | res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; |
| 3286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3288 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 3289 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 3290 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 3291 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3292 | NFS_CAP_CTIME|NFS_CAP_MTIME| |
| 3293 | NFS_CAP_SECURITY_LABEL); |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 3294 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && |
| 3295 | res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | server->caps |= NFS_CAP_ACLS; |
| 3297 | if (res.has_links != 0) |
| 3298 | server->caps |= NFS_CAP_HARDLINKS; |
| 3299 | if (res.has_symlinks != 0) |
| 3300 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3301 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 3302 | server->caps |= NFS_CAP_FILEID; |
| 3303 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 3304 | server->caps |= NFS_CAP_MODE; |
| 3305 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 3306 | server->caps |= NFS_CAP_NLINK; |
| 3307 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 3308 | server->caps |= NFS_CAP_OWNER; |
| 3309 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 3310 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 3311 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 3312 | server->caps |= NFS_CAP_ATIME; |
| 3313 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 3314 | server->caps |= NFS_CAP_CTIME; |
| 3315 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 3316 | server->caps |= NFS_CAP_MTIME; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3317 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 3318 | if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) |
| 3319 | server->caps |= NFS_CAP_SECURITY_LABEL; |
| 3320 | #endif |
| 3321 | memcpy(server->attr_bitmask_nl, res.attr_bitmask, |
| 3322 | sizeof(server->attr_bitmask)); |
Trond Myklebust | b944dba | 2013-11-04 15:20:20 -0500 | [diff] [blame] | 3323 | server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 3324 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3325 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 3326 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 3327 | 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] | 3328 | server->cache_consistency_bitmask[2] = 0; |
Kinglong Mee | 8c61282 | 2015-08-26 21:12:58 +0800 | [diff] [blame] | 3329 | memcpy(server->exclcreat_bitmask, res.exclcreat_bitmask, |
| 3330 | sizeof(server->exclcreat_bitmask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 3332 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | return status; |
| 3336 | } |
| 3337 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 3338 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | { |
| 3340 | struct nfs4_exception exception = { }; |
| 3341 | int err; |
| 3342 | do { |
| 3343 | err = nfs4_handle_exception(server, |
| 3344 | _nfs4_server_capabilities(server, fhandle), |
| 3345 | &exception); |
| 3346 | } while (exception.retry); |
| 3347 | return err; |
| 3348 | } |
| 3349 | |
| 3350 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3351 | struct nfs_fsinfo *info) |
| 3352 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3353 | u32 bitmask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | struct nfs4_lookup_root_arg args = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3355 | .bitmask = bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | }; |
| 3357 | struct nfs4_lookup_res res = { |
| 3358 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3359 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | .fh = fhandle, |
| 3361 | }; |
| 3362 | struct rpc_message msg = { |
| 3363 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 3364 | .rpc_argp = &args, |
| 3365 | .rpc_resp = &res, |
| 3366 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 3367 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3368 | bitmask[0] = nfs4_fattr_bitmap[0]; |
| 3369 | bitmask[1] = nfs4_fattr_bitmap[1]; |
| 3370 | /* |
| 3371 | * Process the label in the upcoming getfattr |
| 3372 | */ |
| 3373 | bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL; |
| 3374 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3375 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3376 | 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] | 3377 | } |
| 3378 | |
| 3379 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3380 | struct nfs_fsinfo *info) |
| 3381 | { |
| 3382 | struct nfs4_exception exception = { }; |
| 3383 | int err; |
| 3384 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3385 | err = _nfs4_lookup_root(server, fhandle, info); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3386 | trace_nfs4_lookup_root(server, fhandle, info->fattr, err); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3387 | switch (err) { |
| 3388 | case 0: |
| 3389 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3390 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3391 | default: |
| 3392 | err = nfs4_handle_exception(server, err, &exception); |
| 3393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 3395 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | return err; |
| 3397 | } |
| 3398 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3399 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3400 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 3401 | { |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3402 | struct rpc_auth_create_args auth_args = { |
| 3403 | .pseudoflavor = flavor, |
| 3404 | }; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3405 | struct rpc_auth *auth; |
| 3406 | int ret; |
| 3407 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 3408 | auth = rpcauth_create(&auth_args, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 3409 | if (IS_ERR(auth)) { |
Chuck Lever | 75bc882 | 2013-03-16 15:55:36 -0400 | [diff] [blame] | 3410 | ret = -EACCES; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3411 | goto out; |
| 3412 | } |
| 3413 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3414 | out: |
| 3415 | return ret; |
| 3416 | } |
| 3417 | |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3418 | /* |
| 3419 | * Retry pseudoroot lookup with various security flavors. We do this when: |
| 3420 | * |
| 3421 | * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC |
| 3422 | * NFSv4.1: the server does not support the SECINFO_NO_NAME operation |
| 3423 | * |
| 3424 | * Returns zero on success, or a negative NFS4ERR value, or a |
| 3425 | * negative errno value. |
| 3426 | */ |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3427 | 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] | 3428 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | { |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3430 | /* Per 3530bis 15.33.5 */ |
| 3431 | static const rpc_authflavor_t flav_array[] = { |
| 3432 | RPC_AUTH_GSS_KRB5P, |
| 3433 | RPC_AUTH_GSS_KRB5I, |
| 3434 | RPC_AUTH_GSS_KRB5, |
Chuck Lever | c4eafe1 | 2013-03-16 15:56:11 -0400 | [diff] [blame] | 3435 | RPC_AUTH_UNIX, /* courtesy */ |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3436 | RPC_AUTH_NULL, |
| 3437 | }; |
| 3438 | int status = -EPERM; |
| 3439 | size_t i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 3441 | if (server->auth_info.flavor_len > 0) { |
| 3442 | /* try each flavor specified by user */ |
| 3443 | for (i = 0; i < server->auth_info.flavor_len; i++) { |
| 3444 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3445 | server->auth_info.flavors[i]); |
| 3446 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3447 | continue; |
| 3448 | break; |
| 3449 | } |
| 3450 | } else { |
| 3451 | /* no flavors specified by user, try default list */ |
| 3452 | for (i = 0; i < ARRAY_SIZE(flav_array); i++) { |
| 3453 | status = nfs4_lookup_root_sec(server, fhandle, info, |
| 3454 | flav_array[i]); |
| 3455 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
| 3456 | continue; |
| 3457 | break; |
| 3458 | } |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 3459 | } |
Chuck Lever | 9a744ba | 2013-03-16 15:56:02 -0400 | [diff] [blame] | 3460 | |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 3461 | /* |
| 3462 | * -EACCESS could mean that the user doesn't have correct permissions |
| 3463 | * to access the mount. It could also mean that we tried to mount |
| 3464 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 3465 | * existing mount programs don't handle -EACCES very well so it should |
| 3466 | * be mapped to -EPERM instead. |
| 3467 | */ |
| 3468 | if (status == -EACCES) |
| 3469 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3470 | return status; |
| 3471 | } |
| 3472 | |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3473 | /** |
| 3474 | * nfs4_proc_get_rootfh - get file handle for server's pseudoroot |
| 3475 | * @server: initialized nfs_server handle |
| 3476 | * @fhandle: we fill in the pseudo-fs root file handle |
| 3477 | * @info: we fill in an FSINFO struct |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3478 | * @auth_probe: probe the auth flavours |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3479 | * |
| 3480 | * Returns zero on success, or a negative errno. |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3481 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 3482 | 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] | 3483 | struct nfs_fsinfo *info, |
| 3484 | bool auth_probe) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 3485 | { |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3486 | int status = 0; |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3487 | |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3488 | if (!auth_probe) |
Trond Myklebust | 5e6b199 | 2013-09-07 12:58:57 -0400 | [diff] [blame] | 3489 | status = nfs4_lookup_root(server, fhandle, info); |
Andre Przywara | c775707 | 2015-04-23 17:17:40 +0100 | [diff] [blame] | 3490 | |
| 3491 | if (auth_probe || status == NFS4ERR_WRONGSEC) |
Trond Myklebust | 698c937 | 2016-07-25 13:31:14 -0400 | [diff] [blame] | 3492 | status = server->nfs_client->cl_mvops->find_root_sec(server, |
| 3493 | fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | if (status == 0) |
| 3496 | status = nfs4_server_capabilities(server, fhandle); |
| 3497 | if (status == 0) |
| 3498 | status = nfs4_do_fsinfo(server, fhandle, info); |
Chuck Lever | 2ed4b95b | 2013-03-16 15:55:45 -0400 | [diff] [blame] | 3499 | |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 3500 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3503 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 3504 | struct nfs_fsinfo *info) |
| 3505 | { |
| 3506 | int error; |
| 3507 | struct nfs_fattr *fattr = info->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3508 | struct nfs4_label *label = NULL; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3509 | |
| 3510 | error = nfs4_server_capabilities(server, mntfh); |
| 3511 | if (error < 0) { |
| 3512 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 3513 | return error; |
| 3514 | } |
| 3515 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3516 | label = nfs4_label_alloc(server, GFP_KERNEL); |
| 3517 | if (IS_ERR(label)) |
| 3518 | return PTR_ERR(label); |
| 3519 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3520 | error = nfs4_proc_getattr(server, mntfh, fattr, label); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3521 | if (error < 0) { |
| 3522 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3523 | goto err_free_label; |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 3527 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 3528 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 3529 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3530 | err_free_label: |
| 3531 | nfs4_label_free(label); |
| 3532 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 3533 | return error; |
| 3534 | } |
| 3535 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3536 | /* |
| 3537 | * Get locations and (maybe) other attributes of a referral. |
| 3538 | * Note that we'll actually follow the referral later when |
| 3539 | * we detect fsid mismatch in inode revalidation |
| 3540 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3541 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 3542 | const struct qstr *name, struct nfs_fattr *fattr, |
| 3543 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3544 | { |
| 3545 | int status = -ENOMEM; |
| 3546 | struct page *page = NULL; |
| 3547 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3548 | |
| 3549 | page = alloc_page(GFP_KERNEL); |
| 3550 | if (page == NULL) |
| 3551 | goto out; |
| 3552 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 3553 | if (locations == NULL) |
| 3554 | goto out; |
| 3555 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3556 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3557 | if (status != 0) |
| 3558 | goto out; |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3559 | |
| 3560 | /* |
| 3561 | * If the fsid didn't change, this is a migration event, not a |
| 3562 | * referral. Cause us to drop into the exception handler, which |
| 3563 | * will kick off migration recovery. |
| 3564 | */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3565 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3566 | dprintk("%s: server did not return a different fsid for" |
| 3567 | " a referral at %s\n", __func__, name->name); |
Chuck Lever | 519ae25 | 2013-10-17 14:13:19 -0400 | [diff] [blame] | 3568 | status = -NFS4ERR_MOVED; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3569 | goto out; |
| 3570 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3571 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 3572 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3573 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 3574 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3575 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3576 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 3577 | out: |
| 3578 | if (page) |
| 3579 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 3580 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 3581 | return status; |
| 3582 | } |
| 3583 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3584 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3585 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | { |
| 3587 | struct nfs4_getattr_arg args = { |
| 3588 | .fh = fhandle, |
| 3589 | .bitmask = server->attr_bitmask, |
| 3590 | }; |
| 3591 | struct nfs4_getattr_res res = { |
| 3592 | .fattr = fattr, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3593 | .label = label, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | .server = server, |
| 3595 | }; |
| 3596 | struct rpc_message msg = { |
| 3597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 3598 | .rpc_argp = &args, |
| 3599 | .rpc_resp = &res, |
| 3600 | }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3601 | |
| 3602 | args.bitmask = nfs4_bitmask(server, label); |
| 3603 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3604 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3605 | 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] | 3606 | } |
| 3607 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3608 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3609 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | { |
| 3611 | struct nfs4_exception exception = { }; |
| 3612 | int err; |
| 3613 | do { |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 3614 | err = _nfs4_proc_getattr(server, fhandle, fattr, label); |
| 3615 | trace_nfs4_getattr(server, fhandle, fattr, err); |
| 3616 | err = nfs4_handle_exception(server, err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | &exception); |
| 3618 | } while (exception.retry); |
| 3619 | return err; |
| 3620 | } |
| 3621 | |
| 3622 | /* |
| 3623 | * The file is not closed if it is opened due to the a request to change |
| 3624 | * the size of the file. The open call will not be needed once the |
| 3625 | * VFS layer lookup-intents are implemented. |
| 3626 | * |
| 3627 | * Close is called when the inode is destroyed. |
| 3628 | * If we haven't opened the file for O_WRONLY, we |
| 3629 | * need to in the size_change case to obtain a stateid. |
| 3630 | * |
| 3631 | * Got race? |
| 3632 | * Because OPEN is always done by name in nfsv4, it is |
| 3633 | * possible that we opened a different file by the same |
| 3634 | * name. We can recognize this race condition, but we |
| 3635 | * can't do anything about it besides returning an error. |
| 3636 | * |
| 3637 | * This will be fixed with VFS changes (lookup-intent). |
| 3638 | */ |
| 3639 | static int |
| 3640 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 3641 | struct iattr *sattr) |
| 3642 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3643 | struct inode *inode = d_inode(dentry); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3644 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3645 | struct nfs4_state *state = NULL; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3646 | struct nfs4_label *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | int status; |
| 3648 | |
Peng Tao | 88ac815 | 2014-09-12 11:04:10 +0800 | [diff] [blame] | 3649 | if (pnfs_ld_layoutret_on_setattr(inode) && |
| 3650 | sattr->ia_valid & ATTR_SIZE && |
| 3651 | sattr->ia_size < i_size_read(inode)) |
Trond Myklebust | 2402867 | 2013-03-20 13:23:33 -0400 | [diff] [blame] | 3652 | pnfs_commit_and_return_layout(inode); |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 3653 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3654 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3656 | /* Deal with open(O_TRUNC) */ |
| 3657 | if (sattr->ia_valid & ATTR_OPEN) |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3658 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME); |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3659 | |
| 3660 | /* Optimization: if the end result is no change, don't RPC */ |
Nadav Shemer | cc7936f | 2013-07-21 17:21:43 +0300 | [diff] [blame] | 3661 | if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 3662 | return 0; |
| 3663 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 3664 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3665 | if (sattr->ia_valid & ATTR_FILE) { |
| 3666 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 3667 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3668 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 3669 | if (ctx) { |
| 3670 | cred = ctx->cred; |
| 3671 | state = ctx->state; |
| 3672 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 3673 | } |
| 3674 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3675 | label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 3676 | if (IS_ERR(label)) |
| 3677 | return PTR_ERR(label); |
| 3678 | |
| 3679 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3680 | if (status == 0) { |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 3681 | nfs_setattr_update_inode(inode, sattr, fattr); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3682 | nfs_setsecurity(inode, fattr, label); |
| 3683 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 3684 | nfs4_label_free(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | return status; |
| 3686 | } |
| 3687 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3688 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 3689 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3690 | struct nfs_fattr *fattr, struct nfs4_label *label) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3691 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3692 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3693 | int status; |
| 3694 | struct nfs4_lookup_arg args = { |
| 3695 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3696 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3697 | .name = name, |
| 3698 | }; |
| 3699 | struct nfs4_lookup_res res = { |
| 3700 | .server = server, |
| 3701 | .fattr = fattr, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3702 | .label = label, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3703 | .fh = fhandle, |
| 3704 | }; |
| 3705 | struct rpc_message msg = { |
| 3706 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 3707 | .rpc_argp = &args, |
| 3708 | .rpc_resp = &res, |
| 3709 | }; |
| 3710 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3711 | args.bitmask = nfs4_bitmask(server, label); |
| 3712 | |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3713 | nfs_fattr_init(fattr); |
| 3714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3716 | 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] | 3717 | dprintk("NFS reply lookup: %d\n", status); |
| 3718 | return status; |
| 3719 | } |
| 3720 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3721 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3722 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3723 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3724 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 3725 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 3726 | fattr->nlink = 2; |
| 3727 | } |
| 3728 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3729 | 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] | 3730 | const struct qstr *name, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3731 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3732 | { |
| 3733 | struct nfs4_exception exception = { }; |
| 3734 | struct rpc_clnt *client = *clnt; |
| 3735 | int err; |
| 3736 | do { |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3737 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3738 | trace_nfs4_lookup(dir, name, err); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3739 | switch (err) { |
| 3740 | case -NFS4ERR_BADNAME: |
| 3741 | err = -ENOENT; |
| 3742 | goto out; |
| 3743 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3744 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Dominique Martinet | c86c90c | 2015-06-04 17:04:17 +0200 | [diff] [blame] | 3745 | if (err == -NFS4ERR_MOVED) |
| 3746 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3747 | goto out; |
| 3748 | case -NFS4ERR_WRONGSEC: |
| 3749 | err = -EPERM; |
| 3750 | if (client != *clnt) |
| 3751 | goto out; |
Andy Adamson | 66b0686 | 2014-06-12 15:02:32 -0400 | [diff] [blame] | 3752 | client = nfs4_negotiate_security(client, dir, name); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3753 | if (IS_ERR(client)) |
| 3754 | return PTR_ERR(client); |
| 3755 | |
| 3756 | exception.retry = 1; |
| 3757 | break; |
| 3758 | default: |
| 3759 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 3760 | } |
| 3761 | } while (exception.retry); |
| 3762 | |
| 3763 | out: |
| 3764 | if (err == 0) |
| 3765 | *clnt = client; |
| 3766 | else if (client != *clnt) |
| 3767 | rpc_shutdown_client(client); |
| 3768 | |
| 3769 | return err; |
| 3770 | } |
| 3771 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3772 | static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3773 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 3774 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3776 | int status; |
| 3777 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 3778 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3779 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 3780 | if (client != NFS_CLIENT(dir)) { |
| 3781 | rpc_shutdown_client(client); |
| 3782 | nfs_fixup_secinfo_attributes(fattr); |
| 3783 | } |
| 3784 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3787 | struct rpc_clnt * |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3788 | nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3789 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 3790 | { |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3791 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3792 | int status; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3793 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 3794 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3795 | if (status < 0) |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3796 | return ERR_PTR(status); |
Trond Myklebust | b72888c | 2013-08-07 20:38:07 -0400 | [diff] [blame] | 3797 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 3798 | } |
| 3799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3801 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3802 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | struct nfs4_accessargs args = { |
| 3804 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 3805 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3807 | struct nfs4_accessres res = { |
| 3808 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 3809 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | struct rpc_message msg = { |
| 3811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 3812 | .rpc_argp = &args, |
| 3813 | .rpc_resp = &res, |
| 3814 | .rpc_cred = entry->cred, |
| 3815 | }; |
| 3816 | int mode = entry->mask; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3817 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | |
| 3819 | /* |
| 3820 | * Determine which access bits we want to ask for... |
| 3821 | */ |
| 3822 | if (mode & MAY_READ) |
| 3823 | args.access |= NFS4_ACCESS_READ; |
| 3824 | if (S_ISDIR(inode->i_mode)) { |
| 3825 | if (mode & MAY_WRITE) |
| 3826 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 3827 | if (mode & MAY_EXEC) |
| 3828 | args.access |= NFS4_ACCESS_LOOKUP; |
| 3829 | } else { |
| 3830 | if (mode & MAY_WRITE) |
| 3831 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 3832 | if (mode & MAY_EXEC) |
| 3833 | args.access |= NFS4_ACCESS_EXECUTE; |
| 3834 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3835 | |
| 3836 | res.fattr = nfs_alloc_fattr(); |
| 3837 | if (res.fattr == NULL) |
| 3838 | return -ENOMEM; |
| 3839 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3840 | 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] | 3841 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 3842 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3843 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3845 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | return status; |
| 3847 | } |
| 3848 | |
| 3849 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 3850 | { |
| 3851 | struct nfs4_exception exception = { }; |
| 3852 | int err; |
| 3853 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3854 | err = _nfs4_proc_access(inode, entry); |
| 3855 | trace_nfs4_access(inode, err); |
| 3856 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | &exception); |
| 3858 | } while (exception.retry); |
| 3859 | return err; |
| 3860 | } |
| 3861 | |
| 3862 | /* |
| 3863 | * TODO: For the time being, we don't try to get any attributes |
| 3864 | * along with any of the zero-copy operations READ, READDIR, |
| 3865 | * READLINK, WRITE. |
| 3866 | * |
| 3867 | * In the case of the first three, we want to put the GETATTR |
| 3868 | * after the read-type operation -- this is because it is hard |
| 3869 | * to predict the length of a GETATTR response in v4, and thus |
| 3870 | * align the READ data correctly. This means that the GETATTR |
| 3871 | * may end up partially falling into the page cache, and we should |
| 3872 | * shift it into the 'tail' of the xdr_buf before processing. |
| 3873 | * To do this efficiently, we need to know the total length |
| 3874 | * of data received, which doesn't seem to be available outside |
| 3875 | * of the RPC layer. |
| 3876 | * |
| 3877 | * In the case of WRITE, we also want to put the GETATTR after |
| 3878 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 3879 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | * |
| 3881 | * Both of these changes to the XDR layer would in fact be quite |
| 3882 | * minor, but I decided to leave them for a subsequent patch. |
| 3883 | */ |
| 3884 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3885 | unsigned int pgbase, unsigned int pglen) |
| 3886 | { |
| 3887 | struct nfs4_readlink args = { |
| 3888 | .fh = NFS_FH(inode), |
| 3889 | .pgbase = pgbase, |
| 3890 | .pglen = pglen, |
| 3891 | .pages = &page, |
| 3892 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3893 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | struct rpc_message msg = { |
| 3895 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 3896 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 3897 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | }; |
| 3899 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3900 | 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] | 3901 | } |
| 3902 | |
| 3903 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 3904 | unsigned int pgbase, unsigned int pglen) |
| 3905 | { |
| 3906 | struct nfs4_exception exception = { }; |
| 3907 | int err; |
| 3908 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 3909 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
| 3910 | trace_nfs4_readlink(inode, err); |
| 3911 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | &exception); |
| 3913 | } while (exception.retry); |
| 3914 | return err; |
| 3915 | } |
| 3916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3918 | * 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] | 3919 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | static int |
| 3921 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3922 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3924 | struct nfs4_label l, *ilabel = NULL; |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3925 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | int status = 0; |
| 3928 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3929 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 3930 | if (IS_ERR(ctx)) |
| 3931 | return PTR_ERR(ctx); |
| 3932 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3933 | ilabel = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 3934 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3935 | sattr->ia_mode &= ~current_umask(); |
Kinglong Mee | c5c3fb5 | 2015-08-26 21:11:39 +0800 | [diff] [blame] | 3936 | state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | if (IS_ERR(state)) { |
| 3938 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 3939 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | out: |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3942 | nfs4_label_release_security(ilabel); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 3943 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | return status; |
| 3945 | } |
| 3946 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3947 | static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3949 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3950 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 3952 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3954 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3955 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3956 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3958 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3959 | .rpc_argp = &args, |
| 3960 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3962 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3963 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3964 | 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] | 3965 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3966 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | return status; |
| 3968 | } |
| 3969 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 3970 | static int nfs4_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | { |
| 3972 | struct nfs4_exception exception = { }; |
| 3973 | int err; |
| 3974 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 3975 | err = _nfs4_proc_remove(dir, name); |
| 3976 | trace_nfs4_remove(dir, name, err); |
| 3977 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | &exception); |
| 3979 | } while (exception.retry); |
| 3980 | return err; |
| 3981 | } |
| 3982 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3983 | 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] | 3984 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3985 | struct nfs_server *server = NFS_SERVER(dir); |
| 3986 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3987 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3989 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 3991 | nfs4_init_sequence(&args->seq_args, &res->seq_res, 1); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 3992 | |
| 3993 | nfs_fattr_init(res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3996 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3997 | { |
Al Viro | 884be17 | 2016-04-28 23:56:31 -0400 | [diff] [blame] | 3998 | nfs4_setup_sequence(NFS_SB(data->dentry->d_sb), |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 3999 | &data->args.seq_args, |
| 4000 | &data->res.seq_res, |
| 4001 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4004 | 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] | 4005 | { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4006 | struct nfs_unlinkdata *data = task->tk_calldata; |
| 4007 | struct nfs_removeres *res = &data->res; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4008 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4009 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4010 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4011 | if (nfs4_async_handle_error(task, res->server, NULL, |
| 4012 | &data->timeout) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4013 | return 0; |
| 4014 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 4015 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4018 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 4019 | { |
| 4020 | struct nfs_server *server = NFS_SERVER(dir); |
| 4021 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 4022 | struct nfs_renameres *res = msg->rpc_resp; |
| 4023 | |
| 4024 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4025 | res->server = server; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4026 | nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4027 | } |
| 4028 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 4029 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 4030 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4031 | nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 4032 | &data->args.seq_args, |
| 4033 | &data->res.seq_res, |
| 4034 | task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 4038 | struct inode *new_dir) |
| 4039 | { |
Trond Myklebust | fbc6f7c | 2013-08-12 17:08:26 -0400 | [diff] [blame] | 4040 | struct nfs_renamedata *data = task->tk_calldata; |
| 4041 | struct nfs_renameres *res = &data->res; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4042 | |
| 4043 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 4044 | return 0; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4045 | if (nfs4_async_handle_error(task, res->server, NULL, &data->timeout) == -EAGAIN) |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4046 | return 0; |
| 4047 | |
| 4048 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4049 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 4050 | return 1; |
| 4051 | } |
| 4052 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4053 | 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] | 4054 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4055 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | struct nfs4_link_arg arg = { |
| 4057 | .fh = NFS_FH(inode), |
| 4058 | .dir_fh = NFS_FH(dir), |
| 4059 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4060 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4062 | struct nfs4_link_res res = { |
| 4063 | .server = server, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4064 | .label = NULL, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4065 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | struct rpc_message msg = { |
| 4067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 4068 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4069 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4071 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4073 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 4074 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4075 | goto out; |
| 4076 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4077 | res.label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4078 | if (IS_ERR(res.label)) { |
| 4079 | status = PTR_ERR(res.label); |
| 4080 | goto out; |
| 4081 | } |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4082 | arg.bitmask = nfs4_bitmask(server, res.label); |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4083 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4084 | 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] | 4085 | if (!status) { |
| 4086 | update_changeattr(dir, &res.cinfo); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4087 | status = nfs_post_op_update_inode(inode, res.fattr); |
| 4088 | if (!status) |
| 4089 | nfs_setsecurity(inode, res.fattr, res.label); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 4090 | } |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4091 | |
| 4092 | |
| 4093 | nfs4_label_free(res.label); |
| 4094 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4095 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 4096 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | return status; |
| 4098 | } |
| 4099 | |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4100 | 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] | 4101 | { |
| 4102 | struct nfs4_exception exception = { }; |
| 4103 | int err; |
| 4104 | do { |
| 4105 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4106 | _nfs4_proc_link(inode, dir, name), |
| 4107 | &exception); |
| 4108 | } while (exception.retry); |
| 4109 | return err; |
| 4110 | } |
| 4111 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4112 | struct nfs4_createdata { |
| 4113 | struct rpc_message msg; |
| 4114 | struct nfs4_create_arg arg; |
| 4115 | struct nfs4_create_res res; |
| 4116 | struct nfs_fh fh; |
| 4117 | struct nfs_fattr fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4118 | struct nfs4_label *label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4119 | }; |
| 4120 | |
| 4121 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 4122 | const struct qstr *name, struct iattr *sattr, u32 ftype) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4123 | { |
| 4124 | struct nfs4_createdata *data; |
| 4125 | |
| 4126 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 4127 | if (data != NULL) { |
| 4128 | struct nfs_server *server = NFS_SERVER(dir); |
| 4129 | |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4130 | data->label = nfs4_label_alloc(server, GFP_KERNEL); |
| 4131 | if (IS_ERR(data->label)) |
| 4132 | goto out_free; |
| 4133 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4134 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 4135 | data->msg.rpc_argp = &data->arg; |
| 4136 | data->msg.rpc_resp = &data->res; |
| 4137 | data->arg.dir_fh = NFS_FH(dir); |
| 4138 | data->arg.server = server; |
| 4139 | data->arg.name = name; |
| 4140 | data->arg.attrs = sattr; |
| 4141 | data->arg.ftype = ftype; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4142 | data->arg.bitmask = nfs4_bitmask(server, data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4143 | data->res.server = server; |
| 4144 | data->res.fh = &data->fh; |
| 4145 | data->res.fattr = &data->fattr; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4146 | data->res.label = data->label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4147 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4148 | } |
| 4149 | return data; |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4150 | out_free: |
| 4151 | kfree(data); |
| 4152 | return NULL; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 4156 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4157 | 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] | 4158 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4159 | if (status == 0) { |
| 4160 | update_changeattr(dir, &data->res.dir_cinfo); |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4161 | 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] | 4162 | } |
| 4163 | return status; |
| 4164 | } |
| 4165 | |
| 4166 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 4167 | { |
David Quigley | 14c43f7 | 2013-05-22 12:50:43 -0400 | [diff] [blame] | 4168 | nfs4_label_free(data->label); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4169 | kfree(data); |
| 4170 | } |
| 4171 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4172 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4173 | struct page *page, unsigned int len, struct iattr *sattr, |
| 4174 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4176 | struct nfs4_createdata *data; |
| 4177 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4179 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4180 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4181 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4182 | status = -ENOMEM; |
| 4183 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 4184 | if (data == NULL) |
| 4185 | goto out; |
| 4186 | |
| 4187 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 4188 | data->arg.u.symlink.pages = &page; |
| 4189 | data->arg.u.symlink.len = len; |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4190 | data->arg.label = label; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4192 | status = nfs4_do_create(dir, dentry, data); |
| 4193 | |
| 4194 | nfs4_free_createdata(data); |
| 4195 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | return status; |
| 4197 | } |
| 4198 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 4199 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 4200 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | { |
| 4202 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4203 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | int err; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4205 | |
| 4206 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4209 | err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label); |
| 4210 | trace_nfs4_symlink(dir, &dentry->d_name, err); |
| 4211 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | &exception); |
| 4213 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4214 | |
| 4215 | nfs4_label_release_security(label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | return err; |
| 4217 | } |
| 4218 | |
| 4219 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4220 | struct iattr *sattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4222 | struct nfs4_createdata *data; |
| 4223 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4225 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 4226 | if (data == NULL) |
| 4227 | goto out; |
| 4228 | |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4229 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4230 | status = nfs4_do_create(dir, dentry, data); |
| 4231 | |
| 4232 | nfs4_free_createdata(data); |
| 4233 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | return status; |
| 4235 | } |
| 4236 | |
| 4237 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 4238 | struct iattr *sattr) |
| 4239 | { |
| 4240 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4241 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4243 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4244 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4245 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4246 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4248 | err = _nfs4_proc_mkdir(dir, dentry, sattr, label); |
| 4249 | trace_nfs4_mkdir(dir, &dentry->d_name, err); |
| 4250 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | &exception); |
| 4252 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4253 | nfs4_label_release_security(label); |
| 4254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | return err; |
| 4256 | } |
| 4257 | |
| 4258 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4259 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4261 | struct inode *dir = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | struct nfs4_readdir_arg args = { |
| 4263 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4264 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | .pgbase = 0, |
| 4266 | .count = count, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4267 | .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 4268 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | }; |
| 4270 | struct nfs4_readdir_res res; |
| 4271 | struct rpc_message msg = { |
| 4272 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 4273 | .rpc_argp = &args, |
| 4274 | .rpc_resp = &res, |
| 4275 | .rpc_cred = cred, |
| 4276 | }; |
| 4277 | int status; |
| 4278 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 4279 | dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, |
| 4280 | dentry, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 4281 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4282 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4284 | 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] | 4285 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 4286 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 4287 | status += args.pgbase; |
| 4288 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 4289 | |
| 4290 | nfs_invalidate_atime(dir); |
| 4291 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4292 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | return status; |
| 4294 | } |
| 4295 | |
| 4296 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 4297 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | { |
| 4299 | struct nfs4_exception exception = { }; |
| 4300 | int err; |
| 4301 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 4302 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
| 4303 | pages, count, plus); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 4304 | trace_nfs4_readdir(d_inode(dentry), err); |
| 4305 | err = nfs4_handle_exception(NFS_SERVER(d_inode(dentry)), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | &exception); |
| 4307 | } while (exception.retry); |
| 4308 | return err; |
| 4309 | } |
| 4310 | |
| 4311 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4312 | struct iattr *sattr, struct nfs4_label *label, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4314 | struct nfs4_createdata *data; |
| 4315 | int mode = sattr->ia_mode; |
| 4316 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4318 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 4319 | if (data == NULL) |
| 4320 | goto out; |
| 4321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4323 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4325 | data->arg.ftype = NF4BLK; |
| 4326 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4327 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | } |
| 4329 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4330 | data->arg.ftype = NF4CHR; |
| 4331 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 4332 | data->arg.u.device.specdata2 = MINOR(rdev); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4333 | } else if (!S_ISSOCK(mode)) { |
| 4334 | status = -EINVAL; |
| 4335 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | } |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 4337 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4338 | data->arg.label = label; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4339 | status = nfs4_do_create(dir, dentry, data); |
Trond Myklebust | 4ea8fed | 2012-10-15 15:47:41 -0400 | [diff] [blame] | 4340 | out_free: |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 4341 | nfs4_free_createdata(data); |
| 4342 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | return status; |
| 4344 | } |
| 4345 | |
| 4346 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 4347 | struct iattr *sattr, dev_t rdev) |
| 4348 | { |
| 4349 | struct nfs4_exception exception = { }; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4350 | struct nfs4_label l, *label = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4352 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4353 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
| 4354 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 4355 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 4357 | err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev); |
| 4358 | trace_nfs4_mknod(dir, &dentry->d_name, err); |
| 4359 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | &exception); |
| 4361 | } while (exception.retry); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 4362 | |
| 4363 | nfs4_label_release_security(label); |
| 4364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | return err; |
| 4366 | } |
| 4367 | |
| 4368 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4369 | struct nfs_fsstat *fsstat) |
| 4370 | { |
| 4371 | struct nfs4_statfs_arg args = { |
| 4372 | .fh = fhandle, |
| 4373 | .bitmask = server->attr_bitmask, |
| 4374 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4375 | struct nfs4_statfs_res res = { |
| 4376 | .fsstat = fsstat, |
| 4377 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | struct rpc_message msg = { |
| 4379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 4380 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 4381 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | }; |
| 4383 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4384 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4385 | 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] | 4386 | } |
| 4387 | |
| 4388 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 4389 | { |
| 4390 | struct nfs4_exception exception = { }; |
| 4391 | int err; |
| 4392 | do { |
| 4393 | err = nfs4_handle_exception(server, |
| 4394 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 4395 | &exception); |
| 4396 | } while (exception.retry); |
| 4397 | return err; |
| 4398 | } |
| 4399 | |
| 4400 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4401 | struct nfs_fsinfo *fsinfo) |
| 4402 | { |
| 4403 | struct nfs4_fsinfo_arg args = { |
| 4404 | .fh = fhandle, |
| 4405 | .bitmask = server->attr_bitmask, |
| 4406 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4407 | struct nfs4_fsinfo_res res = { |
| 4408 | .fsinfo = fsinfo, |
| 4409 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | struct rpc_message msg = { |
| 4411 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 4412 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 4413 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | }; |
| 4415 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4416 | 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] | 4417 | } |
| 4418 | |
| 4419 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4420 | { |
| 4421 | struct nfs4_exception exception = { }; |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4422 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | int err; |
| 4424 | |
| 4425 | do { |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4426 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
Trond Myklebust | b5f875a | 2013-08-13 13:01:39 -0400 | [diff] [blame] | 4427 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4428 | if (err == 0) { |
Trond Myklebust | fb10fb6 | 2016-08-05 19:13:08 -0400 | [diff] [blame] | 4429 | nfs4_set_lease_period(server->nfs_client, |
| 4430 | fsinfo->lease_time * HZ, |
| 4431 | now); |
Chuck Lever | 83ca7f5 | 2013-03-16 15:55:53 -0400 | [diff] [blame] | 4432 | break; |
| 4433 | } |
| 4434 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } while (exception.retry); |
| 4436 | return err; |
| 4437 | } |
| 4438 | |
| 4439 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 4440 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4441 | int error; |
| 4442 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4443 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4444 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4445 | if (error == 0) { |
| 4446 | /* block layout checks this! */ |
| 4447 | server->pnfs_blksize = fsinfo->blksize; |
Jeff Layton | ca440c3 | 2016-09-15 14:40:49 -0400 | [diff] [blame] | 4448 | set_pnfs_layoutdriver(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 4449 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 4450 | |
| 4451 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4455 | struct nfs_pathconf *pathconf) |
| 4456 | { |
| 4457 | struct nfs4_pathconf_arg args = { |
| 4458 | .fh = fhandle, |
| 4459 | .bitmask = server->attr_bitmask, |
| 4460 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4461 | struct nfs4_pathconf_res res = { |
| 4462 | .pathconf = pathconf, |
| 4463 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | struct rpc_message msg = { |
| 4465 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 4466 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 4467 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | }; |
| 4469 | |
| 4470 | /* None of the pathconf attributes are mandatory to implement */ |
| 4471 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 4472 | memset(pathconf, 0, sizeof(*pathconf)); |
| 4473 | return 0; |
| 4474 | } |
| 4475 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 4476 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4477 | 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] | 4478 | } |
| 4479 | |
| 4480 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 4481 | struct nfs_pathconf *pathconf) |
| 4482 | { |
| 4483 | struct nfs4_exception exception = { }; |
| 4484 | int err; |
| 4485 | |
| 4486 | do { |
| 4487 | err = nfs4_handle_exception(server, |
| 4488 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 4489 | &exception); |
| 4490 | } while (exception.retry); |
| 4491 | return err; |
| 4492 | } |
| 4493 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4494 | int nfs4_set_rw_stateid(nfs4_stateid *stateid, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4495 | const struct nfs_open_context *ctx, |
| 4496 | const struct nfs_lock_context *l_ctx, |
| 4497 | fmode_t fmode) |
| 4498 | { |
| 4499 | const struct nfs_lockowner *lockowner = NULL; |
| 4500 | |
| 4501 | if (l_ctx != NULL) |
| 4502 | lockowner = &l_ctx->lockowner; |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 4503 | return nfs4_select_rw_stateid(ctx->state, fmode, lockowner, stateid, NULL); |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4504 | } |
| 4505 | EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid); |
| 4506 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4507 | static bool nfs4_stateid_is_current(nfs4_stateid *stateid, |
| 4508 | const struct nfs_open_context *ctx, |
| 4509 | const struct nfs_lock_context *l_ctx, |
| 4510 | fmode_t fmode) |
| 4511 | { |
| 4512 | nfs4_stateid current_stateid; |
| 4513 | |
Trond Myklebust | e1253be | 2014-03-05 08:44:23 -0500 | [diff] [blame] | 4514 | /* If the current stateid represents a lost lock, then exit */ |
| 4515 | if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
| 4516 | return true; |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4517 | return nfs4_stateid_match(stateid, ¤t_stateid); |
| 4518 | } |
| 4519 | |
| 4520 | static bool nfs4_error_stateid_expired(int err) |
| 4521 | { |
| 4522 | switch (err) { |
| 4523 | case -NFS4ERR_DELEG_REVOKED: |
| 4524 | case -NFS4ERR_ADMIN_REVOKED: |
| 4525 | case -NFS4ERR_BAD_STATEID: |
| 4526 | case -NFS4ERR_STALE_STATEID: |
| 4527 | case -NFS4ERR_OLD_STATEID: |
| 4528 | case -NFS4ERR_OPENMODE: |
| 4529 | case -NFS4ERR_EXPIRED: |
| 4530 | return true; |
| 4531 | } |
| 4532 | return false; |
| 4533 | } |
| 4534 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4535 | void __nfs4_read_done_cb(struct nfs_pgio_header *hdr) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4536 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4537 | nfs_invalidate_atime(hdr->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 4538 | } |
| 4539 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4540 | 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] | 4541 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4542 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4544 | trace_nfs4_read(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4545 | if (task->tk_status < 0) { |
| 4546 | struct nfs4_exception exception = { |
| 4547 | .inode = hdr->inode, |
| 4548 | .state = hdr->args.context->state, |
| 4549 | .stateid = &hdr->args.stateid, |
| 4550 | }; |
| 4551 | task->tk_status = nfs4_async_handle_exception(task, |
| 4552 | server, task->tk_status, &exception); |
| 4553 | if (exception.retry) { |
| 4554 | rpc_restart_call_prepare(task); |
| 4555 | return -EAGAIN; |
| 4556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 4558 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4559 | __nfs4_read_done_cb(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | if (task->tk_status > 0) |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4561 | renew_lease(server, hdr->timestamp); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4562 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | } |
| 4564 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4565 | static bool nfs4_read_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4566 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4567 | { |
| 4568 | |
| 4569 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4570 | nfs4_stateid_is_current(&args->stateid, |
| 4571 | args->context, |
| 4572 | args->lock_context, |
| 4573 | FMODE_READ)) |
| 4574 | return false; |
| 4575 | rpc_restart_call_prepare(task); |
| 4576 | return true; |
| 4577 | } |
| 4578 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4579 | 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] | 4580 | { |
| 4581 | |
| 4582 | dprintk("--> %s\n", __func__); |
| 4583 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4584 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4585 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4586 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4587 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4588 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4589 | nfs4_read_done_cb(task, hdr); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4592 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
| 4593 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4595 | hdr->timestamp = jiffies; |
Trond Myklebust | ca857cc | 2016-06-28 13:54:09 -0400 | [diff] [blame] | 4596 | if (!hdr->pgio_done_cb) |
| 4597 | hdr->pgio_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4598 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4599 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4602 | static int nfs4_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 4603 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 4604 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4605 | if (nfs4_setup_sequence(NFS_SERVER(hdr->inode), |
| 4606 | &hdr->args.seq_args, |
| 4607 | &hdr->res.seq_res, |
Trond Myklebust | 9b20614 | 2013-03-17 15:52:00 -0400 | [diff] [blame] | 4608 | task)) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4609 | return 0; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4610 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 4611 | hdr->args.lock_context, |
| 4612 | hdr->rw_ops->rw_mode) == -EIO) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4613 | return -EIO; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4614 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 4615 | return -EIO; |
| 4616 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4619 | static int nfs4_write_done_cb(struct rpc_task *task, |
| 4620 | struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4622 | struct inode *inode = hdr->inode; |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4623 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4624 | trace_nfs4_write(hdr, task->tk_status); |
Trond Myklebust | 9c27869 | 2016-09-22 13:39:11 -0400 | [diff] [blame] | 4625 | if (task->tk_status < 0) { |
| 4626 | struct nfs4_exception exception = { |
| 4627 | .inode = hdr->inode, |
| 4628 | .state = hdr->args.context->state, |
| 4629 | .stateid = &hdr->args.stateid, |
| 4630 | }; |
| 4631 | task->tk_status = nfs4_async_handle_exception(task, |
| 4632 | NFS_SERVER(inode), task->tk_status, |
| 4633 | &exception); |
| 4634 | if (exception.retry) { |
| 4635 | rpc_restart_call_prepare(task); |
| 4636 | return -EAGAIN; |
| 4637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4639 | if (task->tk_status >= 0) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4640 | renew_lease(NFS_SERVER(inode), hdr->timestamp); |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 4641 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4642 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4643 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4646 | static bool nfs4_write_stateid_changed(struct rpc_task *task, |
Anna Schumaker | 3c6b899 | 2014-05-06 09:12:24 -0400 | [diff] [blame] | 4647 | struct nfs_pgio_args *args) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4648 | { |
| 4649 | |
| 4650 | if (!nfs4_error_stateid_expired(task->tk_status) || |
| 4651 | nfs4_stateid_is_current(&args->stateid, |
| 4652 | args->context, |
| 4653 | args->lock_context, |
| 4654 | FMODE_WRITE)) |
| 4655 | return false; |
| 4656 | rpc_restart_call_prepare(task); |
| 4657 | return true; |
| 4658 | } |
| 4659 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4660 | 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] | 4661 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4662 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4663 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4664 | if (nfs4_write_stateid_changed(task, &hdr->args)) |
Trond Myklebust | 5521abf | 2013-03-16 20:54:34 -0400 | [diff] [blame] | 4665 | return -EAGAIN; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4666 | return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) : |
| 4667 | nfs4_write_done_cb(task, hdr); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4670 | static |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4671 | bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4672 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4673 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4674 | if (hdr->ds_clp != NULL || hdr->dreq != NULL) |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4675 | return false; |
| 4676 | /* Otherwise, request attributes if and only if we don't hold |
| 4677 | * a delegation |
| 4678 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 4679 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4680 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 4681 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4682 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
| 4683 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4685 | struct nfs_server *server = NFS_SERVER(hdr->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4686 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4687 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
| 4688 | hdr->args.bitmask = NULL; |
| 4689 | hdr->res.fattr = NULL; |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 4690 | } else |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4691 | hdr->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 4692 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4693 | if (!hdr->pgio_done_cb) |
| 4694 | hdr->pgio_done_cb = nfs4_write_done_cb; |
| 4695 | hdr->res.server = server; |
| 4696 | hdr->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4698 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 4699 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4702 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 4703 | { |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 4704 | nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 4705 | &data->args.seq_args, |
| 4706 | &data->res.seq_res, |
| 4707 | task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4710 | 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] | 4711 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4713 | |
Trond Myklebust | cc668ab | 2013-08-14 15:31:28 -0400 | [diff] [blame] | 4714 | trace_nfs4_commit(data, task->tk_status); |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 4715 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), |
| 4716 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4717 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4718 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4720 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4723 | 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] | 4724 | { |
| 4725 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4726 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4727 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4730 | 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] | 4731 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 4732 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 4733 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 4734 | if (data->commit_done_cb == NULL) |
| 4735 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 4736 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 4737 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 4738 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4741 | struct nfs4_renewdata { |
| 4742 | struct nfs_client *client; |
| 4743 | unsigned long timestamp; |
| 4744 | }; |
| 4745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | /* |
| 4747 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 4748 | * standalone procedure for queueing an asynchronous RENEW. |
| 4749 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4750 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4751 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4752 | struct nfs4_renewdata *data = calldata; |
| 4753 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4754 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4755 | if (atomic_read(&clp->cl_count) > 1) |
| 4756 | nfs4_schedule_state_renewal(clp); |
| 4757 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4758 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4759 | } |
| 4760 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4761 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4763 | struct nfs4_renewdata *data = calldata; |
| 4764 | struct nfs_client *clp = data->client; |
| 4765 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 4767 | trace_nfs4_renew_async(clp, task->tk_status); |
Chuck Lever | f8aba1e | 2013-10-17 14:13:53 -0400 | [diff] [blame] | 4768 | switch (task->tk_status) { |
| 4769 | case 0: |
| 4770 | break; |
| 4771 | case -NFS4ERR_LEASE_MOVED: |
| 4772 | nfs4_schedule_lease_moved_recovery(clp); |
| 4773 | break; |
| 4774 | default: |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 4775 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4776 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 4777 | return; |
| 4778 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4779 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4780 | return; |
| 4781 | } |
| 4782 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4784 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4787 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 4788 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 4789 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4790 | }; |
| 4791 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4792 | 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] | 4793 | { |
| 4794 | struct rpc_message msg = { |
| 4795 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4796 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4797 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4799 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4801 | if (renew_flags == 0) |
| 4802 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 4803 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 4804 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 4805 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4806 | if (data == NULL) |
| 4807 | return -ENOMEM; |
| 4808 | data->client = clp; |
| 4809 | data->timestamp = jiffies; |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4810 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 4811 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 4814 | 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] | 4815 | { |
| 4816 | struct rpc_message msg = { |
| 4817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 4818 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 4819 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | }; |
| 4821 | unsigned long now = jiffies; |
| 4822 | int status; |
| 4823 | |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 4824 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | if (status < 0) |
| 4826 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4827 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | return 0; |
| 4829 | } |
| 4830 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4831 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 4832 | { |
Malahal Naineni | 7dd7d95 | 2014-01-23 08:54:55 -0600 | [diff] [blame] | 4833 | return server->caps & NFS_CAP_ACLS; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4836 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 4837 | * 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] | 4838 | * the stack. |
| 4839 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4840 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4841 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4842 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 4843 | struct page **pages) |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4844 | { |
| 4845 | struct page *newpage, **spages; |
| 4846 | int rc = 0; |
| 4847 | size_t len; |
| 4848 | spages = pages; |
| 4849 | |
| 4850 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4851 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4852 | newpage = alloc_page(GFP_KERNEL); |
| 4853 | |
| 4854 | if (newpage == NULL) |
| 4855 | goto unwind; |
| 4856 | memcpy(page_address(newpage), buf, len); |
| 4857 | buf += len; |
| 4858 | buflen -= len; |
| 4859 | *pages++ = newpage; |
| 4860 | rc++; |
| 4861 | } while (buflen != 0); |
| 4862 | |
| 4863 | return rc; |
| 4864 | |
| 4865 | unwind: |
| 4866 | for(; rc > 0; rc--) |
| 4867 | __free_page(spages[rc-1]); |
| 4868 | return -ENOMEM; |
| 4869 | } |
| 4870 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4871 | struct nfs4_cached_acl { |
| 4872 | int cached; |
| 4873 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 4874 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4875 | }; |
| 4876 | |
| 4877 | 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] | 4878 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4879 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4880 | |
| 4881 | spin_lock(&inode->i_lock); |
| 4882 | kfree(nfsi->nfs4_acl); |
| 4883 | nfsi->nfs4_acl = acl; |
| 4884 | spin_unlock(&inode->i_lock); |
| 4885 | } |
| 4886 | |
| 4887 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 4888 | { |
| 4889 | nfs4_set_cached_acl(inode, NULL); |
| 4890 | } |
| 4891 | |
| 4892 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 4893 | { |
| 4894 | struct nfs_inode *nfsi = NFS_I(inode); |
| 4895 | struct nfs4_cached_acl *acl; |
| 4896 | int ret = -ENOENT; |
| 4897 | |
| 4898 | spin_lock(&inode->i_lock); |
| 4899 | acl = nfsi->nfs4_acl; |
| 4900 | if (acl == NULL) |
| 4901 | goto out; |
| 4902 | if (buf == NULL) /* user is just asking for length */ |
| 4903 | goto out_len; |
| 4904 | if (acl->cached == 0) |
| 4905 | goto out; |
| 4906 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 4907 | if (acl->len > buflen) |
| 4908 | goto out; |
| 4909 | memcpy(buf, acl->data, acl->len); |
| 4910 | out_len: |
| 4911 | ret = acl->len; |
| 4912 | out: |
| 4913 | spin_unlock(&inode->i_lock); |
| 4914 | return ret; |
| 4915 | } |
| 4916 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4917 | 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] | 4918 | { |
| 4919 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4920 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4921 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4922 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 4923 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4924 | if (acl == NULL) |
| 4925 | goto out; |
| 4926 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 4927 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4928 | } else { |
| 4929 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 4930 | if (acl == NULL) |
| 4931 | goto out; |
| 4932 | acl->cached = 0; |
| 4933 | } |
| 4934 | acl->len = acl_len; |
| 4935 | out: |
| 4936 | nfs4_set_cached_acl(inode, acl); |
| 4937 | } |
| 4938 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4939 | /* |
| 4940 | * The getxattr API returns the required buffer length when called with a |
| 4941 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 4942 | * the required buf. On a NULL buf, we send a page of data to the server |
| 4943 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 4944 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 4945 | * the cache. If not so, we throw away the page, and cache the required |
| 4946 | * length. The next getxattr call will then produce another round trip to |
| 4947 | * the server, this time with the input buf of the required size. |
| 4948 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4949 | 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] | 4950 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4951 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4952 | struct nfs_getaclargs args = { |
| 4953 | .fh = NFS_FH(inode), |
| 4954 | .acl_pages = pages, |
| 4955 | .acl_len = buflen, |
| 4956 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4957 | struct nfs_getaclres res = { |
| 4958 | .acl_len = buflen, |
| 4959 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4960 | struct rpc_message msg = { |
| 4961 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 4962 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 4963 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4964 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4965 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 4966 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4967 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4968 | /* As long as we're doing a round trip to the server anyway, |
| 4969 | * let's be prepared for a page of acl data. */ |
| 4970 | if (npages == 0) |
| 4971 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4972 | if (npages > ARRAY_SIZE(pages)) |
| 4973 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4974 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4975 | for (i = 0; i < npages; i++) { |
| 4976 | pages[i] = alloc_page(GFP_KERNEL); |
| 4977 | if (!pages[i]) |
| 4978 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4979 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4980 | |
| 4981 | /* for decoding across pages */ |
| 4982 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 4983 | if (!res.acl_scratch) |
| 4984 | goto out_free; |
| 4985 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4986 | args.acl_len = npages * PAGE_SIZE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 4987 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 4988 | 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] | 4989 | __func__, buf, buflen, npages, args.acl_len); |
| 4990 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 4991 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4992 | if (ret) |
| 4993 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 4994 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 4995 | /* Handle the case where the passed-in buffer is too short */ |
| 4996 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 4997 | /* Did the user only issue a request for the acl length? */ |
| 4998 | if (buf == NULL) |
| 4999 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5000 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5001 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5002 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5003 | 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] | 5004 | if (buf) { |
| 5005 | if (res.acl_len > buflen) { |
| 5006 | ret = -ERANGE; |
| 5007 | goto out_free; |
| 5008 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5009 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
Sven Wegener | 7d3e91a | 2012-12-08 15:30:18 +0100 | [diff] [blame] | 5010 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 5011 | out_ok: |
| 5012 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5013 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5014 | for (i = 0; i < npages; i++) |
| 5015 | if (pages[i]) |
| 5016 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 5017 | if (res.acl_scratch) |
| 5018 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5019 | return ret; |
| 5020 | } |
| 5021 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5022 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 5023 | { |
| 5024 | struct nfs4_exception exception = { }; |
| 5025 | ssize_t ret; |
| 5026 | do { |
| 5027 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5028 | trace_nfs4_get_acl(inode, ret); |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5029 | if (ret >= 0) |
| 5030 | break; |
| 5031 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 5032 | } while (exception.retry); |
| 5033 | return ret; |
| 5034 | } |
| 5035 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5036 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 5037 | { |
| 5038 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5039 | int ret; |
| 5040 | |
| 5041 | if (!nfs4_server_supports_acls(server)) |
| 5042 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5043 | ret = nfs_revalidate_inode(server, inode); |
| 5044 | if (ret < 0) |
| 5045 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5046 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 5047 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5048 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 5049 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 5050 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 5051 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5052 | return ret; |
| 5053 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5056 | 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] | 5057 | { |
| 5058 | struct nfs_server *server = NFS_SERVER(inode); |
| 5059 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 5060 | struct nfs_setaclargs arg = { |
| 5061 | .fh = NFS_FH(inode), |
| 5062 | .acl_pages = pages, |
| 5063 | .acl_len = buflen, |
| 5064 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5065 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5066 | struct rpc_message msg = { |
| 5067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 5068 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 5069 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5070 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5071 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5072 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5073 | |
| 5074 | if (!nfs4_server_supports_acls(server)) |
| 5075 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 5076 | if (npages > ARRAY_SIZE(pages)) |
| 5077 | return -ERANGE; |
Andreas Gruenbacher | 8fbcf23 | 2015-11-03 18:25:34 +0100 | [diff] [blame] | 5078 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 5079 | if (i < 0) |
| 5080 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 5081 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5082 | 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] | 5083 | |
| 5084 | /* |
| 5085 | * Free each page after tx, so the only ref left is |
| 5086 | * held by the network stack |
| 5087 | */ |
| 5088 | for (; i > 0; i--) |
| 5089 | put_page(pages[i-1]); |
| 5090 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 5091 | /* |
| 5092 | * Acl update can result in inode attribute update. |
| 5093 | * so mark the attribute cache invalid. |
| 5094 | */ |
| 5095 | spin_lock(&inode->i_lock); |
| 5096 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 5097 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 5098 | nfs_access_zap_cache(inode); |
| 5099 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5100 | return ret; |
| 5101 | } |
| 5102 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5103 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 5104 | { |
| 5105 | struct nfs4_exception exception = { }; |
| 5106 | int err; |
| 5107 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5108 | err = __nfs4_proc_set_acl(inode, buf, buflen); |
| 5109 | trace_nfs4_set_acl(inode, err); |
| 5110 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 5111 | &exception); |
| 5112 | } while (exception.retry); |
| 5113 | return err; |
| 5114 | } |
| 5115 | |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5116 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 5117 | static int _nfs4_get_security_label(struct inode *inode, void *buf, |
| 5118 | size_t buflen) |
| 5119 | { |
| 5120 | struct nfs_server *server = NFS_SERVER(inode); |
| 5121 | struct nfs_fattr fattr; |
| 5122 | struct nfs4_label label = {0, 0, buflen, buf}; |
| 5123 | |
| 5124 | u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5125 | struct nfs4_getattr_arg arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5126 | .fh = NFS_FH(inode), |
| 5127 | .bitmask = bitmask, |
| 5128 | }; |
| 5129 | struct nfs4_getattr_res res = { |
| 5130 | .fattr = &fattr, |
| 5131 | .label = &label, |
| 5132 | .server = server, |
| 5133 | }; |
| 5134 | struct rpc_message msg = { |
| 5135 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5136 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5137 | .rpc_resp = &res, |
| 5138 | }; |
| 5139 | int ret; |
| 5140 | |
| 5141 | nfs_fattr_init(&fattr); |
| 5142 | |
Trond Myklebust | fcb63a9 | 2013-11-01 12:42:25 -0400 | [diff] [blame] | 5143 | 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] | 5144 | if (ret) |
| 5145 | return ret; |
| 5146 | if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) |
| 5147 | return -ENOENT; |
| 5148 | if (buflen < label.len) |
| 5149 | return -ERANGE; |
| 5150 | return 0; |
| 5151 | } |
| 5152 | |
| 5153 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
| 5154 | size_t buflen) |
| 5155 | { |
| 5156 | struct nfs4_exception exception = { }; |
| 5157 | int err; |
| 5158 | |
| 5159 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5160 | return -EOPNOTSUPP; |
| 5161 | |
| 5162 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5163 | err = _nfs4_get_security_label(inode, buf, buflen); |
| 5164 | trace_nfs4_get_security_label(inode, err); |
| 5165 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5166 | &exception); |
| 5167 | } while (exception.retry); |
| 5168 | return err; |
| 5169 | } |
| 5170 | |
| 5171 | static int _nfs4_do_set_security_label(struct inode *inode, |
| 5172 | struct nfs4_label *ilabel, |
| 5173 | struct nfs_fattr *fattr, |
| 5174 | struct nfs4_label *olabel) |
| 5175 | { |
| 5176 | |
| 5177 | struct iattr sattr = {0}; |
| 5178 | struct nfs_server *server = NFS_SERVER(inode); |
| 5179 | const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5180 | struct nfs_setattrargs arg = { |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5181 | .fh = NFS_FH(inode), |
| 5182 | .iap = &sattr, |
| 5183 | .server = server, |
| 5184 | .bitmask = bitmask, |
| 5185 | .label = ilabel, |
| 5186 | }; |
| 5187 | struct nfs_setattrres res = { |
| 5188 | .fattr = fattr, |
| 5189 | .label = olabel, |
| 5190 | .server = server, |
| 5191 | }; |
| 5192 | struct rpc_message msg = { |
| 5193 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5194 | .rpc_argp = &arg, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5195 | .rpc_resp = &res, |
| 5196 | }; |
| 5197 | int status; |
| 5198 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5199 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5200 | |
Jeff Layton | 12207f6 | 2013-11-01 10:49:32 -0400 | [diff] [blame] | 5201 | 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] | 5202 | if (status) |
| 5203 | dprintk("%s failed: %d\n", __func__, status); |
| 5204 | |
| 5205 | return status; |
| 5206 | } |
| 5207 | |
| 5208 | static int nfs4_do_set_security_label(struct inode *inode, |
| 5209 | struct nfs4_label *ilabel, |
| 5210 | struct nfs_fattr *fattr, |
| 5211 | struct nfs4_label *olabel) |
| 5212 | { |
| 5213 | struct nfs4_exception exception = { }; |
| 5214 | int err; |
| 5215 | |
| 5216 | do { |
Trond Myklebust | c1578b7 | 2013-08-12 16:58:42 -0400 | [diff] [blame] | 5217 | err = _nfs4_do_set_security_label(inode, ilabel, |
| 5218 | fattr, olabel); |
| 5219 | trace_nfs4_set_security_label(inode, err); |
| 5220 | err = nfs4_handle_exception(NFS_SERVER(inode), err, |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5221 | &exception); |
| 5222 | } while (exception.retry); |
| 5223 | return err; |
| 5224 | } |
| 5225 | |
| 5226 | static int |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 5227 | 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] | 5228 | { |
| 5229 | struct nfs4_label ilabel, *olabel = NULL; |
| 5230 | struct nfs_fattr fattr; |
| 5231 | struct rpc_cred *cred; |
David Quigley | aa9c266 | 2013-05-22 12:50:44 -0400 | [diff] [blame] | 5232 | int status; |
| 5233 | |
| 5234 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
| 5235 | return -EOPNOTSUPP; |
| 5236 | |
| 5237 | nfs_fattr_init(&fattr); |
| 5238 | |
| 5239 | ilabel.pi = 0; |
| 5240 | ilabel.lfs = 0; |
| 5241 | ilabel.label = (char *)buf; |
| 5242 | ilabel.len = buflen; |
| 5243 | |
| 5244 | cred = rpc_lookup_cred(); |
| 5245 | if (IS_ERR(cred)) |
| 5246 | return PTR_ERR(cred); |
| 5247 | |
| 5248 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
| 5249 | if (IS_ERR(olabel)) { |
| 5250 | status = -PTR_ERR(olabel); |
| 5251 | goto out; |
| 5252 | } |
| 5253 | |
| 5254 | status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel); |
| 5255 | if (status == 0) |
| 5256 | nfs_setsecurity(inode, &fattr, olabel); |
| 5257 | |
| 5258 | nfs4_label_free(olabel); |
| 5259 | out: |
| 5260 | put_rpccred(cred); |
| 5261 | return status; |
| 5262 | } |
| 5263 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
| 5264 | |
| 5265 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5266 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 5267 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5268 | { |
| 5269 | __be32 verf[2]; |
| 5270 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5271 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 5272 | /* An impossible timestamp guarantees this value |
| 5273 | * will never match a generated boot time. */ |
| 5274 | verf[0] = 0; |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5275 | verf[1] = cpu_to_be32(NSEC_PER_SEC + 1); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5276 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5277 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 5278 | verf[0] = cpu_to_be32(nn->boot_time.tv_sec); |
| 5279 | verf[1] = cpu_to_be32(nn->boot_time.tv_nsec); |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 5280 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5281 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 5282 | } |
| 5283 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5284 | static int |
| 5285 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5286 | { |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5287 | size_t len; |
| 5288 | char *str; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5289 | |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5290 | if (clp->cl_owner_id != NULL) |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5291 | return 0; |
Kinglong Mee | 4a3e577 | 2015-08-31 10:53:43 +0800 | [diff] [blame] | 5292 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5293 | rcu_read_lock(); |
Kinglong Mee | 4a70316 | 2015-08-31 10:53:33 +0800 | [diff] [blame] | 5294 | len = 14 + strlen(clp->cl_ipaddr) + 1 + |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5295 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
| 5296 | 1 + |
| 5297 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)) + |
| 5298 | 1; |
| 5299 | rcu_read_unlock(); |
| 5300 | |
| 5301 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5302 | return -EINVAL; |
| 5303 | |
| 5304 | /* |
| 5305 | * Since this string is allocated at mount time, and held until the |
| 5306 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5307 | * about a memory-reclaim deadlock. |
| 5308 | */ |
| 5309 | str = kmalloc(len, GFP_KERNEL); |
| 5310 | if (!str) |
| 5311 | return -ENOMEM; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5312 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5313 | rcu_read_lock(); |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5314 | scnprintf(str, len, "Linux NFSv4.0 %s/%s %s", |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5315 | clp->cl_ipaddr, |
| 5316 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
| 5317 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_PROTO)); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5318 | rcu_read_unlock(); |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5319 | |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5320 | clp->cl_owner_id = str; |
| 5321 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5322 | } |
| 5323 | |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5324 | static int |
| 5325 | nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5326 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5327 | size_t len; |
| 5328 | char *str; |
| 5329 | |
| 5330 | len = 10 + 10 + 1 + 10 + 1 + |
| 5331 | strlen(nfs4_client_id_uniquifier) + 1 + |
| 5332 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5333 | |
| 5334 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5335 | return -EINVAL; |
| 5336 | |
| 5337 | /* |
| 5338 | * Since this string is allocated at mount time, and held until the |
| 5339 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5340 | * about a memory-reclaim deadlock. |
| 5341 | */ |
| 5342 | str = kmalloc(len, GFP_KERNEL); |
| 5343 | if (!str) |
| 5344 | return -ENOMEM; |
| 5345 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5346 | scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5347 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5348 | nfs4_client_id_uniquifier, |
| 5349 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5350 | clp->cl_owner_id = str; |
| 5351 | return 0; |
| 5352 | } |
| 5353 | |
| 5354 | static int |
| 5355 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
| 5356 | { |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5357 | size_t len; |
| 5358 | char *str; |
Trond Myklebust | ceb3a16 | 2015-01-03 15:16:04 -0500 | [diff] [blame] | 5359 | |
| 5360 | if (clp->cl_owner_id != NULL) |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5361 | return 0; |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 5362 | |
| 5363 | if (nfs4_client_id_uniquifier[0] != '\0') |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5364 | return nfs4_init_uniquifier_client_string(clp); |
| 5365 | |
| 5366 | len = 10 + 10 + 1 + 10 + 1 + |
| 5367 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
| 5368 | |
| 5369 | if (len > NFS4_OPAQUE_LIMIT + 1) |
| 5370 | return -EINVAL; |
| 5371 | |
| 5372 | /* |
| 5373 | * Since this string is allocated at mount time, and held until the |
| 5374 | * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
| 5375 | * about a memory-reclaim deadlock. |
| 5376 | */ |
| 5377 | str = kmalloc(len, GFP_KERNEL); |
| 5378 | if (!str) |
| 5379 | return -ENOMEM; |
| 5380 | |
Trond Myklebust | f2dd436 | 2015-10-08 11:33:17 -0400 | [diff] [blame] | 5381 | scnprintf(str, len, "Linux NFSv%u.%u %s", |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5382 | clp->rpc_ops->version, clp->cl_minorversion, |
| 5383 | clp->cl_rpcclient->cl_nodename); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5384 | clp->cl_owner_id = str; |
| 5385 | return 0; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5386 | } |
| 5387 | |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5388 | /* |
| 5389 | * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback |
| 5390 | * services. Advertise one based on the address family of the |
| 5391 | * clientaddr. |
| 5392 | */ |
| 5393 | static unsigned int |
| 5394 | nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len) |
| 5395 | { |
| 5396 | if (strchr(clp->cl_ipaddr, ':') != NULL) |
| 5397 | return scnprintf(buf, len, "tcp6"); |
| 5398 | else |
| 5399 | return scnprintf(buf, len, "tcp"); |
| 5400 | } |
| 5401 | |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5402 | static void nfs4_setclientid_done(struct rpc_task *task, void *calldata) |
| 5403 | { |
| 5404 | struct nfs4_setclientid *sc = calldata; |
| 5405 | |
| 5406 | if (task->tk_status == 0) |
| 5407 | sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred); |
| 5408 | } |
| 5409 | |
| 5410 | static const struct rpc_call_ops nfs4_setclientid_ops = { |
| 5411 | .rpc_call_done = nfs4_setclientid_done, |
| 5412 | }; |
| 5413 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5414 | /** |
| 5415 | * nfs4_proc_setclientid - Negotiate client ID |
| 5416 | * @clp: state data structure |
| 5417 | * @program: RPC program for NFSv4 callback service |
| 5418 | * @port: IP port number for NFS4 callback service |
| 5419 | * @cred: RPC credential to use for this call |
| 5420 | * @res: where to place the result |
| 5421 | * |
| 5422 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5423 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5424 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 5425 | unsigned short port, struct rpc_cred *cred, |
| 5426 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | { |
| 5428 | nfs4_verifier sc_verifier; |
| 5429 | struct nfs4_setclientid setclientid = { |
| 5430 | .sc_verifier = &sc_verifier, |
| 5431 | .sc_prog = program, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5432 | .sc_clnt = clp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | }; |
| 5434 | struct rpc_message msg = { |
| 5435 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 5436 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5437 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5438 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | }; |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5440 | struct rpc_task *task; |
| 5441 | struct rpc_task_setup task_setup_data = { |
| 5442 | .rpc_client = clp->cl_rpcclient, |
| 5443 | .rpc_message = &msg, |
| 5444 | .callback_ops = &nfs4_setclientid_ops, |
| 5445 | .callback_data = &setclientid, |
| 5446 | .flags = RPC_TASK_TIMEOUT, |
| 5447 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5448 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5450 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5451 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5452 | |
| 5453 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 5454 | status = nfs4_init_uniform_client_string(clp); |
| 5455 | else |
Jeff Layton | a319268 | 2015-06-09 19:43:59 -0400 | [diff] [blame] | 5456 | status = nfs4_init_nonuniform_client_string(clp); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 5457 | |
| 5458 | if (status) |
| 5459 | goto out; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5460 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5461 | /* cb_client4 */ |
Chuck Lever | 706cb8d | 2014-03-12 12:51:47 -0400 | [diff] [blame] | 5462 | setclientid.sc_netid_len = |
| 5463 | nfs4_init_callback_netid(clp, |
| 5464 | setclientid.sc_netid, |
| 5465 | sizeof(setclientid.sc_netid)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 5466 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 5467 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | clp->cl_ipaddr, port >> 8, port & 255); |
| 5469 | |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5470 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5471 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 5472 | clp->cl_owner_id); |
Jeff Layton | f11b2a1 | 2014-06-21 20:52:17 -0400 | [diff] [blame] | 5473 | task = rpc_run_task(&task_setup_data); |
| 5474 | if (IS_ERR(task)) { |
| 5475 | status = PTR_ERR(task); |
| 5476 | goto out; |
| 5477 | } |
| 5478 | status = task->tk_status; |
| 5479 | if (setclientid.sc_cred) { |
| 5480 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
| 5481 | put_rpccred(setclientid.sc_cred); |
| 5482 | } |
| 5483 | rpc_put_task(task); |
| 5484 | out: |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5485 | trace_nfs4_setclientid(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5486 | dprintk("NFS reply setclientid: %d\n", status); |
| 5487 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5490 | /** |
| 5491 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 5492 | * @clp: state data structure |
| 5493 | * @res: result of a previous SETCLIENTID |
| 5494 | * @cred: RPC credential to use for this call |
| 5495 | * |
| 5496 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5497 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5498 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5499 | struct nfs4_setclientid_res *arg, |
| 5500 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | struct rpc_message msg = { |
| 5503 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 5504 | .rpc_argp = arg, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 5505 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | int status; |
| 5508 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5509 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 5510 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5511 | clp->cl_clientid); |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5512 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 5513 | trace_nfs4_setclientid_confirm(clp, status); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5514 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | return status; |
| 5516 | } |
| 5517 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5518 | struct nfs4_delegreturndata { |
| 5519 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5520 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5521 | struct nfs_fh fh; |
| 5522 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5523 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5524 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5525 | int rpc_status; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5526 | struct inode *inode; |
| 5527 | bool roc; |
| 5528 | u32 roc_barrier; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5529 | }; |
| 5530 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5531 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 5532 | { |
| 5533 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5534 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5535 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5536 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5537 | |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 5538 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5539 | switch (task->tk_status) { |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5540 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5541 | renew_lease(data->res.server, data->timestamp); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5542 | case -NFS4ERR_ADMIN_REVOKED: |
| 5543 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5544 | case -NFS4ERR_EXPIRED: |
| 5545 | nfs4_free_revoked_stateid(data->res.server, |
| 5546 | data->args.stateid, |
| 5547 | task->tk_msg.rpc_cred); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5548 | case -NFS4ERR_BAD_STATEID: |
| 5549 | case -NFS4ERR_OLD_STATEID: |
| 5550 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5551 | task->tk_status = 0; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5552 | if (data->roc) |
| 5553 | pnfs_roc_set_barrier(data->inode, data->roc_barrier); |
Trond Myklebust | c97cf60 | 2013-11-19 16:34:14 -0500 | [diff] [blame] | 5554 | break; |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5555 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5556 | if (nfs4_async_handle_error(task, data->res.server, |
| 5557 | NULL, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5558 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 5559 | return; |
| 5560 | } |
| 5561 | } |
| 5562 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | static void nfs4_delegreturn_release(void *calldata) |
| 5566 | { |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5567 | struct nfs4_delegreturndata *data = calldata; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5568 | struct inode *inode = data->inode; |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5569 | |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5570 | if (inode) { |
| 5571 | if (data->roc) |
| 5572 | pnfs_roc_release(inode); |
| 5573 | nfs_iput_and_deactive(inode); |
| 5574 | } |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5575 | kfree(calldata); |
| 5576 | } |
| 5577 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5578 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 5579 | { |
| 5580 | struct nfs4_delegreturndata *d_data; |
| 5581 | |
| 5582 | d_data = (struct nfs4_delegreturndata *)data; |
| 5583 | |
Peng Tao | 500d701 | 2015-09-22 11:35:22 +0800 | [diff] [blame] | 5584 | if (nfs4_wait_on_layoutreturn(d_data->inode, task)) |
| 5585 | return; |
| 5586 | |
Trond Myklebust | 4ff376f | 2015-08-18 23:23:21 -0500 | [diff] [blame] | 5587 | if (d_data->roc) |
| 5588 | pnfs_roc_get_barrier(d_data->inode, &d_data->roc_barrier); |
Peng Tao | 039b756 | 2014-07-03 13:05:02 +0800 | [diff] [blame] | 5589 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 5590 | nfs4_setup_sequence(d_data->res.server, |
| 5591 | &d_data->args.seq_args, |
| 5592 | &d_data->res.seq_res, |
| 5593 | task); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5594 | } |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5595 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 5596 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 5597 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5598 | .rpc_call_done = nfs4_delegreturn_done, |
| 5599 | .rpc_release = nfs4_delegreturn_release, |
| 5600 | }; |
| 5601 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5602 | 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] | 5603 | { |
| 5604 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5605 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5606 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5607 | struct rpc_message msg = { |
| 5608 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 5609 | .rpc_cred = cred, |
| 5610 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5611 | struct rpc_task_setup task_setup_data = { |
| 5612 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5613 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5614 | .callback_ops = &nfs4_delegreturn_ops, |
| 5615 | .flags = RPC_TASK_ASYNC, |
| 5616 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5617 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5618 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5619 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5620 | if (data == NULL) |
| 5621 | return -ENOMEM; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5622 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 5623 | |
| 5624 | nfs4_state_protect(server->nfs_client, |
| 5625 | NFS_SP4_MACH_CRED_CLEANUP, |
| 5626 | &task_setup_data.rpc_client, &msg); |
| 5627 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5628 | data->args.fhandle = &data->fh; |
| 5629 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 5630 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5631 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 5632 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 5633 | data->res.fattr = &data->fattr; |
| 5634 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5635 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5636 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5637 | data->rpc_status = 0; |
Trond Myklebust | ea7c38f | 2015-02-05 15:13:24 -0500 | [diff] [blame] | 5638 | data->inode = nfs_igrab_and_active(inode); |
| 5639 | if (data->inode) |
| 5640 | data->roc = nfs4_roc(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5641 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5642 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5643 | msg.rpc_argp = &data->args; |
| 5644 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5645 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 5646 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5647 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5648 | if (!issync) |
| 5649 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5650 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5651 | if (status != 0) |
| 5652 | goto out; |
| 5653 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 5654 | if (status == 0) |
| 5655 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 5656 | else |
| 5657 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5658 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5659 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 5660 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | } |
| 5662 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5663 | 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] | 5664 | { |
| 5665 | struct nfs_server *server = NFS_SERVER(inode); |
| 5666 | struct nfs4_exception exception = { }; |
| 5667 | int err; |
| 5668 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 5669 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 5670 | trace_nfs4_delegreturn(inode, stateid, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | switch (err) { |
| 5672 | case -NFS4ERR_STALE_STATEID: |
| 5673 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | case 0: |
| 5675 | return 0; |
| 5676 | } |
| 5677 | err = nfs4_handle_exception(server, err, &exception); |
| 5678 | } while (exception.retry); |
| 5679 | return err; |
| 5680 | } |
| 5681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5683 | { |
| 5684 | struct inode *inode = state->inode; |
| 5685 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5686 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5687 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5689 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5691 | struct nfs_lockt_res res = { |
| 5692 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | }; |
| 5694 | struct rpc_message msg = { |
| 5695 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 5696 | .rpc_argp = &arg, |
| 5697 | .rpc_resp = &res, |
| 5698 | .rpc_cred = state->owner->so_cred, |
| 5699 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | struct nfs4_lock_state *lsp; |
| 5701 | int status; |
| 5702 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5703 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5704 | status = nfs4_set_lock_state(state, request); |
| 5705 | if (status != 0) |
| 5706 | goto out; |
| 5707 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5708 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5709 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5710 | 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] | 5711 | switch (status) { |
| 5712 | case 0: |
| 5713 | request->fl_type = F_UNLCK; |
| 5714 | break; |
| 5715 | case -NFS4ERR_DENIED: |
| 5716 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 5718 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | a6f951d | 2013-10-01 14:24:58 -0400 | [diff] [blame] | 5719 | request->fl_ops = NULL; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 5720 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | return status; |
| 5722 | } |
| 5723 | |
| 5724 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5725 | { |
| 5726 | struct nfs4_exception exception = { }; |
| 5727 | int err; |
| 5728 | |
| 5729 | do { |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5730 | err = _nfs4_proc_getlk(state, cmd, request); |
| 5731 | trace_nfs4_get_lock(request, state, cmd, err); |
| 5732 | err = nfs4_handle_exception(NFS_SERVER(state->inode), err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | &exception); |
| 5734 | } while (exception.retry); |
| 5735 | return err; |
| 5736 | } |
| 5737 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5738 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5739 | struct nfs_locku_args arg; |
| 5740 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5741 | struct nfs4_lock_state *lsp; |
| 5742 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5743 | struct file_lock fl; |
Trond Myklebust | 516285eb | 2015-09-20 16:15:24 -0400 | [diff] [blame] | 5744 | struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5745 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5746 | }; |
| 5747 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5748 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 5749 | struct nfs_open_context *ctx, |
| 5750 | struct nfs4_lock_state *lsp, |
| 5751 | struct nfs_seqid *seqid) |
| 5752 | { |
| 5753 | struct nfs4_unlockdata *p; |
| 5754 | struct inode *inode = lsp->ls_state->inode; |
| 5755 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5756 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5757 | if (p == NULL) |
| 5758 | return NULL; |
| 5759 | p->arg.fh = NFS_FH(inode); |
| 5760 | p->arg.fl = &p->fl; |
| 5761 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5762 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5763 | p->lsp = lsp; |
| 5764 | atomic_inc(&lsp->ls_count); |
| 5765 | /* Ensure we don't close file until we're done freeing locks! */ |
| 5766 | p->ctx = get_nfs_open_context(ctx); |
| 5767 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5768 | p->server = NFS_SERVER(inode); |
| 5769 | return p; |
| 5770 | } |
| 5771 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5772 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5773 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5774 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5775 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5776 | nfs4_put_lock_state(calldata->lsp); |
| 5777 | put_nfs_open_context(calldata->ctx); |
| 5778 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5781 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5782 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5783 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5784 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5785 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 5786 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5787 | switch (task->tk_status) { |
| 5788 | case 0: |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5789 | renew_lease(calldata->server, calldata->timestamp); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5790 | locks_lock_inode_wait(calldata->lsp->ls_state->inode, &calldata->fl); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 5791 | if (nfs4_update_lock_stateid(calldata->lsp, |
| 5792 | &calldata->res.stateid)) |
| 5793 | break; |
Trond Myklebust | 26d3630 | 2016-09-22 13:39:05 -0400 | [diff] [blame] | 5794 | case -NFS4ERR_ADMIN_REVOKED: |
| 5795 | case -NFS4ERR_EXPIRED: |
| 5796 | nfs4_free_revoked_stateid(calldata->server, |
| 5797 | &calldata->arg.stateid, |
| 5798 | task->tk_msg.rpc_cred); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 5799 | case -NFS4ERR_BAD_STATEID: |
| 5800 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5801 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5802 | if (!nfs4_stateid_match(&calldata->arg.stateid, |
| 5803 | &calldata->lsp->ls_stateid)) |
| 5804 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5805 | break; |
| 5806 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 5807 | if (nfs4_async_handle_error(task, calldata->server, |
| 5808 | NULL, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5809 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5810 | } |
Trond Myklebust | 2b1bc30 | 2012-10-29 18:53:23 -0400 | [diff] [blame] | 5811 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5814 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5815 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5816 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5818 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5819 | goto out_wait; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5820 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 5821 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5822 | /* Note: exit _without_ running nfs4_locku_done */ |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5823 | goto out_no_action; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5824 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5825 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5826 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 5827 | &calldata->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5828 | &calldata->res.seq_res, |
| 5829 | task) != 0) |
| 5830 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5831 | return; |
| 5832 | out_no_action: |
| 5833 | task->tk_action = NULL; |
| 5834 | out_wait: |
| 5835 | nfs4_sequence_done(task, &calldata->res.seq_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | } |
| 5837 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5838 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 5839 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5840 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5841 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 5842 | }; |
| 5843 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5844 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 5845 | struct nfs_open_context *ctx, |
| 5846 | struct nfs4_lock_state *lsp, |
| 5847 | struct nfs_seqid *seqid) |
| 5848 | { |
| 5849 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5850 | struct rpc_message msg = { |
| 5851 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 5852 | .rpc_cred = ctx->cred, |
| 5853 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5854 | struct rpc_task_setup task_setup_data = { |
| 5855 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 5856 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5857 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 5858 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5859 | .flags = RPC_TASK_ASYNC, |
| 5860 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5861 | |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 5862 | nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client, |
| 5863 | NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg); |
| 5864 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 5865 | /* Ensure this is an unlock - when canceling a lock, the |
| 5866 | * canceled lock is passed in, and it won't be an unlock. |
| 5867 | */ |
| 5868 | fl->fl_type = F_UNLCK; |
| 5869 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5870 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 5871 | if (data == NULL) { |
| 5872 | nfs_free_seqid(seqid); |
| 5873 | return ERR_PTR(-ENOMEM); |
| 5874 | } |
| 5875 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 5876 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 5877 | msg.rpc_argp = &data->arg; |
| 5878 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 5879 | task_setup_data.callback_data = data; |
| 5880 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5881 | } |
| 5882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5884 | { |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5885 | struct inode *inode = state->inode; |
| 5886 | struct nfs4_state_owner *sp = state->owner; |
| 5887 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5888 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5889 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5890 | struct rpc_task *task; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5891 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 5892 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5893 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5895 | status = nfs4_set_lock_state(state, request); |
| 5896 | /* Unlock _before_ we do the RPC call */ |
| 5897 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5898 | /* Exclude nfs_delegation_claim_locks() */ |
| 5899 | mutex_lock(&sp->so_delegreturn_mutex); |
| 5900 | /* Exclude nfs4_reclaim_open_stateid() - note nesting! */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5901 | down_read(&nfsi->rwsem); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 5902 | if (locks_lock_inode_wait(inode, request) == -ENOENT) { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5903 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5904 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5905 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 5906 | } |
| 5907 | up_read(&nfsi->rwsem); |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 5908 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5909 | if (status != 0) |
| 5910 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 5911 | /* Is this a delegated lock? */ |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5912 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | c5a2a15 | 2013-04-30 12:43:42 -0400 | [diff] [blame] | 5913 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5914 | goto out; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5915 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5916 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5917 | status = -ENOMEM; |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5918 | if (IS_ERR(seqid)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5919 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5920 | 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] | 5921 | status = PTR_ERR(task); |
| 5922 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5923 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5924 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 5925 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 5926 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 5927 | request->fl_flags = fl_flags; |
Trond Myklebust | d1b748a | 2013-08-12 16:35:20 -0400 | [diff] [blame] | 5928 | trace_nfs4_unlock(request, state, F_SETLK, status); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 5929 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | } |
| 5931 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5932 | struct nfs4_lockdata { |
| 5933 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 5934 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5935 | struct nfs4_lock_state *lsp; |
| 5936 | struct nfs_open_context *ctx; |
| 5937 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 5938 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5939 | int rpc_status; |
| 5940 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5941 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5942 | }; |
| 5943 | |
| 5944 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5945 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 5946 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5947 | { |
| 5948 | struct nfs4_lockdata *p; |
| 5949 | struct inode *inode = lsp->ls_state->inode; |
| 5950 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5951 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5952 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5953 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5954 | if (p == NULL) |
| 5955 | return NULL; |
| 5956 | |
| 5957 | p->arg.fh = NFS_FH(inode); |
| 5958 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5959 | 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] | 5960 | if (IS_ERR(p->arg.open_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5961 | goto out_free; |
Trond Myklebust | b4019c0 | 2015-01-24 14:19:19 -0500 | [diff] [blame] | 5962 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5963 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | badc76d | 2015-01-23 18:48:00 -0500 | [diff] [blame] | 5964 | if (IS_ERR(p->arg.lock_seqid)) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5965 | goto out_free_seqid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5966 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5967 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 5968 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 5969 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5970 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 5971 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5972 | atomic_inc(&lsp->ls_count); |
| 5973 | p->ctx = get_nfs_open_context(ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 5974 | get_file(fl->fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5975 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 5976 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5977 | out_free_seqid: |
| 5978 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5979 | out_free: |
| 5980 | kfree(p); |
| 5981 | return NULL; |
| 5982 | } |
| 5983 | |
| 5984 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 5985 | { |
| 5986 | struct nfs4_lockdata *data = calldata; |
| 5987 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5989 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 5990 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 5991 | goto out_wait; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5992 | /* Do we need to do an open_to_lock_owner? */ |
Trond Myklebust | 6b44753 | 2015-01-24 18:38:15 -0500 | [diff] [blame] | 5993 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5994 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 5995 | goto out_release_lock_seqid; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 5996 | } |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 5997 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5998 | &state->open_stateid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 5999 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 6000 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6001 | } else { |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6002 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6003 | nfs4_stateid_copy(&data->arg.lock_stateid, |
| 6004 | &data->lsp->ls_stateid); |
| 6005 | } |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6006 | if (!nfs4_valid_open_stateid(state)) { |
| 6007 | data->rpc_status = -EBADF; |
| 6008 | task->tk_action = NULL; |
| 6009 | goto out_release_open_seqid; |
| 6010 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 6011 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6012 | if (nfs4_setup_sequence(data->server, |
| 6013 | &data->arg.seq_args, |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6014 | &data->res.seq_res, |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 6015 | task) == 0) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6016 | return; |
Trond Myklebust | 5d42230 | 2013-03-14 16:57:48 -0400 | [diff] [blame] | 6017 | out_release_open_seqid: |
Trond Myklebust | 2240a9e | 2012-10-29 18:37:40 -0400 | [diff] [blame] | 6018 | nfs_release_seqid(data->arg.open_seqid); |
| 6019 | out_release_lock_seqid: |
| 6020 | nfs_release_seqid(data->arg.lock_seqid); |
Trond Myklebust | c8da19b | 2013-02-11 19:01:21 -0500 | [diff] [blame] | 6021 | out_wait: |
| 6022 | nfs4_sequence_done(task, &data->res.seq_res); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6023 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6024 | } |
| 6025 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6026 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 6027 | { |
| 6028 | struct nfs4_lockdata *data = calldata; |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6029 | struct nfs4_lock_state *lsp = data->lsp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6030 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6031 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6032 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6033 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6034 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 6035 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6036 | data->rpc_status = task->tk_status; |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6037 | switch (task->tk_status) { |
| 6038 | case 0: |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 6039 | renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6040 | data->timestamp); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6041 | if (data->arg.new_lock) { |
| 6042 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6043 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) { |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6044 | rpc_restart_call_prepare(task); |
| 6045 | break; |
| 6046 | } |
| 6047 | } |
Trond Myklebust | 39071e6 | 2015-01-24 15:07:56 -0500 | [diff] [blame] | 6048 | if (data->arg.new_lock_owner != 0) { |
| 6049 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
| 6050 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); |
| 6051 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
| 6052 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
| 6053 | rpc_restart_call_prepare(task); |
Trond Myklebust | 425c1d4 | 2015-01-24 14:57:53 -0500 | [diff] [blame] | 6054 | break; |
| 6055 | case -NFS4ERR_BAD_STATEID: |
| 6056 | case -NFS4ERR_OLD_STATEID: |
| 6057 | case -NFS4ERR_STALE_STATEID: |
| 6058 | case -NFS4ERR_EXPIRED: |
| 6059 | if (data->arg.new_lock_owner != 0) { |
| 6060 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
| 6061 | &lsp->ls_state->open_stateid)) |
| 6062 | rpc_restart_call_prepare(task); |
| 6063 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
| 6064 | &lsp->ls_stateid)) |
| 6065 | rpc_restart_call_prepare(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6066 | } |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6067 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | static void nfs4_lock_release(void *calldata) |
| 6071 | { |
| 6072 | struct nfs4_lockdata *data = calldata; |
| 6073 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6074 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 6075 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6076 | if (data->cancelled != 0) { |
| 6077 | struct rpc_task *task; |
| 6078 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 6079 | data->arg.lock_seqid); |
| 6080 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6081 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6082 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6083 | } else |
| 6084 | nfs_free_seqid(data->arg.lock_seqid); |
| 6085 | nfs4_put_lock_state(data->lsp); |
| 6086 | put_nfs_open_context(data->ctx); |
Jeff Layton | feaff8e | 2015-05-12 15:48:10 -0400 | [diff] [blame] | 6087 | fput(data->fl.fl_file); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6088 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6089 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6090 | } |
| 6091 | |
| 6092 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 6093 | .rpc_call_prepare = nfs4_lock_prepare, |
| 6094 | .rpc_call_done = nfs4_lock_done, |
| 6095 | .rpc_release = nfs4_lock_release, |
| 6096 | }; |
| 6097 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6098 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 6099 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6100 | switch (error) { |
| 6101 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | d7f3e4b | 2016-09-22 13:39:09 -0400 | [diff] [blame] | 6102 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6103 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6104 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6105 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 6106 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6107 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6108 | break; |
| 6109 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 6110 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 6111 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6112 | }; |
| 6113 | } |
| 6114 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6115 | 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] | 6116 | { |
| 6117 | struct nfs4_lockdata *data; |
| 6118 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6119 | struct rpc_message msg = { |
| 6120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 6121 | .rpc_cred = state->owner->so_cred, |
| 6122 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6123 | struct rpc_task_setup task_setup_data = { |
| 6124 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 6125 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6126 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 6127 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6128 | .flags = RPC_TASK_ASYNC, |
| 6129 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6130 | int ret; |
| 6131 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6132 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6133 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6134 | fl->fl_u.nfs4_fl.owner, |
| 6135 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6136 | if (data == NULL) |
| 6137 | return -ENOMEM; |
| 6138 | if (IS_SETLKW(cmd)) |
| 6139 | data->arg.block = 1; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 6140 | nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 6141 | msg.rpc_argp = &data->arg; |
| 6142 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6143 | task_setup_data.callback_data = data; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 6144 | if (recovery_type > NFS_LOCK_NEW) { |
| 6145 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 6146 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 6147 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6148 | } else |
| 6149 | data->arg.new_lock = 1; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 6150 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 6151 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6152 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6153 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 6154 | if (ret == 0) { |
| 6155 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 6156 | if (ret) |
| 6157 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 6158 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6159 | } else |
| 6160 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 6161 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6162 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 6163 | trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 6164 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 6168 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6169 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6170 | struct nfs4_exception exception = { |
| 6171 | .inode = state->inode, |
| 6172 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6173 | int err; |
| 6174 | |
| 6175 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6176 | /* Cache the lock if possible... */ |
| 6177 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6178 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6179 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 6180 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6181 | break; |
| 6182 | nfs4_handle_exception(server, err, &exception); |
| 6183 | } while (exception.retry); |
| 6184 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6188 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6189 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6190 | struct nfs4_exception exception = { |
| 6191 | .inode = state->inode, |
| 6192 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6193 | int err; |
| 6194 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 6195 | err = nfs4_set_lock_state(state, request); |
| 6196 | if (err != 0) |
| 6197 | return err; |
Trond Myklebust | f6de7a3 | 2013-09-04 10:08:54 -0400 | [diff] [blame] | 6198 | if (!recover_lost_locks) { |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 6199 | set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags); |
| 6200 | return 0; |
| 6201 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6202 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 6203 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 6204 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6205 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6206 | switch (err) { |
| 6207 | default: |
| 6208 | goto out; |
| 6209 | case -NFS4ERR_GRACE: |
| 6210 | case -NFS4ERR_DELAY: |
| 6211 | nfs4_handle_exception(server, err, &exception); |
| 6212 | err = 0; |
| 6213 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6214 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 6215 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 6216 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6219 | #if defined(CONFIG_NFS_V4_1) |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6220 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 6221 | { |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6222 | struct nfs4_lock_state *lsp; |
| 6223 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 6224 | |
Trond Myklebust | c5896fc | 2016-09-22 13:39:03 -0400 | [diff] [blame] | 6225 | status = nfs4_set_lock_state(state, request); |
| 6226 | if (status != 0) |
| 6227 | return status; |
| 6228 | lsp = request->fl_u.nfs4_fl.owner; |
| 6229 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || |
| 6230 | test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) |
| 6231 | return 0; |
| 6232 | status = nfs4_lock_expired(state, request); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 6233 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6234 | } |
| 6235 | #endif |
| 6236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6238 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6239 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6240 | struct nfs4_state_owner *sp = state->owner; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6241 | unsigned char fl_flags = request->fl_flags; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6242 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6244 | request->fl_flags |= FL_ACCESS; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6245 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6246 | if (status < 0) |
| 6247 | goto out; |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6248 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6249 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6250 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6251 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6252 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 6253 | request->fl_flags = fl_flags & ~FL_SLEEP; |
Jeff Layton | 75575dd | 2016-09-17 18:17:32 -0400 | [diff] [blame] | 6254 | status = locks_lock_inode_wait(state->inode, request); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6255 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6256 | mutex_unlock(&sp->so_delegreturn_mutex); |
Trond Myklebust | c69899a | 2015-01-24 16:03:52 -0500 | [diff] [blame] | 6257 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6258 | } |
Trond Myklebust | 9a99af4 | 2013-02-04 20:17:49 -0500 | [diff] [blame] | 6259 | up_read(&nfsi->rwsem); |
Chuck Lever | 11476e9 | 2016-04-11 16:20:22 -0400 | [diff] [blame] | 6260 | mutex_unlock(&sp->so_delegreturn_mutex); |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 6261 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 6262 | out: |
| 6263 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | return status; |
| 6265 | } |
| 6266 | |
| 6267 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6268 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6269 | struct nfs4_exception exception = { |
| 6270 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 6271 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 6272 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | int err; |
| 6274 | |
| 6275 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6276 | err = _nfs4_proc_setlk(state, cmd, request); |
| 6277 | if (err == -NFS4ERR_DENIED) |
| 6278 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6279 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 6280 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | } while (exception.retry); |
| 6282 | return err; |
| 6283 | } |
| 6284 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6285 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 6286 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 6287 | |
| 6288 | static int |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6289 | nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, |
| 6290 | struct file_lock *request) |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6291 | { |
| 6292 | int status = -ERESTARTSYS; |
| 6293 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 6294 | |
| 6295 | while(!signalled()) { |
| 6296 | status = nfs4_proc_setlk(state, cmd, request); |
| 6297 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6298 | break; |
| 6299 | freezable_schedule_timeout_interruptible(timeout); |
| 6300 | timeout *= 2; |
| 6301 | timeout = min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT, timeout); |
| 6302 | status = -ERESTARTSYS; |
| 6303 | } |
| 6304 | return status; |
| 6305 | } |
| 6306 | |
Jeff Layton | a1d617d8 | 2016-09-17 18:17:39 -0400 | [diff] [blame] | 6307 | #ifdef CONFIG_NFS_V4_1 |
| 6308 | struct nfs4_lock_waiter { |
| 6309 | struct task_struct *task; |
| 6310 | struct inode *inode; |
| 6311 | struct nfs_lowner *owner; |
| 6312 | bool notified; |
| 6313 | }; |
| 6314 | |
| 6315 | static int |
| 6316 | nfs4_wake_lock_waiter(wait_queue_t *wait, unsigned int mode, int flags, void *key) |
| 6317 | { |
| 6318 | int ret; |
| 6319 | struct cb_notify_lock_args *cbnl = key; |
| 6320 | struct nfs4_lock_waiter *waiter = wait->private; |
| 6321 | struct nfs_lowner *lowner = &cbnl->cbnl_owner, |
| 6322 | *wowner = waiter->owner; |
| 6323 | |
| 6324 | /* Only wake if the callback was for the same owner */ |
| 6325 | if (lowner->clientid != wowner->clientid || |
| 6326 | lowner->id != wowner->id || |
| 6327 | lowner->s_dev != wowner->s_dev) |
| 6328 | return 0; |
| 6329 | |
| 6330 | /* Make sure it's for the right inode */ |
| 6331 | if (nfs_compare_fh(NFS_FH(waiter->inode), &cbnl->cbnl_fh)) |
| 6332 | return 0; |
| 6333 | |
| 6334 | waiter->notified = true; |
| 6335 | |
| 6336 | /* override "private" so we can use default_wake_function */ |
| 6337 | wait->private = waiter->task; |
| 6338 | ret = autoremove_wake_function(wait, mode, flags, key); |
| 6339 | wait->private = waiter; |
| 6340 | return ret; |
| 6341 | } |
| 6342 | |
| 6343 | static int |
| 6344 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6345 | { |
| 6346 | int status = -ERESTARTSYS; |
| 6347 | unsigned long flags; |
| 6348 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
| 6349 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 6350 | struct nfs_client *clp = server->nfs_client; |
| 6351 | wait_queue_head_t *q = &clp->cl_lock_waitq; |
| 6352 | struct nfs_lowner owner = { .clientid = clp->cl_clientid, |
| 6353 | .id = lsp->ls_seqid.owner_id, |
| 6354 | .s_dev = server->s_dev }; |
| 6355 | struct nfs4_lock_waiter waiter = { .task = current, |
| 6356 | .inode = state->inode, |
| 6357 | .owner = &owner, |
| 6358 | .notified = false }; |
| 6359 | wait_queue_t wait; |
| 6360 | |
| 6361 | /* Don't bother with waitqueue if we don't expect a callback */ |
| 6362 | if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) |
| 6363 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6364 | |
| 6365 | init_wait(&wait); |
| 6366 | wait.private = &waiter; |
| 6367 | wait.func = nfs4_wake_lock_waiter; |
| 6368 | add_wait_queue(q, &wait); |
| 6369 | |
| 6370 | while(!signalled()) { |
| 6371 | status = nfs4_proc_setlk(state, cmd, request); |
| 6372 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 6373 | break; |
| 6374 | |
| 6375 | status = -ERESTARTSYS; |
| 6376 | spin_lock_irqsave(&q->lock, flags); |
| 6377 | if (waiter.notified) { |
| 6378 | spin_unlock_irqrestore(&q->lock, flags); |
| 6379 | continue; |
| 6380 | } |
| 6381 | set_current_state(TASK_INTERRUPTIBLE); |
| 6382 | spin_unlock_irqrestore(&q->lock, flags); |
| 6383 | |
| 6384 | freezable_schedule_timeout_interruptible(NFS4_LOCK_MAXTIMEOUT); |
| 6385 | } |
| 6386 | |
| 6387 | finish_wait(q, &wait); |
| 6388 | return status; |
| 6389 | } |
| 6390 | #else /* !CONFIG_NFS_V4_1 */ |
| 6391 | static inline int |
| 6392 | nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 6393 | { |
| 6394 | return nfs4_retry_setlk_simple(state, cmd, request); |
| 6395 | } |
| 6396 | #endif |
| 6397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6398 | static int |
| 6399 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 6400 | { |
| 6401 | struct nfs_open_context *ctx; |
| 6402 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6403 | int status; |
| 6404 | |
| 6405 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 6406 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | state = ctx->state; |
| 6408 | |
| 6409 | if (request->fl_start < 0 || request->fl_end < 0) |
| 6410 | return -EINVAL; |
| 6411 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6412 | if (IS_GETLK(cmd)) { |
| 6413 | if (state != NULL) |
| 6414 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 6415 | return 0; |
| 6416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6417 | |
| 6418 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 6419 | return -EINVAL; |
| 6420 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6421 | if (request->fl_type == F_UNLCK) { |
| 6422 | if (state != NULL) |
| 6423 | return nfs4_proc_unlck(state, cmd, request); |
| 6424 | return 0; |
| 6425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6426 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 6427 | if (state == NULL) |
| 6428 | return -ENOLCK; |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6429 | |
| 6430 | if ((request->fl_flags & FL_POSIX) && |
| 6431 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 6432 | return -ENOLCK; |
| 6433 | |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6434 | /* |
| 6435 | * Don't rely on the VFS having checked the file open mode, |
| 6436 | * since it won't do this for flock() locks. |
| 6437 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 6438 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 6439 | case F_RDLCK: |
| 6440 | if (!(filp->f_mode & FMODE_READ)) |
| 6441 | return -EBADF; |
| 6442 | break; |
| 6443 | case F_WRLCK: |
| 6444 | if (!(filp->f_mode & FMODE_WRITE)) |
| 6445 | return -EBADF; |
| 6446 | } |
| 6447 | |
Jeff Layton | 1ea67db | 2016-09-17 18:17:37 -0400 | [diff] [blame] | 6448 | status = nfs4_set_lock_state(state, request); |
| 6449 | if (status != 0) |
| 6450 | return status; |
| 6451 | |
Jeff Layton | d2f3a7f | 2016-09-17 18:17:38 -0400 | [diff] [blame] | 6452 | return nfs4_retry_setlk(state, cmd, request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6455 | 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] | 6456 | { |
| 6457 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6458 | int err; |
| 6459 | |
| 6460 | err = nfs4_set_lock_state(state, fl); |
| 6461 | if (err != 0) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6462 | return err; |
Trond Myklebust | 4a706fa | 2013-04-01 14:47:22 -0400 | [diff] [blame] | 6463 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 6464 | return nfs4_handle_delegation_recall_error(server, state, stateid, err); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 6465 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6466 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6467 | struct nfs_release_lockowner_data { |
| 6468 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6469 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6470 | struct nfs_release_lockowner_args args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6471 | struct nfs_release_lockowner_res res; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6472 | unsigned long timestamp; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6473 | }; |
| 6474 | |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6475 | static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata) |
| 6476 | { |
| 6477 | struct nfs_release_lockowner_data *data = calldata; |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6478 | struct nfs_server *server = data->server; |
Peng Tao | cb04ad2 | 2014-06-11 05:24:15 +0800 | [diff] [blame] | 6479 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 6480 | &data->args.seq_args, &data->res.seq_res, task); |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6481 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6482 | data->timestamp = jiffies; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata) |
| 6486 | { |
| 6487 | struct nfs_release_lockowner_data *data = calldata; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6488 | struct nfs_server *server = data->server; |
| 6489 | |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6490 | nfs40_sequence_done(task, &data->res.seq_res); |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6491 | |
| 6492 | switch (task->tk_status) { |
| 6493 | case 0: |
| 6494 | renew_lease(server, data->timestamp); |
| 6495 | break; |
| 6496 | case -NFS4ERR_STALE_CLIENTID: |
| 6497 | case -NFS4ERR_EXPIRED: |
Kinglong Mee | 5b53dc8 | 2014-08-04 16:18:16 +0800 | [diff] [blame] | 6498 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 6499 | break; |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6500 | case -NFS4ERR_LEASE_MOVED: |
| 6501 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 6502 | if (nfs4_async_handle_error(task, server, |
| 6503 | NULL, NULL) == -EAGAIN) |
Chuck Lever | 60ea681 | 2013-10-17 14:13:47 -0400 | [diff] [blame] | 6504 | rpc_restart_call_prepare(task); |
| 6505 | } |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6506 | } |
| 6507 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6508 | static void nfs4_release_lockowner_release(void *calldata) |
| 6509 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6510 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6511 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6512 | kfree(calldata); |
| 6513 | } |
| 6514 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6515 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6516 | .rpc_call_prepare = nfs4_release_lockowner_prepare, |
| 6517 | .rpc_call_done = nfs4_release_lockowner_done, |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6518 | .rpc_release = nfs4_release_lockowner_release, |
| 6519 | }; |
| 6520 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6521 | static void |
| 6522 | nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6523 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6524 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6525 | struct rpc_message msg = { |
| 6526 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 6527 | }; |
| 6528 | |
| 6529 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6530 | return; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6531 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6532 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 6533 | if (!data) |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 6534 | return; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6535 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 6536 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6537 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6538 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 6539 | data->args.lock_owner.s_dev = server->s_dev; |
Chuck Lever | fbd4bfd | 2013-08-09 12:49:38 -0400 | [diff] [blame] | 6540 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6541 | msg.rpc_argp = &data->args; |
Trond Myklebust | b7e63a1 | 2014-02-26 11:19:14 -0800 | [diff] [blame] | 6542 | msg.rpc_resp = &data->res; |
| 6543 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 6544 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 6545 | } |
| 6546 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6547 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 6548 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6549 | static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6550 | struct dentry *unused, struct inode *inode, |
| 6551 | const char *key, const void *buf, |
| 6552 | size_t buflen, int flags) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6553 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6554 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6555 | } |
| 6556 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6557 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6558 | struct dentry *unused, struct inode *inode, |
| 6559 | const char *key, void *buf, size_t buflen) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6560 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6561 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6562 | } |
| 6563 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6564 | static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6565 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 6566 | return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry))); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6567 | } |
| 6568 | |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6569 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6570 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6571 | static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6572 | struct dentry *unused, struct inode *inode, |
| 6573 | const char *key, const void *buf, |
| 6574 | size_t buflen, int flags) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6575 | { |
| 6576 | if (security_ismaclabel(key)) |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 6577 | return nfs4_set_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6578 | |
| 6579 | return -EOPNOTSUPP; |
| 6580 | } |
| 6581 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 6582 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6583 | struct dentry *unused, struct inode *inode, |
| 6584 | const char *key, void *buf, size_t buflen) |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6585 | { |
| 6586 | if (security_ismaclabel(key)) |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 6587 | return nfs4_get_security_label(inode, buf, buflen); |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6588 | return -EOPNOTSUPP; |
| 6589 | } |
| 6590 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6591 | static ssize_t |
| 6592 | 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] | 6593 | { |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6594 | int len = 0; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6595 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6596 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
| 6597 | len = security_inode_listsecurity(inode, list, list_len); |
| 6598 | if (list_len && len > list_len) |
| 6599 | return -ERANGE; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6600 | } |
| 6601 | return len; |
| 6602 | } |
| 6603 | |
| 6604 | static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { |
| 6605 | .prefix = XATTR_SECURITY_PREFIX, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6606 | .get = nfs4_xattr_get_nfs4_label, |
| 6607 | .set = nfs4_xattr_set_nfs4_label, |
| 6608 | }; |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6609 | |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 6610 | #else |
| 6611 | |
| 6612 | static ssize_t |
| 6613 | nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len) |
| 6614 | { |
| 6615 | return 0; |
| 6616 | } |
| 6617 | |
| 6618 | #endif |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 6619 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6620 | /* |
| 6621 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 6622 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6623 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 6624 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6625 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 6626 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 6627 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6628 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6629 | return; |
| 6630 | |
| 6631 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 6632 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 6633 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 6634 | fattr->nlink = 2; |
| 6635 | } |
| 6636 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6637 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6638 | const struct qstr *name, |
| 6639 | struct nfs4_fs_locations *fs_locations, |
| 6640 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6641 | { |
| 6642 | struct nfs_server *server = NFS_SERVER(dir); |
David Quigley | a09df2c | 2013-05-22 12:50:41 -0400 | [diff] [blame] | 6643 | u32 bitmask[3] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 6644 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6645 | }; |
| 6646 | struct nfs4_fs_locations_arg args = { |
| 6647 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6648 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6649 | .page = page, |
| 6650 | .bitmask = bitmask, |
| 6651 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6652 | struct nfs4_fs_locations_res res = { |
| 6653 | .fs_locations = fs_locations, |
| 6654 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6655 | struct rpc_message msg = { |
| 6656 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6657 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 6658 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6659 | }; |
| 6660 | int status; |
| 6661 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 6662 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 6663 | |
| 6664 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 6665 | * is not supported */ |
| 6666 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 6667 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 6668 | else |
| 6669 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 6670 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 6671 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6672 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 6673 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6674 | 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] | 6675 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 6676 | return status; |
| 6677 | } |
| 6678 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 6679 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 6680 | const struct qstr *name, |
| 6681 | struct nfs4_fs_locations *fs_locations, |
| 6682 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6683 | { |
| 6684 | struct nfs4_exception exception = { }; |
| 6685 | int err; |
| 6686 | do { |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 6687 | err = _nfs4_proc_fs_locations(client, dir, name, |
| 6688 | fs_locations, page); |
| 6689 | trace_nfs4_get_fs_locations(dir, name, err); |
| 6690 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 6691 | &exception); |
| 6692 | } while (exception.retry); |
| 6693 | return err; |
| 6694 | } |
| 6695 | |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 6696 | /* |
| 6697 | * This operation also signals the server that this client is |
| 6698 | * performing migration recovery. The server can stop returning |
| 6699 | * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is |
| 6700 | * appended to this compound to identify the client ID which is |
| 6701 | * performing recovery. |
| 6702 | */ |
| 6703 | static int _nfs40_proc_get_locations(struct inode *inode, |
| 6704 | struct nfs4_fs_locations *locations, |
| 6705 | struct page *page, struct rpc_cred *cred) |
| 6706 | { |
| 6707 | struct nfs_server *server = NFS_SERVER(inode); |
| 6708 | struct rpc_clnt *clnt = server->client; |
| 6709 | u32 bitmask[2] = { |
| 6710 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6711 | }; |
| 6712 | struct nfs4_fs_locations_arg args = { |
| 6713 | .clientid = server->nfs_client->cl_clientid, |
| 6714 | .fh = NFS_FH(inode), |
| 6715 | .page = page, |
| 6716 | .bitmask = bitmask, |
| 6717 | .migration = 1, /* skip LOOKUP */ |
| 6718 | .renew = 1, /* append RENEW */ |
| 6719 | }; |
| 6720 | struct nfs4_fs_locations_res res = { |
| 6721 | .fs_locations = locations, |
| 6722 | .migration = 1, |
| 6723 | .renew = 1, |
| 6724 | }; |
| 6725 | struct rpc_message msg = { |
| 6726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6727 | .rpc_argp = &args, |
| 6728 | .rpc_resp = &res, |
| 6729 | .rpc_cred = cred, |
| 6730 | }; |
| 6731 | unsigned long now = jiffies; |
| 6732 | int status; |
| 6733 | |
| 6734 | nfs_fattr_init(&locations->fattr); |
| 6735 | locations->server = server; |
| 6736 | locations->nlocations = 0; |
| 6737 | |
| 6738 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6739 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6740 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6741 | &args.seq_args, &res.seq_res); |
| 6742 | if (status) |
| 6743 | return status; |
| 6744 | |
| 6745 | renew_lease(server, now); |
| 6746 | return 0; |
| 6747 | } |
| 6748 | |
| 6749 | #ifdef CONFIG_NFS_V4_1 |
| 6750 | |
| 6751 | /* |
| 6752 | * This operation also signals the server that this client is |
| 6753 | * performing migration recovery. The server can stop asserting |
| 6754 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID |
| 6755 | * performing this operation is identified in the SEQUENCE |
| 6756 | * operation in this compound. |
| 6757 | * |
| 6758 | * When the client supports GETATTR(fs_locations_info), it can |
| 6759 | * be plumbed in here. |
| 6760 | */ |
| 6761 | static int _nfs41_proc_get_locations(struct inode *inode, |
| 6762 | struct nfs4_fs_locations *locations, |
| 6763 | struct page *page, struct rpc_cred *cred) |
| 6764 | { |
| 6765 | struct nfs_server *server = NFS_SERVER(inode); |
| 6766 | struct rpc_clnt *clnt = server->client; |
| 6767 | u32 bitmask[2] = { |
| 6768 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 6769 | }; |
| 6770 | struct nfs4_fs_locations_arg args = { |
| 6771 | .fh = NFS_FH(inode), |
| 6772 | .page = page, |
| 6773 | .bitmask = bitmask, |
| 6774 | .migration = 1, /* skip LOOKUP */ |
| 6775 | }; |
| 6776 | struct nfs4_fs_locations_res res = { |
| 6777 | .fs_locations = locations, |
| 6778 | .migration = 1, |
| 6779 | }; |
| 6780 | struct rpc_message msg = { |
| 6781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 6782 | .rpc_argp = &args, |
| 6783 | .rpc_resp = &res, |
| 6784 | .rpc_cred = cred, |
| 6785 | }; |
| 6786 | int status; |
| 6787 | |
| 6788 | nfs_fattr_init(&locations->fattr); |
| 6789 | locations->server = server; |
| 6790 | locations->nlocations = 0; |
| 6791 | |
| 6792 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6793 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6794 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6795 | &args.seq_args, &res.seq_res); |
| 6796 | if (status == NFS4_OK && |
| 6797 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6798 | status = -NFS4ERR_LEASE_MOVED; |
| 6799 | return status; |
| 6800 | } |
| 6801 | |
| 6802 | #endif /* CONFIG_NFS_V4_1 */ |
| 6803 | |
| 6804 | /** |
| 6805 | * nfs4_proc_get_locations - discover locations for a migrated FSID |
| 6806 | * @inode: inode on FSID that is migrating |
| 6807 | * @locations: result of query |
| 6808 | * @page: buffer |
| 6809 | * @cred: credential to use for this operation |
| 6810 | * |
| 6811 | * Returns NFS4_OK on success, a negative NFS4ERR status code if the |
| 6812 | * operation failed, or a negative errno if a local error occurred. |
| 6813 | * |
| 6814 | * On success, "locations" is filled in, but if the server has |
| 6815 | * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not |
| 6816 | * asserted. |
| 6817 | * |
| 6818 | * -NFS4ERR_LEASE_MOVED is returned if the server still has leases |
| 6819 | * from this client that require migration recovery. |
| 6820 | */ |
| 6821 | int nfs4_proc_get_locations(struct inode *inode, |
| 6822 | struct nfs4_fs_locations *locations, |
| 6823 | struct page *page, struct rpc_cred *cred) |
| 6824 | { |
| 6825 | struct nfs_server *server = NFS_SERVER(inode); |
| 6826 | struct nfs_client *clp = server->nfs_client; |
| 6827 | const struct nfs4_mig_recovery_ops *ops = |
| 6828 | clp->cl_mvops->mig_recovery_ops; |
| 6829 | struct nfs4_exception exception = { }; |
| 6830 | int status; |
| 6831 | |
| 6832 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6833 | (unsigned long long)server->fsid.major, |
| 6834 | (unsigned long long)server->fsid.minor, |
| 6835 | clp->cl_hostname); |
| 6836 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6837 | |
| 6838 | do { |
| 6839 | status = ops->get_locations(inode, locations, page, cred); |
| 6840 | if (status != -NFS4ERR_DELAY) |
| 6841 | break; |
| 6842 | nfs4_handle_exception(server, status, &exception); |
| 6843 | } while (exception.retry); |
| 6844 | return status; |
| 6845 | } |
| 6846 | |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 6847 | /* |
| 6848 | * This operation also signals the server that this client is |
| 6849 | * performing "lease moved" recovery. The server can stop |
| 6850 | * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation |
| 6851 | * is appended to this compound to identify the client ID which is |
| 6852 | * performing recovery. |
| 6853 | */ |
| 6854 | static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6855 | { |
| 6856 | struct nfs_server *server = NFS_SERVER(inode); |
| 6857 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 6858 | struct rpc_clnt *clnt = server->client; |
| 6859 | struct nfs4_fsid_present_arg args = { |
| 6860 | .fh = NFS_FH(inode), |
| 6861 | .clientid = clp->cl_clientid, |
| 6862 | .renew = 1, /* append RENEW */ |
| 6863 | }; |
| 6864 | struct nfs4_fsid_present_res res = { |
| 6865 | .renew = 1, |
| 6866 | }; |
| 6867 | struct rpc_message msg = { |
| 6868 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6869 | .rpc_argp = &args, |
| 6870 | .rpc_resp = &res, |
| 6871 | .rpc_cred = cred, |
| 6872 | }; |
| 6873 | unsigned long now = jiffies; |
| 6874 | int status; |
| 6875 | |
| 6876 | res.fh = nfs_alloc_fhandle(); |
| 6877 | if (res.fh == NULL) |
| 6878 | return -ENOMEM; |
| 6879 | |
| 6880 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6881 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6882 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6883 | &args.seq_args, &res.seq_res); |
| 6884 | nfs_free_fhandle(res.fh); |
| 6885 | if (status) |
| 6886 | return status; |
| 6887 | |
| 6888 | do_renew_lease(clp, now); |
| 6889 | return 0; |
| 6890 | } |
| 6891 | |
| 6892 | #ifdef CONFIG_NFS_V4_1 |
| 6893 | |
| 6894 | /* |
| 6895 | * This operation also signals the server that this client is |
| 6896 | * performing "lease moved" recovery. The server can stop asserting |
| 6897 | * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing |
| 6898 | * this operation is identified in the SEQUENCE operation in this |
| 6899 | * compound. |
| 6900 | */ |
| 6901 | static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6902 | { |
| 6903 | struct nfs_server *server = NFS_SERVER(inode); |
| 6904 | struct rpc_clnt *clnt = server->client; |
| 6905 | struct nfs4_fsid_present_arg args = { |
| 6906 | .fh = NFS_FH(inode), |
| 6907 | }; |
| 6908 | struct nfs4_fsid_present_res res = { |
| 6909 | }; |
| 6910 | struct rpc_message msg = { |
| 6911 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT], |
| 6912 | .rpc_argp = &args, |
| 6913 | .rpc_resp = &res, |
| 6914 | .rpc_cred = cred, |
| 6915 | }; |
| 6916 | int status; |
| 6917 | |
| 6918 | res.fh = nfs_alloc_fhandle(); |
| 6919 | if (res.fh == NULL) |
| 6920 | return -ENOMEM; |
| 6921 | |
| 6922 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
| 6923 | nfs4_set_sequence_privileged(&args.seq_args); |
| 6924 | status = nfs4_call_sync_sequence(clnt, server, &msg, |
| 6925 | &args.seq_args, &res.seq_res); |
| 6926 | nfs_free_fhandle(res.fh); |
| 6927 | if (status == NFS4_OK && |
| 6928 | res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED) |
| 6929 | status = -NFS4ERR_LEASE_MOVED; |
| 6930 | return status; |
| 6931 | } |
| 6932 | |
| 6933 | #endif /* CONFIG_NFS_V4_1 */ |
| 6934 | |
| 6935 | /** |
| 6936 | * nfs4_proc_fsid_present - Is this FSID present or absent on server? |
| 6937 | * @inode: inode on FSID to check |
| 6938 | * @cred: credential to use for this operation |
| 6939 | * |
| 6940 | * Server indicates whether the FSID is present, moved, or not |
| 6941 | * recognized. This operation is necessary to clear a LEASE_MOVED |
| 6942 | * condition for this client ID. |
| 6943 | * |
| 6944 | * Returns NFS4_OK if the FSID is present on this server, |
| 6945 | * -NFS4ERR_MOVED if the FSID is no longer present, a negative |
| 6946 | * NFS4ERR code if some error occurred on the server, or a |
| 6947 | * negative errno if a local failure occurred. |
| 6948 | */ |
| 6949 | int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
| 6950 | { |
| 6951 | struct nfs_server *server = NFS_SERVER(inode); |
| 6952 | struct nfs_client *clp = server->nfs_client; |
| 6953 | const struct nfs4_mig_recovery_ops *ops = |
| 6954 | clp->cl_mvops->mig_recovery_ops; |
| 6955 | struct nfs4_exception exception = { }; |
| 6956 | int status; |
| 6957 | |
| 6958 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
| 6959 | (unsigned long long)server->fsid.major, |
| 6960 | (unsigned long long)server->fsid.minor, |
| 6961 | clp->cl_hostname); |
| 6962 | nfs_display_fhandle(NFS_FH(inode), __func__); |
| 6963 | |
| 6964 | do { |
| 6965 | status = ops->fsid_present(inode, cred); |
| 6966 | if (status != -NFS4ERR_DELAY) |
| 6967 | break; |
| 6968 | nfs4_handle_exception(server, status, &exception); |
| 6969 | } while (exception.retry); |
| 6970 | return status; |
| 6971 | } |
| 6972 | |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6973 | /** |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6974 | * If 'use_integrity' is true and the state managment nfs_client |
| 6975 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
| 6976 | * and the machine credential as per RFC3530bis and RFC5661 Security |
| 6977 | * Considerations sections. Otherwise, just use the user cred with the |
| 6978 | * filesystem's rpc_client. |
Andy Adamson | 5ec16a8 | 2013-08-08 10:57:55 -0400 | [diff] [blame] | 6979 | */ |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6980 | 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] | 6981 | { |
| 6982 | int status; |
| 6983 | struct nfs4_secinfo_arg args = { |
| 6984 | .dir_fh = NFS_FH(dir), |
| 6985 | .name = name, |
| 6986 | }; |
| 6987 | struct nfs4_secinfo_res res = { |
| 6988 | .flavors = flavors, |
| 6989 | }; |
| 6990 | struct rpc_message msg = { |
| 6991 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 6992 | .rpc_argp = &args, |
| 6993 | .rpc_resp = &res, |
| 6994 | }; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6995 | struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 6996 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 6997 | |
| 6998 | if (use_integrity) { |
| 6999 | clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7000 | cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
| 7001 | msg.rpc_cred = cred; |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7002 | } |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7003 | |
| 7004 | dprintk("NFS call secinfo %s\n", name->name); |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7005 | |
| 7006 | nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
| 7007 | NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
| 7008 | |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7009 | status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
| 7010 | &res.seq_res, 0); |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7011 | dprintk("NFS reply secinfo: %d\n", status); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7012 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 7013 | if (cred) |
| 7014 | put_rpccred(cred); |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7015 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7016 | return status; |
| 7017 | } |
| 7018 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 7019 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 7020 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7021 | { |
| 7022 | struct nfs4_exception exception = { }; |
| 7023 | int err; |
| 7024 | do { |
Weston Andros Adamson | a5250de | 2013-09-03 15:18:49 -0400 | [diff] [blame] | 7025 | err = -NFS4ERR_WRONGSEC; |
| 7026 | |
| 7027 | /* try to use integrity protection with machine cred */ |
| 7028 | if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client)) |
| 7029 | err = _nfs4_proc_secinfo(dir, name, flavors, true); |
| 7030 | |
| 7031 | /* |
| 7032 | * if unable to use integrity protection, or SECINFO with |
| 7033 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 7034 | * disallowed by spec, but exists in deployed servers) use |
| 7035 | * the current filesystem's rpc_client and the user cred. |
| 7036 | */ |
| 7037 | if (err == -NFS4ERR_WRONGSEC) |
| 7038 | err = _nfs4_proc_secinfo(dir, name, flavors, false); |
| 7039 | |
Trond Myklebust | 078ea3d | 2013-08-12 16:45:55 -0400 | [diff] [blame] | 7040 | trace_nfs4_secinfo(dir, name, err); |
| 7041 | err = nfs4_handle_exception(NFS_SERVER(dir), err, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 7042 | &exception); |
| 7043 | } while (exception.retry); |
| 7044 | return err; |
| 7045 | } |
| 7046 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 7047 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7048 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7049 | * Check the exchange flags returned by the server for invalid flags, having |
| 7050 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 7051 | * DS flags set. |
| 7052 | */ |
| 7053 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 7054 | { |
| 7055 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 7056 | goto out_inval; |
| 7057 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 7058 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 7059 | goto out_inval; |
| 7060 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 7061 | goto out_inval; |
| 7062 | return NFS_OK; |
| 7063 | out_inval: |
| 7064 | return -NFS4ERR_INVAL; |
| 7065 | } |
| 7066 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7067 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 7068 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 7069 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7070 | { |
| 7071 | if (a->server_scope_sz == b->server_scope_sz && |
| 7072 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 7073 | return true; |
| 7074 | |
| 7075 | return false; |
| 7076 | } |
| 7077 | |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7078 | static void |
| 7079 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
| 7080 | { |
| 7081 | } |
| 7082 | |
| 7083 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
| 7084 | .rpc_call_done = &nfs4_bind_one_conn_to_session_done, |
| 7085 | }; |
| 7086 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 7087 | /* |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7088 | * nfs4_proc_bind_one_conn_to_session() |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7089 | * |
| 7090 | * The 4.1 client currently uses the same TCP connection for the |
| 7091 | * fore and backchannel. |
| 7092 | */ |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7093 | static |
| 7094 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
| 7095 | struct rpc_xprt *xprt, |
| 7096 | struct nfs_client *clp, |
| 7097 | struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7098 | { |
| 7099 | int status; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7100 | struct nfs41_bind_conn_to_session_args args = { |
| 7101 | .client = clp, |
| 7102 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
| 7103 | }; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7104 | struct nfs41_bind_conn_to_session_res res; |
| 7105 | struct rpc_message msg = { |
| 7106 | .rpc_proc = |
| 7107 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7108 | .rpc_argp = &args, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7109 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 7110 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7111 | }; |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7112 | struct rpc_task_setup task_setup_data = { |
| 7113 | .rpc_client = clnt, |
| 7114 | .rpc_xprt = xprt, |
Andy Adamson | 02a95de | 2016-02-05 16:08:37 -0500 | [diff] [blame] | 7115 | .callback_ops = &nfs4_bind_one_conn_to_session_ops, |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7116 | .rpc_message = &msg, |
| 7117 | .flags = RPC_TASK_TIMEOUT, |
| 7118 | }; |
| 7119 | struct rpc_task *task; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7120 | |
| 7121 | dprintk("--> %s\n", __func__); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7122 | |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7123 | nfs4_copy_sessionid(&args.sessionid, &clp->cl_session->sess_id); |
| 7124 | if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) |
| 7125 | args.dir = NFS4_CDFC4_FORE; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7126 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7127 | /* Do not set the backchannel flag unless this is clnt->cl_xprt */ |
| 7128 | if (xprt != rcu_access_pointer(clnt->cl_xprt)) |
| 7129 | args.dir = NFS4_CDFC4_FORE; |
| 7130 | |
| 7131 | task = rpc_run_task(&task_setup_data); |
| 7132 | if (!IS_ERR(task)) { |
| 7133 | status = task->tk_status; |
| 7134 | rpc_put_task(task); |
| 7135 | } else |
| 7136 | status = PTR_ERR(task); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7137 | trace_nfs4_bind_conn_to_session(clp, status); |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7138 | if (status == 0) { |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7139 | if (memcmp(res.sessionid.data, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7140 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 7141 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 7142 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7143 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7144 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7145 | if ((res.dir & args.dir) != res.dir || res.dir == 0) { |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7146 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 7147 | __func__); |
| 7148 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7149 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7150 | } |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7151 | 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] | 7152 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 7153 | __func__); |
| 7154 | status = -EIO; |
Trond Myklebust | 71a097c | 2015-02-18 09:27:18 -0800 | [diff] [blame] | 7155 | goto out; |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7156 | } |
| 7157 | } |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7158 | out: |
| 7159 | dprintk("<-- %s status= %d\n", __func__, status); |
| 7160 | return status; |
| 7161 | } |
| 7162 | |
Trond Myklebust | d9ddbf5 | 2016-01-30 22:58:24 -0500 | [diff] [blame] | 7163 | struct rpc_bind_conn_calldata { |
| 7164 | struct nfs_client *clp; |
| 7165 | struct rpc_cred *cred; |
| 7166 | }; |
| 7167 | |
| 7168 | static int |
| 7169 | nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt, |
| 7170 | struct rpc_xprt *xprt, |
| 7171 | void *calldata) |
| 7172 | { |
| 7173 | struct rpc_bind_conn_calldata *p = calldata; |
| 7174 | |
| 7175 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
| 7176 | } |
| 7177 | |
| 7178 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
| 7179 | { |
| 7180 | struct rpc_bind_conn_calldata data = { |
| 7181 | .clp = clp, |
| 7182 | .cred = cred, |
| 7183 | }; |
| 7184 | return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, |
| 7185 | nfs4_proc_bind_conn_to_session_callback, &data); |
| 7186 | } |
| 7187 | |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 7188 | /* |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7189 | * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map |
| 7190 | * 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] | 7191 | */ |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7192 | static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = { |
| 7193 | .how = SP4_MACH_CRED, |
| 7194 | .enforce.u.words = { |
| 7195 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7196 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7197 | 1 << (OP_CREATE_SESSION - 32) | |
| 7198 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7199 | 1 << (OP_DESTROY_CLIENTID - 32) |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7200 | }, |
| 7201 | .allow.u.words = { |
| 7202 | [0] = 1 << (OP_CLOSE) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7203 | 1 << (OP_OPEN_DOWNGRADE) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7204 | 1 << (OP_LOCKU) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7205 | 1 << (OP_DELEGRETURN) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7206 | 1 << (OP_COMMIT), |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7207 | [1] = 1 << (OP_SECINFO - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7208 | 1 << (OP_SECINFO_NO_NAME - 32) | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7209 | 1 << (OP_LAYOUTRETURN - 32) | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7210 | 1 << (OP_TEST_STATEID - 32) | |
Weston Andros Adamson | a027962 | 2013-09-10 18:44:30 -0400 | [diff] [blame] | 7211 | 1 << (OP_FREE_STATEID - 32) | |
| 7212 | 1 << (OP_WRITE - 32) |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7213 | } |
| 7214 | }; |
| 7215 | |
| 7216 | /* |
| 7217 | * Select the state protection mode for client `clp' given the server results |
| 7218 | * from exchange_id in `sp'. |
| 7219 | * |
| 7220 | * Returns 0 on success, negative errno otherwise. |
| 7221 | */ |
| 7222 | static int nfs4_sp4_select_mode(struct nfs_client *clp, |
| 7223 | struct nfs41_state_protection *sp) |
| 7224 | { |
| 7225 | static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = { |
| 7226 | [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) | |
| 7227 | 1 << (OP_EXCHANGE_ID - 32) | |
| 7228 | 1 << (OP_CREATE_SESSION - 32) | |
| 7229 | 1 << (OP_DESTROY_SESSION - 32) | |
| 7230 | 1 << (OP_DESTROY_CLIENTID - 32) |
| 7231 | }; |
| 7232 | unsigned int i; |
| 7233 | |
| 7234 | if (sp->how == SP4_MACH_CRED) { |
| 7235 | /* Print state protect result */ |
| 7236 | dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n"); |
| 7237 | for (i = 0; i <= LAST_NFS4_OP; i++) { |
| 7238 | if (test_bit(i, sp->enforce.u.longs)) |
| 7239 | dfprintk(MOUNT, " enforce op %d\n", i); |
| 7240 | if (test_bit(i, sp->allow.u.longs)) |
| 7241 | dfprintk(MOUNT, " allow op %d\n", i); |
| 7242 | } |
| 7243 | |
| 7244 | /* make sure nothing is on enforce list that isn't supported */ |
| 7245 | for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) { |
| 7246 | if (sp->enforce.u.words[i] & ~supported_enforce[i]) { |
| 7247 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7248 | return -EINVAL; |
| 7249 | } |
| 7250 | } |
| 7251 | |
| 7252 | /* |
| 7253 | * Minimal mode - state operations are allowed to use machine |
| 7254 | * credential. Note this already happens by default, so the |
| 7255 | * client doesn't have to do anything more than the negotiation. |
| 7256 | * |
| 7257 | * NOTE: we don't care if EXCHANGE_ID is in the list - |
| 7258 | * we're already using the machine cred for exchange_id |
| 7259 | * and will never use a different cred. |
| 7260 | */ |
| 7261 | if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) && |
| 7262 | test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) && |
| 7263 | test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) && |
| 7264 | test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) { |
| 7265 | dfprintk(MOUNT, "sp4_mach_cred:\n"); |
| 7266 | dfprintk(MOUNT, " minimal mode enabled\n"); |
| 7267 | set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags); |
| 7268 | } else { |
| 7269 | dfprintk(MOUNT, "sp4_mach_cred: disabled\n"); |
| 7270 | return -EINVAL; |
| 7271 | } |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7272 | |
| 7273 | if (test_bit(OP_CLOSE, sp->allow.u.longs) && |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7274 | test_bit(OP_OPEN_DOWNGRADE, sp->allow.u.longs) && |
| 7275 | test_bit(OP_DELEGRETURN, sp->allow.u.longs) && |
Weston Andros Adamson | fa94072 | 2013-08-13 16:37:34 -0400 | [diff] [blame] | 7276 | test_bit(OP_LOCKU, sp->allow.u.longs)) { |
| 7277 | dfprintk(MOUNT, " cleanup mode enabled\n"); |
| 7278 | set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags); |
| 7279 | } |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7280 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 7281 | if (test_bit(OP_LAYOUTRETURN, sp->allow.u.longs)) { |
| 7282 | dfprintk(MOUNT, " pnfs cleanup mode enabled\n"); |
| 7283 | set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 7284 | &clp->cl_sp4_flags); |
| 7285 | } |
| 7286 | |
Weston Andros Adamson | 8b5bee2 | 2013-08-13 16:37:35 -0400 | [diff] [blame] | 7287 | if (test_bit(OP_SECINFO, sp->allow.u.longs) && |
| 7288 | test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) { |
| 7289 | dfprintk(MOUNT, " secinfo mode enabled\n"); |
| 7290 | set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags); |
| 7291 | } |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 7292 | |
| 7293 | if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) && |
| 7294 | test_bit(OP_FREE_STATEID, sp->allow.u.longs)) { |
| 7295 | dfprintk(MOUNT, " stateid mode enabled\n"); |
| 7296 | set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags); |
| 7297 | } |
Weston Andros Adamson | 8c21c62 | 2013-08-13 16:37:37 -0400 | [diff] [blame] | 7298 | |
| 7299 | if (test_bit(OP_WRITE, sp->allow.u.longs)) { |
| 7300 | dfprintk(MOUNT, " write mode enabled\n"); |
| 7301 | set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags); |
| 7302 | } |
| 7303 | |
| 7304 | if (test_bit(OP_COMMIT, sp->allow.u.longs)) { |
| 7305 | dfprintk(MOUNT, " commit mode enabled\n"); |
| 7306 | set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags); |
| 7307 | } |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7308 | } |
| 7309 | |
| 7310 | return 0; |
| 7311 | } |
| 7312 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7313 | struct nfs41_exchange_id_data { |
| 7314 | struct nfs41_exchange_id_res res; |
| 7315 | struct nfs41_exchange_id_args args; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7316 | struct rpc_xprt *xprt; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7317 | int rpc_status; |
| 7318 | }; |
| 7319 | |
| 7320 | static void nfs4_exchange_id_done(struct rpc_task *task, void *data) |
| 7321 | { |
| 7322 | struct nfs41_exchange_id_data *cdata = |
| 7323 | (struct nfs41_exchange_id_data *)data; |
| 7324 | struct nfs_client *clp = cdata->args.client; |
| 7325 | int status = task->tk_status; |
| 7326 | |
| 7327 | trace_nfs4_exchange_id(clp, status); |
| 7328 | |
| 7329 | if (status == 0) |
| 7330 | status = nfs4_check_cl_exchange_flags(cdata->res.flags); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7331 | |
| 7332 | if (cdata->xprt && status == 0) { |
| 7333 | status = nfs4_detect_session_trunking(clp, &cdata->res, |
| 7334 | cdata->xprt); |
| 7335 | goto out; |
| 7336 | } |
| 7337 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7338 | if (status == 0) |
| 7339 | status = nfs4_sp4_select_mode(clp, &cdata->res.state_protect); |
| 7340 | |
| 7341 | if (status == 0) { |
| 7342 | clp->cl_clientid = cdata->res.clientid; |
| 7343 | clp->cl_exchange_flags = cdata->res.flags; |
| 7344 | /* Client ID is not confirmed */ |
| 7345 | if (!(cdata->res.flags & EXCHGID4_FLAG_CONFIRMED_R)) { |
| 7346 | clear_bit(NFS4_SESSION_ESTABLISHED, |
| 7347 | &clp->cl_session->session_state); |
| 7348 | clp->cl_seqid = cdata->res.seqid; |
| 7349 | } |
| 7350 | |
| 7351 | kfree(clp->cl_serverowner); |
| 7352 | clp->cl_serverowner = cdata->res.server_owner; |
| 7353 | cdata->res.server_owner = NULL; |
| 7354 | |
| 7355 | /* use the most recent implementation id */ |
| 7356 | kfree(clp->cl_implid); |
| 7357 | clp->cl_implid = cdata->res.impl_id; |
| 7358 | cdata->res.impl_id = NULL; |
| 7359 | |
| 7360 | if (clp->cl_serverscope != NULL && |
| 7361 | !nfs41_same_server_scope(clp->cl_serverscope, |
| 7362 | cdata->res.server_scope)) { |
| 7363 | dprintk("%s: server_scope mismatch detected\n", |
| 7364 | __func__); |
| 7365 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 7366 | kfree(clp->cl_serverscope); |
| 7367 | clp->cl_serverscope = NULL; |
| 7368 | } |
| 7369 | |
| 7370 | if (clp->cl_serverscope == NULL) { |
| 7371 | clp->cl_serverscope = cdata->res.server_scope; |
| 7372 | cdata->res.server_scope = NULL; |
| 7373 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7374 | /* Save the EXCHANGE_ID verifier session trunk tests */ |
| 7375 | memcpy(clp->cl_confirm.data, cdata->args.verifier->data, |
| 7376 | sizeof(clp->cl_confirm.data)); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7377 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7378 | out: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7379 | cdata->rpc_status = status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7380 | return; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7381 | } |
| 7382 | |
| 7383 | static void nfs4_exchange_id_release(void *data) |
| 7384 | { |
| 7385 | struct nfs41_exchange_id_data *cdata = |
| 7386 | (struct nfs41_exchange_id_data *)data; |
| 7387 | |
| 7388 | nfs_put_client(cdata->args.client); |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7389 | if (cdata->xprt) { |
| 7390 | xprt_put(cdata->xprt); |
| 7391 | rpc_clnt_xprt_switch_put(cdata->args.client->cl_rpcclient); |
| 7392 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7393 | kfree(cdata->res.impl_id); |
| 7394 | kfree(cdata->res.server_scope); |
| 7395 | kfree(cdata->res.server_owner); |
| 7396 | kfree(cdata); |
| 7397 | } |
| 7398 | |
| 7399 | static const struct rpc_call_ops nfs4_exchange_id_call_ops = { |
| 7400 | .rpc_call_done = nfs4_exchange_id_done, |
| 7401 | .rpc_release = nfs4_exchange_id_release, |
| 7402 | }; |
| 7403 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7404 | /* |
| 7405 | * _nfs4_proc_exchange_id() |
| 7406 | * |
| 7407 | * Wrapper for EXCHANGE_ID operation. |
| 7408 | */ |
| 7409 | 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] | 7410 | u32 sp4_how, struct rpc_xprt *xprt) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7411 | { |
| 7412 | nfs4_verifier verifier; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7413 | struct rpc_message msg = { |
| 7414 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7415 | .rpc_cred = cred, |
| 7416 | }; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7417 | struct rpc_task_setup task_setup_data = { |
| 7418 | .rpc_client = clp->cl_rpcclient, |
| 7419 | .callback_ops = &nfs4_exchange_id_call_ops, |
| 7420 | .rpc_message = &msg, |
| 7421 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
| 7422 | }; |
| 7423 | struct nfs41_exchange_id_data *calldata; |
| 7424 | struct rpc_task *task; |
| 7425 | int status = -EIO; |
| 7426 | |
| 7427 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 7428 | goto out; |
| 7429 | |
| 7430 | status = -ENOMEM; |
| 7431 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
| 7432 | if (!calldata) |
| 7433 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7434 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7435 | if (!xprt) |
| 7436 | nfs4_init_boot_verifier(clp, &verifier); |
Jeff Layton | 873e385 | 2015-06-09 19:44:00 -0400 | [diff] [blame] | 7437 | |
| 7438 | status = nfs4_init_uniform_client_string(clp); |
| 7439 | if (status) |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7440 | goto out_calldata; |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7441 | |
| 7442 | dprintk("NFS call exchange_id auth=%s, '%s'\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7443 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Jeff Layton | 3a6bb73 | 2015-06-09 19:43:57 -0400 | [diff] [blame] | 7444 | clp->cl_owner_id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7445 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7446 | calldata->res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
| 7447 | GFP_NOFS); |
| 7448 | status = -ENOMEM; |
| 7449 | if (unlikely(calldata->res.server_owner == NULL)) |
| 7450 | goto out_calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7451 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7452 | calldata->res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 7453 | GFP_NOFS); |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7454 | if (unlikely(calldata->res.server_scope == NULL)) |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 7455 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7456 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7457 | calldata->res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
| 7458 | if (unlikely(calldata->res.impl_id == NULL)) |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7459 | goto out_server_scope; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7460 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7461 | switch (sp4_how) { |
| 7462 | case SP4_NONE: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7463 | calldata->args.state_protect.how = SP4_NONE; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7464 | break; |
| 7465 | |
| 7466 | case SP4_MACH_CRED: |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7467 | calldata->args.state_protect = nfs4_sp4_mach_cred_request; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7468 | break; |
| 7469 | |
| 7470 | default: |
| 7471 | /* unsupported! */ |
| 7472 | WARN_ON_ONCE(1); |
| 7473 | status = -EINVAL; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7474 | goto out_impl_id; |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7475 | } |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7476 | if (xprt) { |
| 7477 | calldata->xprt = xprt; |
| 7478 | task_setup_data.rpc_xprt = xprt; |
| 7479 | task_setup_data.flags = |
| 7480 | RPC_TASK_SOFT|RPC_TASK_SOFTCONN|RPC_TASK_ASYNC; |
| 7481 | calldata->args.verifier = &clp->cl_confirm; |
| 7482 | } else { |
| 7483 | calldata->args.verifier = &verifier; |
| 7484 | } |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7485 | calldata->args.client = clp; |
| 7486 | #ifdef CONFIG_NFS_V4_1_MIGRATION |
| 7487 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7488 | EXCHGID4_FLAG_BIND_PRINC_STATEID | |
| 7489 | EXCHGID4_FLAG_SUPP_MOVED_MIGR, |
| 7490 | #else |
| 7491 | calldata->args.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER | |
| 7492 | EXCHGID4_FLAG_BIND_PRINC_STATEID, |
| 7493 | #endif |
| 7494 | msg.rpc_argp = &calldata->args; |
| 7495 | msg.rpc_resp = &calldata->res; |
| 7496 | task_setup_data.callback_data = calldata; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 7497 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7498 | task = rpc_run_task(&task_setup_data); |
| 7499 | if (IS_ERR(task)) { |
| 7500 | status = PTR_ERR(task); |
| 7501 | goto out_impl_id; |
Kinglong Mee | 6b55970 | 2015-07-01 11:54:53 +0800 | [diff] [blame] | 7502 | } |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7503 | |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7504 | if (!xprt) { |
| 7505 | status = rpc_wait_for_completion_task(task); |
| 7506 | if (!status) |
| 7507 | status = calldata->rpc_status; |
| 7508 | } else /* session trunking test */ |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7509 | status = calldata->rpc_status; |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7510 | |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7511 | rpc_put_task(task); |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 7512 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 7513 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7514 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 7515 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7516 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 7517 | clp->cl_implid->date.seconds, |
| 7518 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 7519 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7520 | return status; |
Andy Adamson | 8d89bd7 | 2016-09-09 09:22:18 -0400 | [diff] [blame] | 7521 | |
| 7522 | out_impl_id: |
| 7523 | kfree(calldata->res.impl_id); |
| 7524 | out_server_scope: |
| 7525 | kfree(calldata->res.server_scope); |
| 7526 | out_server_owner: |
| 7527 | kfree(calldata->res.server_owner); |
| 7528 | out_calldata: |
| 7529 | kfree(calldata); |
| 7530 | goto out; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 7531 | } |
| 7532 | |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7533 | /* |
| 7534 | * nfs4_proc_exchange_id() |
| 7535 | * |
| 7536 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 7537 | * |
| 7538 | * Since the clientid has expired, all compounds using sessions |
| 7539 | * associated with the stale clientid will be returning |
| 7540 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 7541 | * be in some phase of session reset. |
| 7542 | * |
| 7543 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
| 7544 | */ |
| 7545 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
| 7546 | { |
| 7547 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
| 7548 | int status; |
| 7549 | |
| 7550 | /* try SP4_MACH_CRED if krb5i/p */ |
| 7551 | if (authflavor == RPC_AUTH_GSS_KRB5I || |
| 7552 | authflavor == RPC_AUTH_GSS_KRB5P) { |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7553 | status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7554 | if (!status) |
| 7555 | return 0; |
| 7556 | } |
| 7557 | |
| 7558 | /* try SP4_NONE */ |
Andy Adamson | ad0849a | 2016-09-09 09:22:28 -0400 | [diff] [blame] | 7559 | return _nfs4_proc_exchange_id(clp, cred, SP4_NONE, NULL); |
Weston Andros Adamson | 2031cd1 | 2013-08-13 16:37:32 -0400 | [diff] [blame] | 7560 | } |
| 7561 | |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 7562 | /** |
| 7563 | * nfs4_test_session_trunk |
| 7564 | * |
| 7565 | * This is an add_xprt_test() test function called from |
| 7566 | * rpc_clnt_setup_test_and_add_xprt. |
| 7567 | * |
| 7568 | * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt |
| 7569 | * and is dereferrenced in nfs4_exchange_id_release |
| 7570 | * |
| 7571 | * Upon success, add the new transport to the rpc_clnt |
| 7572 | * |
| 7573 | * @clnt: struct rpc_clnt to get new transport |
| 7574 | * @xprt: the rpc_xprt to test |
| 7575 | * @data: call data for _nfs4_proc_exchange_id. |
| 7576 | */ |
| 7577 | int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
| 7578 | void *data) |
| 7579 | { |
| 7580 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
| 7581 | u32 sp4_how; |
| 7582 | |
| 7583 | dprintk("--> %s try %s\n", __func__, |
| 7584 | xprt->address_strings[RPC_DISPLAY_ADDR]); |
| 7585 | |
| 7586 | sp4_how = (adata->clp->cl_sp4_flags == 0 ? SP4_NONE : SP4_MACH_CRED); |
| 7587 | |
| 7588 | /* Test connection for session trunking. Async exchange_id call */ |
| 7589 | return _nfs4_proc_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
| 7590 | } |
| 7591 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
| 7592 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7593 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7594 | struct rpc_cred *cred) |
| 7595 | { |
| 7596 | struct rpc_message msg = { |
| 7597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 7598 | .rpc_argp = clp, |
| 7599 | .rpc_cred = cred, |
| 7600 | }; |
| 7601 | int status; |
| 7602 | |
| 7603 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7604 | trace_nfs4_destroy_clientid(clp, status); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7605 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 7606 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7607 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 7608 | return status; |
| 7609 | } |
| 7610 | |
| 7611 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 7612 | struct rpc_cred *cred) |
| 7613 | { |
| 7614 | unsigned int loop; |
| 7615 | int ret; |
| 7616 | |
| 7617 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 7618 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 7619 | switch (ret) { |
| 7620 | case -NFS4ERR_DELAY: |
| 7621 | case -NFS4ERR_CLIENTID_BUSY: |
| 7622 | ssleep(1); |
| 7623 | break; |
| 7624 | default: |
| 7625 | return ret; |
| 7626 | } |
| 7627 | } |
| 7628 | return 0; |
| 7629 | } |
| 7630 | |
| 7631 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 7632 | { |
| 7633 | struct rpc_cred *cred; |
| 7634 | int ret = 0; |
| 7635 | |
| 7636 | if (clp->cl_mvops->minor_version < 1) |
| 7637 | goto out; |
| 7638 | if (clp->cl_exchange_flags == 0) |
| 7639 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 7640 | if (clp->cl_preserve_clid) |
| 7641 | goto out; |
Chuck Lever | 73d8bde | 2013-07-24 12:28:37 -0400 | [diff] [blame] | 7642 | cred = nfs4_get_clid_cred(clp); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 7643 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 7644 | if (cred) |
| 7645 | put_rpccred(cred); |
| 7646 | switch (ret) { |
| 7647 | case 0: |
| 7648 | case -NFS4ERR_STALE_CLIENTID: |
| 7649 | clp->cl_exchange_flags = 0; |
| 7650 | } |
| 7651 | out: |
| 7652 | return ret; |
| 7653 | } |
| 7654 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7655 | struct nfs4_get_lease_time_data { |
| 7656 | struct nfs4_get_lease_time_args *args; |
| 7657 | struct nfs4_get_lease_time_res *res; |
| 7658 | struct nfs_client *clp; |
| 7659 | }; |
| 7660 | |
| 7661 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 7662 | void *calldata) |
| 7663 | { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7664 | struct nfs4_get_lease_time_data *data = |
| 7665 | (struct nfs4_get_lease_time_data *)calldata; |
| 7666 | |
| 7667 | dprintk("--> %s\n", __func__); |
| 7668 | /* just setup sequence, do not trigger session recovery |
| 7669 | since we're invoked within one */ |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 7670 | nfs41_setup_sequence(data->clp->cl_session, |
| 7671 | &data->args->la_seq_args, |
| 7672 | &data->res->lr_seq_res, |
| 7673 | task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7674 | dprintk("<-- %s\n", __func__); |
| 7675 | } |
| 7676 | |
| 7677 | /* |
| 7678 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 7679 | * from sequence operation or clientid errors. |
| 7680 | */ |
| 7681 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 7682 | { |
| 7683 | struct nfs4_get_lease_time_data *data = |
| 7684 | (struct nfs4_get_lease_time_data *)calldata; |
| 7685 | |
| 7686 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 7687 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 7688 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7689 | switch (task->tk_status) { |
| 7690 | case -NFS4ERR_DELAY: |
| 7691 | case -NFS4ERR_GRACE: |
| 7692 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 7693 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 7694 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 7695 | /* fall through */ |
| 7696 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 7697 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7698 | return; |
| 7699 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7700 | dprintk("<-- %s\n", __func__); |
| 7701 | } |
| 7702 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7703 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7704 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 7705 | .rpc_call_done = nfs4_get_lease_time_done, |
| 7706 | }; |
| 7707 | |
| 7708 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 7709 | { |
| 7710 | struct rpc_task *task; |
| 7711 | struct nfs4_get_lease_time_args args; |
| 7712 | struct nfs4_get_lease_time_res res = { |
| 7713 | .lr_fsinfo = fsinfo, |
| 7714 | }; |
| 7715 | struct nfs4_get_lease_time_data data = { |
| 7716 | .args = &args, |
| 7717 | .res = &res, |
| 7718 | .clp = clp, |
| 7719 | }; |
| 7720 | struct rpc_message msg = { |
| 7721 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 7722 | .rpc_argp = &args, |
| 7723 | .rpc_resp = &res, |
| 7724 | }; |
| 7725 | struct rpc_task_setup task_setup = { |
| 7726 | .rpc_client = clp->cl_rpcclient, |
| 7727 | .rpc_message = &msg, |
| 7728 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7729 | .callback_data = &data, |
| 7730 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7731 | }; |
| 7732 | int status; |
| 7733 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 7734 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 7735 | nfs4_set_sequence_privileged(&args.la_seq_args); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 7736 | dprintk("--> %s\n", __func__); |
| 7737 | task = rpc_run_task(&task_setup); |
| 7738 | |
| 7739 | if (IS_ERR(task)) |
| 7740 | status = PTR_ERR(task); |
| 7741 | else { |
| 7742 | status = task->tk_status; |
| 7743 | rpc_put_task(task); |
| 7744 | } |
| 7745 | dprintk("<-- %s return %d\n", __func__, status); |
| 7746 | |
| 7747 | return status; |
| 7748 | } |
| 7749 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7750 | /* |
| 7751 | * Initialize the values to be used by the client in CREATE_SESSION |
| 7752 | * If nfs4_init_session set the fore channel request and response sizes, |
| 7753 | * use them. |
| 7754 | * |
| 7755 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 7756 | * always set csa_cachethis to FALSE because the current implementation |
| 7757 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 7758 | */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7759 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args, |
| 7760 | struct rpc_clnt *clnt) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7761 | { |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7762 | unsigned int max_rqst_sz, max_resp_sz; |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7763 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7764 | |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7765 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
| 7766 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
| 7767 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7768 | /* Fore channel attributes */ |
Andy Adamson | 18aad3d | 2013-06-26 12:21:49 -0400 | [diff] [blame] | 7769 | args->fc_attrs.max_rqst_sz = max_rqst_sz; |
| 7770 | args->fc_attrs.max_resp_sz = max_resp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7771 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 7772 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7773 | |
| 7774 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7775 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7776 | __func__, |
| 7777 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 7778 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7779 | |
| 7780 | /* Back channel attributes */ |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7781 | args->bc_attrs.max_rqst_sz = max_bc_payload; |
| 7782 | args->bc_attrs.max_resp_sz = max_bc_payload; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7783 | args->bc_attrs.max_resp_sz_cached = 0; |
| 7784 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7785 | 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] | 7786 | |
| 7787 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 7788 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 7789 | __func__, |
| 7790 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 7791 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 7792 | args->bc_attrs.max_reqs); |
| 7793 | } |
| 7794 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7795 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, |
| 7796 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7797 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7798 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7799 | struct nfs4_channel_attrs *rcvd = &res->fc_attrs; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7800 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7801 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 7802 | return -EINVAL; |
| 7803 | /* |
| 7804 | * Our requested max_ops is the minimum we need; we're not |
| 7805 | * prepared to break up compounds into smaller pieces than that. |
| 7806 | * So, no point even trying to continue if the server won't |
| 7807 | * cooperate: |
| 7808 | */ |
| 7809 | if (rcvd->max_ops < sent->max_ops) |
| 7810 | return -EINVAL; |
| 7811 | if (rcvd->max_reqs == 0) |
| 7812 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 7813 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 7814 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7815 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7816 | } |
| 7817 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7818 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, |
| 7819 | struct nfs41_create_session_res *res) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7820 | { |
| 7821 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7822 | struct nfs4_channel_attrs *rcvd = &res->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7823 | |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7824 | if (!(res->flags & SESSION4_BACK_CHAN)) |
| 7825 | goto out; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7826 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 7827 | return -EINVAL; |
| 7828 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 7829 | return -EINVAL; |
| 7830 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 7831 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7832 | if (rcvd->max_ops > sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7833 | return -EINVAL; |
Trond Myklebust | 5405fc4 | 2016-08-29 20:03:52 -0400 | [diff] [blame] | 7834 | if (rcvd->max_reqs > sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7835 | return -EINVAL; |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7836 | out: |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7837 | return 0; |
| 7838 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7839 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7840 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7841 | struct nfs41_create_session_res *res) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7842 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7843 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7844 | |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7845 | ret = nfs4_verify_fore_channel_attrs(args, res); |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 7846 | if (ret) |
| 7847 | return ret; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7848 | return nfs4_verify_back_channel_attrs(args, res); |
| 7849 | } |
| 7850 | |
| 7851 | static void nfs4_update_session(struct nfs4_session *session, |
| 7852 | struct nfs41_create_session_res *res) |
| 7853 | { |
| 7854 | nfs4_copy_sessionid(&session->sess_id, &res->sessionid); |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7855 | /* Mark client id and session as being confirmed */ |
| 7856 | session->clp->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; |
| 7857 | set_bit(NFS4_SESSION_ESTABLISHED, &session->session_state); |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7858 | session->flags = res->flags; |
| 7859 | memcpy(&session->fc_attrs, &res->fc_attrs, sizeof(session->fc_attrs)); |
Trond Myklebust | b1c0df5 | 2015-02-18 11:34:58 -0800 | [diff] [blame] | 7860 | if (res->flags & SESSION4_BACK_CHAN) |
| 7861 | memcpy(&session->bc_attrs, &res->bc_attrs, |
| 7862 | sizeof(session->bc_attrs)); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7863 | } |
| 7864 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7865 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 7866 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7867 | { |
| 7868 | struct nfs4_session *session = clp->cl_session; |
| 7869 | struct nfs41_create_session_args args = { |
| 7870 | .client = clp, |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7871 | .clientid = clp->cl_clientid, |
| 7872 | .seqid = clp->cl_seqid, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7873 | .cb_program = NFS4_CALLBACK, |
| 7874 | }; |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7875 | struct nfs41_create_session_res res; |
| 7876 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7877 | struct rpc_message msg = { |
| 7878 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 7879 | .rpc_argp = &args, |
| 7880 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7881 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7882 | }; |
| 7883 | int status; |
| 7884 | |
Chuck Lever | 6b26cc8 | 2016-05-02 14:40:40 -0400 | [diff] [blame] | 7885 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 7886 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7887 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7888 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7889 | trace_nfs4_create_session(clp, status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7890 | |
Trond Myklebust | b519d40 | 2016-09-11 14:50:01 -0400 | [diff] [blame] | 7891 | switch (status) { |
| 7892 | case -NFS4ERR_STALE_CLIENTID: |
| 7893 | case -NFS4ERR_DELAY: |
| 7894 | case -ETIMEDOUT: |
| 7895 | case -EACCES: |
| 7896 | case -EAGAIN: |
| 7897 | goto out; |
| 7898 | }; |
| 7899 | |
| 7900 | clp->cl_seqid++; |
Trond Myklebust | 43095d3 | 2012-11-20 11:13:12 -0500 | [diff] [blame] | 7901 | if (!status) { |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 7902 | /* Verify the session's negotiated channel_attrs values */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7903 | status = nfs4_verify_channel_attrs(&args, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7904 | /* Increment the clientid slot sequence id */ |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7905 | if (status) |
| 7906 | goto out; |
| 7907 | nfs4_update_session(session, &res); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7908 | } |
Trond Myklebust | 79969dd | 2015-02-18 11:30:18 -0800 | [diff] [blame] | 7909 | out: |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7910 | return status; |
| 7911 | } |
| 7912 | |
| 7913 | /* |
| 7914 | * Issues a CREATE_SESSION operation to the server. |
| 7915 | * It is the responsibility of the caller to verify the session is |
| 7916 | * expired before calling this routine. |
| 7917 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7918 | 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] | 7919 | { |
| 7920 | int status; |
| 7921 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7922 | struct nfs4_session *session = clp->cl_session; |
| 7923 | |
| 7924 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 7925 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7926 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7927 | if (status) |
| 7928 | goto out; |
| 7929 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 7930 | /* Init or reset the session slot tables */ |
| 7931 | status = nfs4_setup_session_slot_tables(session); |
| 7932 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7933 | if (status) |
| 7934 | goto out; |
| 7935 | |
| 7936 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 7937 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 7938 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 7939 | out: |
| 7940 | dprintk("<-- %s\n", __func__); |
| 7941 | return status; |
| 7942 | } |
| 7943 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7944 | /* |
| 7945 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 7946 | * The caller must serialize access to this routine. |
| 7947 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7948 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 7949 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7950 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 7951 | struct rpc_message msg = { |
| 7952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 7953 | .rpc_argp = session, |
| 7954 | .rpc_cred = cred, |
| 7955 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7956 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7957 | |
| 7958 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 7959 | |
| 7960 | /* session is still being setup */ |
Trond Myklebust | e11259f | 2015-03-03 20:35:31 -0500 | [diff] [blame] | 7961 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
| 7962 | return 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7963 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 7964 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 7965 | trace_nfs4_destroy_session(session->clp, status); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7966 | |
| 7967 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 7968 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 7969 | "Session has been destroyed regardless...\n", status); |
| 7970 | |
| 7971 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 7972 | return status; |
| 7973 | } |
| 7974 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 7975 | /* |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 7976 | * Renew the cl_session lease. |
| 7977 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7978 | struct nfs4_sequence_data { |
| 7979 | struct nfs_client *clp; |
| 7980 | struct nfs4_sequence_args args; |
| 7981 | struct nfs4_sequence_res res; |
| 7982 | }; |
| 7983 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7984 | static void nfs41_sequence_release(void *data) |
| 7985 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7986 | struct nfs4_sequence_data *calldata = data; |
| 7987 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7988 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 7989 | if (atomic_read(&clp->cl_count) > 1) |
| 7990 | nfs4_schedule_state_renewal(clp); |
| 7991 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7992 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 7993 | } |
| 7994 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7995 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 7996 | { |
| 7997 | switch(task->tk_status) { |
| 7998 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 7999 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 8000 | return -EAGAIN; |
| 8001 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8002 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8003 | } |
| 8004 | return 0; |
| 8005 | } |
| 8006 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8007 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8008 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8009 | struct nfs4_sequence_data *calldata = data; |
| 8010 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8011 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8012 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 8013 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8014 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8015 | trace_nfs4_sequence(clp, task->tk_status); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8016 | if (task->tk_status < 0) { |
| 8017 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8018 | if (atomic_read(&clp->cl_count) == 1) |
| 8019 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8020 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8021 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 8022 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8023 | return; |
| 8024 | } |
| 8025 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8026 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8027 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8028 | dprintk("<-- %s\n", __func__); |
| 8029 | } |
| 8030 | |
| 8031 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 8032 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8033 | struct nfs4_sequence_data *calldata = data; |
| 8034 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8035 | struct nfs4_sequence_args *args; |
| 8036 | struct nfs4_sequence_res *res; |
| 8037 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8038 | args = task->tk_msg.rpc_argp; |
| 8039 | res = task->tk_msg.rpc_resp; |
| 8040 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8041 | nfs41_setup_sequence(clp->cl_session, args, res, task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8042 | } |
| 8043 | |
| 8044 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 8045 | .rpc_call_done = nfs41_sequence_call_done, |
| 8046 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 8047 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8048 | }; |
| 8049 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8050 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
| 8051 | struct rpc_cred *cred, |
| 8052 | bool is_privileged) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8053 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8054 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8055 | struct rpc_message msg = { |
| 8056 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 8057 | .rpc_cred = cred, |
| 8058 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8059 | struct rpc_task_setup task_setup_data = { |
| 8060 | .rpc_client = clp->cl_rpcclient, |
| 8061 | .rpc_message = &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8062 | .callback_ops = &nfs41_sequence_ops, |
Trond Myklebust | bc7a05c | 2013-04-08 17:50:28 -0400 | [diff] [blame] | 8063 | .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8064 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8065 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8066 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8067 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 8068 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8069 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 8070 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8071 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8072 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8073 | nfs4_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8074 | if (is_privileged) |
| 8075 | nfs4_set_sequence_privileged(&calldata->args); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8076 | msg.rpc_argp = &calldata->args; |
| 8077 | msg.rpc_resp = &calldata->res; |
| 8078 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8079 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8080 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8081 | return rpc_run_task(&task_setup_data); |
| 8082 | } |
| 8083 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8084 | 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] | 8085 | { |
| 8086 | struct rpc_task *task; |
| 8087 | int ret = 0; |
| 8088 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 8089 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
Andy Adamson | d1f456b | 2014-09-29 12:31:57 -0400 | [diff] [blame] | 8090 | return -EAGAIN; |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8091 | task = _nfs41_proc_sequence(clp, cred, false); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8092 | if (IS_ERR(task)) |
| 8093 | ret = PTR_ERR(task); |
| 8094 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 8095 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8096 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8097 | return ret; |
| 8098 | } |
| 8099 | |
| 8100 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 8101 | { |
| 8102 | struct rpc_task *task; |
| 8103 | int ret; |
| 8104 | |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8105 | task = _nfs41_proc_sequence(clp, cred, true); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8106 | if (IS_ERR(task)) { |
| 8107 | ret = PTR_ERR(task); |
| 8108 | goto out; |
| 8109 | } |
| 8110 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | be82416 | 2015-07-05 14:50:46 -0400 | [diff] [blame] | 8111 | if (!ret) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 8112 | ret = task->tk_status; |
| 8113 | rpc_put_task(task); |
| 8114 | out: |
| 8115 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 8116 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 8117 | } |
| 8118 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8119 | struct nfs4_reclaim_complete_data { |
| 8120 | struct nfs_client *clp; |
| 8121 | struct nfs41_reclaim_complete_args arg; |
| 8122 | struct nfs41_reclaim_complete_res res; |
| 8123 | }; |
| 8124 | |
| 8125 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 8126 | { |
| 8127 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8128 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8129 | nfs41_setup_sequence(calldata->clp->cl_session, |
| 8130 | &calldata->arg.seq_args, |
| 8131 | &calldata->res.seq_res, |
| 8132 | task); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8133 | } |
| 8134 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8135 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 8136 | { |
| 8137 | switch(task->tk_status) { |
| 8138 | case 0: |
| 8139 | case -NFS4ERR_COMPLETE_ALREADY: |
| 8140 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 8141 | break; |
| 8142 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8143 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 8144 | /* fall through */ |
| 8145 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8146 | return -EAGAIN; |
| 8147 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 8148 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8149 | } |
| 8150 | return 0; |
| 8151 | } |
| 8152 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8153 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 8154 | { |
| 8155 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8156 | struct nfs_client *clp = calldata->clp; |
| 8157 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 8158 | |
| 8159 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 8160 | if (!nfs41_sequence_done(task, res)) |
| 8161 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8162 | |
Trond Myklebust | c6d01c6 | 2013-08-09 11:51:26 -0400 | [diff] [blame] | 8163 | trace_nfs4_reclaim_complete(clp, task->tk_status); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 8164 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 8165 | rpc_restart_call_prepare(task); |
| 8166 | return; |
| 8167 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8168 | dprintk("<-- %s\n", __func__); |
| 8169 | } |
| 8170 | |
| 8171 | static void nfs4_free_reclaim_complete_data(void *data) |
| 8172 | { |
| 8173 | struct nfs4_reclaim_complete_data *calldata = data; |
| 8174 | |
| 8175 | kfree(calldata); |
| 8176 | } |
| 8177 | |
| 8178 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 8179 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 8180 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 8181 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 8182 | }; |
| 8183 | |
| 8184 | /* |
| 8185 | * Issue a global reclaim complete. |
| 8186 | */ |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8187 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
| 8188 | struct rpc_cred *cred) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8189 | { |
| 8190 | struct nfs4_reclaim_complete_data *calldata; |
| 8191 | struct rpc_task *task; |
| 8192 | struct rpc_message msg = { |
| 8193 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
Trond Myklebust | 965e9c2 | 2013-05-20 11:05:17 -0400 | [diff] [blame] | 8194 | .rpc_cred = cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8195 | }; |
| 8196 | struct rpc_task_setup task_setup_data = { |
| 8197 | .rpc_client = clp->cl_rpcclient, |
| 8198 | .rpc_message = &msg, |
| 8199 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 8200 | .flags = RPC_TASK_ASYNC, |
| 8201 | }; |
| 8202 | int status = -ENOMEM; |
| 8203 | |
| 8204 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 8205 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8206 | if (calldata == NULL) |
| 8207 | goto out; |
| 8208 | calldata->clp = clp; |
| 8209 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8210 | |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8211 | nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8212 | nfs4_set_sequence_privileged(&calldata->arg.seq_args); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8213 | msg.rpc_argp = &calldata->arg; |
| 8214 | msg.rpc_resp = &calldata->res; |
| 8215 | task_setup_data.callback_data = calldata; |
| 8216 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8217 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8218 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8219 | goto out; |
| 8220 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 8221 | status = nfs4_wait_for_completion_rpc_task(task); |
| 8222 | if (status == 0) |
| 8223 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8224 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 8225 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 8226 | out: |
| 8227 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8228 | return status; |
| 8229 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8230 | |
| 8231 | static void |
| 8232 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 8233 | { |
| 8234 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 8235 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8236 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8237 | |
| 8238 | dprintk("--> %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8239 | nfs41_setup_sequence(session, &lgp->args.seq_args, |
| 8240 | &lgp->res.seq_res, task); |
| 8241 | dprintk("<-- %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8242 | } |
| 8243 | |
| 8244 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 8245 | { |
| 8246 | struct nfs4_layoutget *lgp = calldata; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8247 | |
| 8248 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8249 | nfs41_sequence_process(task, &lgp->res.seq_res); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8250 | dprintk("<-- %s\n", __func__); |
| 8251 | } |
| 8252 | |
| 8253 | static int |
| 8254 | nfs4_layoutget_handle_exception(struct rpc_task *task, |
| 8255 | struct nfs4_layoutget *lgp, struct nfs4_exception *exception) |
| 8256 | { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8257 | struct inode *inode = lgp->args.inode; |
| 8258 | struct nfs_server *server = NFS_SERVER(inode); |
| 8259 | struct pnfs_layout_hdr *lo; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8260 | int nfs4err = task->tk_status; |
| 8261 | int err, status = 0; |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8262 | LIST_HEAD(head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8263 | |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8264 | dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8265 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8266 | switch (nfs4err) { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8267 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8268 | goto out; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8269 | |
| 8270 | /* |
| 8271 | * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs |
| 8272 | * on the file. set tk_status to -ENODATA to tell upper layer to |
| 8273 | * retry go inband. |
| 8274 | */ |
| 8275 | case -NFS4ERR_LAYOUTUNAVAILABLE: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8276 | status = -ENODATA; |
Peng Tao | 7c1e6e5 | 2015-12-05 17:01:01 +0800 | [diff] [blame] | 8277 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8278 | /* |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8279 | * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of |
| 8280 | * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3). |
| 8281 | */ |
| 8282 | case -NFS4ERR_BADLAYOUT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8283 | status = -EOVERFLOW; |
| 8284 | goto out; |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8285 | /* |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8286 | * NFS4ERR_LAYOUTTRYLATER is a conflict with another client |
Trond Myklebust | 21b874c | 2015-08-31 01:19:22 -0700 | [diff] [blame] | 8287 | * (or clients) writing to the same RAID stripe except when |
| 8288 | * the minlength argument is 0 (see RFC5661 section 18.43.3). |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8289 | * |
| 8290 | * Treat it like we would RECALLCONFLICT -- we retry for a little |
| 8291 | * while, and then eventually give up. |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8292 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8293 | case -NFS4ERR_LAYOUTTRYLATER: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8294 | if (lgp->args.minlength == 0) { |
| 8295 | status = -EOVERFLOW; |
| 8296 | goto out; |
Boaz Harrosh | ed7e542 | 2014-01-22 20:34:54 +0200 | [diff] [blame] | 8297 | } |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8298 | status = -EBUSY; |
| 8299 | break; |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8300 | case -NFS4ERR_RECALLCONFLICT: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8301 | status = -ERECALLCONFLICT; |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8302 | break; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8303 | case -NFS4ERR_DELEG_REVOKED: |
| 8304 | case -NFS4ERR_ADMIN_REVOKED: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8305 | case -NFS4ERR_EXPIRED: |
| 8306 | case -NFS4ERR_BAD_STATEID: |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8307 | exception->timeout = 0; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8308 | spin_lock(&inode->i_lock); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8309 | lo = NFS_I(inode)->layout; |
| 8310 | /* If the open stateid was bad, then recover it. */ |
| 8311 | if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || |
| 8312 | nfs4_stateid_match_other(&lgp->args.stateid, |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8313 | &lgp->args.ctx->state->stateid)) { |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8314 | spin_unlock(&inode->i_lock); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8315 | exception->state = lgp->args.ctx->state; |
Trond Myklebust | 26f4744 | 2016-09-22 13:39:10 -0400 | [diff] [blame] | 8316 | exception->stateid = &lgp->args.stateid; |
Trond Myklebust | 2259f96 | 2015-09-20 13:30:30 -0400 | [diff] [blame] | 8317 | break; |
| 8318 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8319 | |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8320 | /* |
| 8321 | * Mark the bad layout state as invalid, then retry |
| 8322 | */ |
Trond Myklebust | 668f455 | 2016-07-24 17:08:59 -0400 | [diff] [blame] | 8323 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Trond Myklebust | f7db0b2 | 2016-07-14 15:14:02 -0400 | [diff] [blame] | 8324 | spin_unlock(&inode->i_lock); |
| 8325 | pnfs_free_lseg_list(&head); |
| 8326 | status = -EAGAIN; |
| 8327 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8328 | } |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8329 | |
Trond Myklebust | e85d7ee | 2016-07-14 18:46:24 -0400 | [diff] [blame] | 8330 | err = nfs4_handle_exception(server, nfs4err, exception); |
| 8331 | if (!status) { |
| 8332 | if (exception->retry) |
| 8333 | status = -EAGAIN; |
| 8334 | else |
| 8335 | status = err; |
| 8336 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 8337 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8338 | dprintk("<-- %s\n", __func__); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8339 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8340 | } |
| 8341 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8342 | static size_t max_response_pages(struct nfs_server *server) |
| 8343 | { |
| 8344 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 8345 | return nfs_page_array_len(0, max_resp_sz); |
| 8346 | } |
| 8347 | |
| 8348 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 8349 | { |
| 8350 | int i; |
| 8351 | |
| 8352 | if (!pages) |
| 8353 | return; |
| 8354 | |
| 8355 | for (i = 0; i < size; i++) { |
| 8356 | if (!pages[i]) |
| 8357 | break; |
| 8358 | __free_page(pages[i]); |
| 8359 | } |
| 8360 | kfree(pages); |
| 8361 | } |
| 8362 | |
| 8363 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 8364 | { |
| 8365 | struct page **pages; |
| 8366 | int i; |
| 8367 | |
| 8368 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 8369 | if (!pages) { |
| 8370 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 8371 | return NULL; |
| 8372 | } |
| 8373 | |
| 8374 | for (i = 0; i < size; i++) { |
| 8375 | pages[i] = alloc_page(gfp_flags); |
| 8376 | if (!pages[i]) { |
| 8377 | dprintk("%s: failed to allocate page\n", __func__); |
| 8378 | nfs4_free_pages(pages, size); |
| 8379 | return NULL; |
| 8380 | } |
| 8381 | } |
| 8382 | |
| 8383 | return pages; |
| 8384 | } |
| 8385 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8386 | static void nfs4_layoutget_release(void *calldata) |
| 8387 | { |
| 8388 | struct nfs4_layoutget *lgp = calldata; |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8389 | struct inode *inode = lgp->args.inode; |
| 8390 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8391 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8392 | |
| 8393 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8394 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8395 | pnfs_put_layout_hdr(NFS_I(inode)->layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8396 | put_nfs_open_context(lgp->args.ctx); |
| 8397 | kfree(calldata); |
| 8398 | dprintk("<-- %s\n", __func__); |
| 8399 | } |
| 8400 | |
| 8401 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 8402 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 8403 | .rpc_call_done = nfs4_layoutget_done, |
| 8404 | .rpc_release = nfs4_layoutget_release, |
| 8405 | }; |
| 8406 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8407 | struct pnfs_layout_segment * |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8408 | 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] | 8409 | { |
Weston Andros Adamson | a47970f | 2013-02-25 21:27:33 -0500 | [diff] [blame] | 8410 | struct inode *inode = lgp->args.inode; |
| 8411 | struct nfs_server *server = NFS_SERVER(inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8412 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8413 | struct rpc_task *task; |
| 8414 | struct rpc_message msg = { |
| 8415 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 8416 | .rpc_argp = &lgp->args, |
| 8417 | .rpc_resp = &lgp->res, |
Trond Myklebust | 6ab5934 | 2013-05-20 10:49:34 -0400 | [diff] [blame] | 8418 | .rpc_cred = lgp->cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8419 | }; |
| 8420 | struct rpc_task_setup task_setup_data = { |
| 8421 | .rpc_client = server->client, |
| 8422 | .rpc_message = &msg, |
| 8423 | .callback_ops = &nfs4_layoutget_call_ops, |
| 8424 | .callback_data = lgp, |
| 8425 | .flags = RPC_TASK_ASYNC, |
| 8426 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8427 | struct pnfs_layout_segment *lseg = NULL; |
Trond Myklebust | bc23676 | 2016-06-17 16:48:18 -0400 | [diff] [blame] | 8428 | struct nfs4_exception exception = { |
| 8429 | .inode = inode, |
| 8430 | .timeout = *timeout, |
| 8431 | }; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8432 | int status = 0; |
| 8433 | |
| 8434 | dprintk("--> %s\n", __func__); |
| 8435 | |
Peng Tao | 4bd5a98 | 2014-11-17 11:05:17 +0800 | [diff] [blame] | 8436 | /* nfs4_layoutget_release calls pnfs_put_layout_hdr */ |
| 8437 | pnfs_get_layout_hdr(NFS_I(inode)->layout); |
| 8438 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8439 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 8440 | if (!lgp->args.layout.pages) { |
| 8441 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8442 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 8443 | } |
| 8444 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 8445 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 8446 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8447 | lgp->res.seq_res.sr_slot = NULL; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8448 | 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] | 8449 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8450 | task = rpc_run_task(&task_setup_data); |
| 8451 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8452 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8453 | status = nfs4_wait_for_completion_rpc_task(task); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8454 | if (status == 0) { |
| 8455 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
| 8456 | *timeout = exception.timeout; |
| 8457 | } |
| 8458 | |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8459 | trace_nfs4_layoutget(lgp->args.ctx, |
| 8460 | &lgp->args.range, |
| 8461 | &lgp->res.range, |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8462 | &lgp->res.stateid, |
Trond Myklebust | 1037e6e | 2013-08-14 16:36:51 -0400 | [diff] [blame] | 8463 | status); |
Jeff Layton | 183d9e7 | 2016-05-17 12:28:47 -0400 | [diff] [blame] | 8464 | |
Weston Andros Adamson | 085b7a4 | 2013-02-15 16:03:46 -0500 | [diff] [blame] | 8465 | /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
| 8466 | if (status == 0 && lgp->res.layoutp->len) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8467 | lseg = pnfs_layout_process(lgp); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8468 | nfs4_sequence_free_slot(&lgp->res.seq_res); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8469 | rpc_put_task(task); |
| 8470 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 8471 | if (status) |
| 8472 | return ERR_PTR(status); |
| 8473 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8474 | } |
| 8475 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8476 | static void |
| 8477 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 8478 | { |
| 8479 | struct nfs4_layoutreturn *lrp = calldata; |
| 8480 | |
| 8481 | dprintk("--> %s\n", __func__); |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8482 | nfs41_setup_sequence(lrp->clp->cl_session, |
| 8483 | &lrp->args.seq_args, |
| 8484 | &lrp->res.seq_res, |
| 8485 | task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8486 | } |
| 8487 | |
| 8488 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 8489 | { |
| 8490 | struct nfs4_layoutreturn *lrp = calldata; |
| 8491 | struct nfs_server *server; |
| 8492 | |
| 8493 | dprintk("--> %s\n", __func__); |
| 8494 | |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8495 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8496 | return; |
| 8497 | |
| 8498 | server = NFS_SERVER(lrp->args.inode); |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8499 | switch (task->tk_status) { |
| 8500 | default: |
| 8501 | task->tk_status = 0; |
| 8502 | case 0: |
| 8503 | break; |
| 8504 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8505 | if (nfs4_async_handle_error(task, server, NULL, NULL) != -EAGAIN) |
Trond Myklebust | f22e5ed | 2013-12-04 12:09:45 -0500 | [diff] [blame] | 8506 | break; |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8507 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 8508 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8509 | return; |
| 8510 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8511 | dprintk("<-- %s\n", __func__); |
| 8512 | } |
| 8513 | |
| 8514 | static void nfs4_layoutreturn_release(void *calldata) |
| 8515 | { |
| 8516 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8517 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8518 | LIST_HEAD(freeme); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8519 | |
| 8520 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8521 | spin_lock(&lo->plh_inode->i_lock); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8522 | if (lrp->res.lrs_present) { |
| 8523 | pnfs_mark_matching_lsegs_invalid(lo, &freeme, |
| 8524 | &lrp->args.range, |
| 8525 | be32_to_cpu(lrp->args.stateid.seqid)); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8526 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Trond Myklebust | 52ec7be | 2016-09-03 11:05:28 -0400 | [diff] [blame] | 8527 | } else |
| 8528 | pnfs_mark_layout_stateid_invalid(lo, &freeme); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 8529 | pnfs_clear_layoutreturn_waitbit(lo); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 8530 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 2e80dbe | 2016-08-28 11:50:26 -0400 | [diff] [blame] | 8531 | nfs4_sequence_free_slot(&lrp->res.seq_res); |
Trond Myklebust | c5d7371 | 2015-07-09 17:58:39 +0200 | [diff] [blame] | 8532 | pnfs_free_lseg_list(&freeme); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 8533 | pnfs_put_layout_hdr(lrp->args.layout); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8534 | nfs_iput_and_deactive(lrp->inode); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8535 | kfree(calldata); |
| 8536 | dprintk("<-- %s\n", __func__); |
| 8537 | } |
| 8538 | |
| 8539 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 8540 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 8541 | .rpc_call_done = nfs4_layoutreturn_done, |
| 8542 | .rpc_release = nfs4_layoutreturn_release, |
| 8543 | }; |
| 8544 | |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8545 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8546 | { |
| 8547 | struct rpc_task *task; |
| 8548 | struct rpc_message msg = { |
| 8549 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 8550 | .rpc_argp = &lrp->args, |
| 8551 | .rpc_resp = &lrp->res, |
Trond Myklebust | 9556000 | 2013-05-20 10:43:47 -0400 | [diff] [blame] | 8552 | .rpc_cred = lrp->cred, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8553 | }; |
| 8554 | struct rpc_task_setup task_setup_data = { |
Andy Adamson | 1771c57 | 2013-07-22 12:42:05 -0400 | [diff] [blame] | 8555 | .rpc_client = NFS_SERVER(lrp->args.inode)->client, |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8556 | .rpc_message = &msg, |
| 8557 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 8558 | .callback_data = lrp, |
| 8559 | }; |
Peng Tao | 6c16605 | 2014-11-17 09:30:40 +0800 | [diff] [blame] | 8560 | int status = 0; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8561 | |
Andrew Elble | 99ade3c | 2015-12-02 09:39:51 -0500 | [diff] [blame] | 8562 | nfs4_state_protect(NFS_SERVER(lrp->args.inode)->nfs_client, |
| 8563 | NFS_SP4_MACH_CRED_PNFS_CLEANUP, |
| 8564 | &task_setup_data.rpc_client, &msg); |
| 8565 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8566 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8567 | if (!sync) { |
| 8568 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); |
| 8569 | if (!lrp->inode) { |
| 8570 | nfs4_layoutreturn_release(lrp); |
| 8571 | return -EAGAIN; |
| 8572 | } |
| 8573 | task_setup_data.flags |= RPC_TASK_ASYNC; |
| 8574 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8575 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8576 | task = rpc_run_task(&task_setup_data); |
| 8577 | if (IS_ERR(task)) |
| 8578 | return PTR_ERR(task); |
Trond Myklebust | 5a0ec8ac | 2015-02-05 16:35:16 -0500 | [diff] [blame] | 8579 | if (sync) |
| 8580 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8581 | trace_nfs4_layoutreturn(lrp->args.inode, &lrp->args.stateid, status); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 8582 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8583 | rpc_put_task(task); |
| 8584 | return status; |
| 8585 | } |
| 8586 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8587 | static int |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8588 | _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_getdeviceinfo_args args = { |
| 8593 | .pdev = pdev, |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8594 | .notify_types = NOTIFY_DEVICEID4_CHANGE | |
| 8595 | NOTIFY_DEVICEID4_DELETE, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8596 | }; |
| 8597 | struct nfs4_getdeviceinfo_res res = { |
| 8598 | .pdev = pdev, |
| 8599 | }; |
| 8600 | struct rpc_message msg = { |
| 8601 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 8602 | .rpc_argp = &args, |
| 8603 | .rpc_resp = &res, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8604 | .rpc_cred = cred, |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8605 | }; |
| 8606 | int status; |
| 8607 | |
| 8608 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 8609 | 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] | 8610 | if (res.notification & ~args.notify_types) |
| 8611 | dprintk("%s: unsupported notification\n", __func__); |
Trond Myklebust | df52699 | 2015-03-09 14:48:32 -0400 | [diff] [blame] | 8612 | if (res.notification != args.notify_types) |
| 8613 | pdev->nocache = 1; |
Trond Myklebust | 4e59080 | 2015-03-09 14:01:25 -0400 | [diff] [blame] | 8614 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8615 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8616 | |
| 8617 | return status; |
| 8618 | } |
| 8619 | |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8620 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
| 8621 | struct pnfs_device *pdev, |
| 8622 | struct rpc_cred *cred) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8623 | { |
| 8624 | struct nfs4_exception exception = { }; |
| 8625 | int err; |
| 8626 | |
| 8627 | do { |
| 8628 | err = nfs4_handle_exception(server, |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 8629 | _nfs4_proc_getdeviceinfo(server, pdev, cred), |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 8630 | &exception); |
| 8631 | } while (exception.retry); |
| 8632 | return err; |
| 8633 | } |
| 8634 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 8635 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8636 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 8637 | { |
| 8638 | struct nfs4_layoutcommit_data *data = calldata; |
| 8639 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8640 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8641 | |
Trond Myklebust | d9afbd1 | 2012-10-22 20:28:44 -0400 | [diff] [blame] | 8642 | nfs41_setup_sequence(session, |
| 8643 | &data->args.seq_args, |
| 8644 | &data->res.seq_res, |
| 8645 | task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8646 | } |
| 8647 | |
| 8648 | static void |
| 8649 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 8650 | { |
| 8651 | struct nfs4_layoutcommit_data *data = calldata; |
| 8652 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 8653 | |
Trond Myklebust | 6ba7db3 | 2012-10-22 20:07:20 -0400 | [diff] [blame] | 8654 | if (!nfs41_sequence_done(task, &data->res.seq_res)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8655 | return; |
| 8656 | |
| 8657 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8658 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 8659 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 8660 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 8661 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8662 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8663 | case 0: |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8664 | break; |
| 8665 | default: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8666 | if (nfs4_async_handle_error(task, server, NULL, NULL) == -EAGAIN) { |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 8667 | rpc_restart_call_prepare(task); |
| 8668 | return; |
| 8669 | } |
| 8670 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8671 | } |
| 8672 | |
| 8673 | static void nfs4_layoutcommit_release(void *calldata) |
| 8674 | { |
| 8675 | struct nfs4_layoutcommit_data *data = calldata; |
| 8676 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 8677 | pnfs_cleanup_layoutcommit(data); |
Trond Myklebust | d8c951c | 2014-01-13 12:08:11 -0500 | [diff] [blame] | 8678 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 8679 | data->res.fattr); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8680 | put_rpccred(data->cred); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8681 | nfs_iput_and_deactive(data->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8682 | kfree(data); |
| 8683 | } |
| 8684 | |
| 8685 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 8686 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 8687 | .rpc_call_done = nfs4_layoutcommit_done, |
| 8688 | .rpc_release = nfs4_layoutcommit_release, |
| 8689 | }; |
| 8690 | |
| 8691 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 8692 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8693 | { |
| 8694 | struct rpc_message msg = { |
| 8695 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 8696 | .rpc_argp = &data->args, |
| 8697 | .rpc_resp = &data->res, |
| 8698 | .rpc_cred = data->cred, |
| 8699 | }; |
| 8700 | struct rpc_task_setup task_setup_data = { |
| 8701 | .task = &data->task, |
| 8702 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 8703 | .rpc_message = &msg, |
| 8704 | .callback_ops = &nfs4_layoutcommit_ops, |
| 8705 | .callback_data = data, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8706 | }; |
| 8707 | struct rpc_task *task; |
| 8708 | int status = 0; |
| 8709 | |
Kinglong Mee | b4839eb | 2015-07-01 12:00:13 +0800 | [diff] [blame] | 8710 | dprintk("NFS: initiating layoutcommit call. sync %d " |
| 8711 | "lbw: %llu inode %lu\n", sync, |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8712 | data->args.lastbytewritten, |
| 8713 | data->args.inode->i_ino); |
| 8714 | |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8715 | if (!sync) { |
| 8716 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 8717 | if (data->inode == NULL) { |
| 8718 | nfs4_layoutcommit_release(data); |
| 8719 | return -EAGAIN; |
| 8720 | } |
| 8721 | task_setup_data.flags = RPC_TASK_ASYNC; |
| 8722 | } |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8723 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8724 | task = rpc_run_task(&task_setup_data); |
| 8725 | if (IS_ERR(task)) |
| 8726 | return PTR_ERR(task); |
Trond Myklebust | 472e259 | 2015-02-05 16:50:30 -0500 | [diff] [blame] | 8727 | if (sync) |
| 8728 | status = task->tk_status; |
Olga Kornievskaia | 48c9579 | 2015-11-24 13:29:41 -0500 | [diff] [blame] | 8729 | trace_nfs4_layoutcommit(data->args.inode, &data->args.stateid, status); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 8730 | dprintk("%s: status %d\n", __func__, status); |
| 8731 | rpc_put_task(task); |
| 8732 | return status; |
| 8733 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8734 | |
Andy Adamson | 9743120 | 2013-08-08 10:57:56 -0400 | [diff] [blame] | 8735 | /** |
| 8736 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
| 8737 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
| 8738 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8739 | static int |
| 8740 | _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] | 8741 | struct nfs_fsinfo *info, |
| 8742 | struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8743 | { |
| 8744 | struct nfs41_secinfo_no_name_args args = { |
| 8745 | .style = SECINFO_STYLE_CURRENT_FH, |
| 8746 | }; |
| 8747 | struct nfs4_secinfo_res res = { |
| 8748 | .flavors = flavors, |
| 8749 | }; |
| 8750 | struct rpc_message msg = { |
| 8751 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 8752 | .rpc_argp = &args, |
| 8753 | .rpc_resp = &res, |
| 8754 | }; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8755 | struct rpc_clnt *clnt = server->client; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8756 | struct rpc_cred *cred = NULL; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8757 | int status; |
| 8758 | |
| 8759 | if (use_integrity) { |
| 8760 | clnt = server->nfs_client->cl_rpcclient; |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8761 | cred = nfs4_get_clid_cred(server->nfs_client); |
| 8762 | msg.rpc_cred = cred; |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | dprintk("--> %s\n", __func__); |
| 8766 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
| 8767 | &res.seq_res, 0); |
| 8768 | dprintk("<-- %s status=%d\n", __func__, status); |
| 8769 | |
Weston Andros Adamson | 7cb852d | 2013-09-10 18:44:31 -0400 | [diff] [blame] | 8770 | if (cred) |
| 8771 | put_rpccred(cred); |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8772 | |
| 8773 | return status; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | static int |
| 8777 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8778 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 8779 | { |
| 8780 | struct nfs4_exception exception = { }; |
| 8781 | int err; |
| 8782 | do { |
Weston Andros Adamson | b1b3e13 | 2013-09-04 12:13:19 -0400 | [diff] [blame] | 8783 | /* first try using integrity protection */ |
| 8784 | err = -NFS4ERR_WRONGSEC; |
| 8785 | |
| 8786 | /* try to use integrity protection with machine cred */ |
| 8787 | if (_nfs4_is_integrity_protected(server->nfs_client)) |
| 8788 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8789 | flavors, true); |
| 8790 | |
| 8791 | /* |
| 8792 | * if unable to use integrity protection, or SECINFO with |
| 8793 | * integrity protection returns NFS4ERR_WRONGSEC (which is |
| 8794 | * disallowed by spec, but exists in deployed servers) use |
| 8795 | * the current filesystem's rpc_client and the user cred. |
| 8796 | */ |
| 8797 | if (err == -NFS4ERR_WRONGSEC) |
| 8798 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, |
| 8799 | flavors, false); |
| 8800 | |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8801 | switch (err) { |
| 8802 | case 0: |
| 8803 | case -NFS4ERR_WRONGSEC: |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8804 | case -ENOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8805 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8806 | default: |
| 8807 | err = nfs4_handle_exception(server, err, &exception); |
| 8808 | } |
| 8809 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 8810 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8811 | return err; |
| 8812 | } |
| 8813 | |
| 8814 | static int |
| 8815 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 8816 | struct nfs_fsinfo *info) |
| 8817 | { |
| 8818 | int err; |
| 8819 | struct page *page; |
Anna Schumaker | 367156d | 2013-09-25 17:02:48 -0400 | [diff] [blame] | 8820 | rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8821 | struct nfs4_secinfo_flavors *flavors; |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8822 | struct nfs4_secinfo4 *secinfo; |
| 8823 | int i; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8824 | |
| 8825 | page = alloc_page(GFP_KERNEL); |
| 8826 | if (!page) { |
| 8827 | err = -ENOMEM; |
| 8828 | goto out; |
| 8829 | } |
| 8830 | |
| 8831 | flavors = page_address(page); |
| 8832 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 8833 | |
| 8834 | /* |
| 8835 | * Fall back on "guess and check" method if |
| 8836 | * the server doesn't support SECINFO_NO_NAME |
| 8837 | */ |
Weston Andros Adamson | 78b19ba | 2014-01-13 16:54:45 -0500 | [diff] [blame] | 8838 | if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8839 | err = nfs4_find_root_sec(server, fhandle, info); |
| 8840 | goto out_freepage; |
| 8841 | } |
| 8842 | if (err) |
| 8843 | goto out_freepage; |
| 8844 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8845 | for (i = 0; i < flavors->num_flavors; i++) { |
| 8846 | secinfo = &flavors->flavors[i]; |
| 8847 | |
| 8848 | switch (secinfo->flavor) { |
| 8849 | case RPC_AUTH_NULL: |
| 8850 | case RPC_AUTH_UNIX: |
| 8851 | case RPC_AUTH_GSS: |
| 8852 | flavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
| 8853 | &secinfo->flavor_info); |
| 8854 | break; |
| 8855 | default: |
| 8856 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8857 | break; |
| 8858 | } |
| 8859 | |
Weston Andros Adamson | 4d4b69d | 2013-10-18 15:15:19 -0400 | [diff] [blame] | 8860 | if (!nfs_auth_info_match(&server->auth_info, flavor)) |
| 8861 | flavor = RPC_AUTH_MAXFLAVOR; |
| 8862 | |
Weston Andros Adamson | 58a8cf1 | 2013-09-24 13:58:02 -0400 | [diff] [blame] | 8863 | if (flavor != RPC_AUTH_MAXFLAVOR) { |
| 8864 | err = nfs4_lookup_root_sec(server, fhandle, |
| 8865 | info, flavor); |
| 8866 | if (!err) |
| 8867 | break; |
| 8868 | } |
| 8869 | } |
| 8870 | |
| 8871 | if (flavor == RPC_AUTH_MAXFLAVOR) |
| 8872 | err = -EPERM; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 8873 | |
| 8874 | out_freepage: |
| 8875 | put_page(page); |
| 8876 | if (err == -EACCES) |
| 8877 | return -EPERM; |
| 8878 | out: |
| 8879 | return err; |
| 8880 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8881 | |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8882 | static int _nfs41_test_stateid(struct nfs_server *server, |
| 8883 | nfs4_stateid *stateid, |
| 8884 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8885 | { |
| 8886 | int status; |
| 8887 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8888 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8889 | }; |
| 8890 | struct nfs41_test_stateid_res res; |
| 8891 | struct rpc_message msg = { |
| 8892 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 8893 | .rpc_argp = &args, |
| 8894 | .rpc_resp = &res, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8895 | .rpc_cred = cred, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8896 | }; |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8897 | struct rpc_clnt *rpc_client = server->client; |
| 8898 | |
| 8899 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 8900 | &rpc_client, &msg); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 8901 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8902 | dprintk("NFS call test_stateid %p\n", stateid); |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 8903 | nfs4_init_sequence(&args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8904 | nfs4_set_sequence_privileged(&args.seq_args); |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 8905 | status = nfs4_call_sync_sequence(rpc_client, server, &msg, |
Trond Myklebust | 8fe72ba | 2012-10-29 19:02:20 -0400 | [diff] [blame] | 8906 | &args.seq_args, &res.seq_res); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8907 | if (status != NFS_OK) { |
| 8908 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8909 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8910 | } |
| 8911 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 8912 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8913 | } |
| 8914 | |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8915 | static void nfs4_handle_delay_or_session_error(struct nfs_server *server, |
| 8916 | int err, struct nfs4_exception *exception) |
| 8917 | { |
| 8918 | exception->retry = 0; |
| 8919 | switch(err) { |
| 8920 | case -NFS4ERR_DELAY: |
| 8921 | nfs4_handle_exception(server, err, exception); |
| 8922 | break; |
| 8923 | case -NFS4ERR_BADSESSION: |
| 8924 | case -NFS4ERR_BADSLOT: |
| 8925 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 8926 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 8927 | case -NFS4ERR_DEADSESSION: |
| 8928 | nfs4_do_handle_exception(server, err, exception); |
| 8929 | } |
| 8930 | } |
| 8931 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8932 | /** |
| 8933 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 8934 | * |
| 8935 | * @server: server / transport on which to perform the operation |
| 8936 | * @stateid: state ID to test |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8937 | * @cred: credential |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 8938 | * |
| 8939 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 8940 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 8941 | * failed or the state ID is not currently valid. |
| 8942 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8943 | static int nfs41_test_stateid(struct nfs_server *server, |
| 8944 | nfs4_stateid *stateid, |
| 8945 | struct rpc_cred *cred) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8946 | { |
| 8947 | struct nfs4_exception exception = { }; |
| 8948 | int err; |
| 8949 | do { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8950 | err = _nfs41_test_stateid(server, stateid, cred); |
Trond Myklebust | 43912bb | 2016-09-22 13:38:56 -0400 | [diff] [blame] | 8951 | nfs4_handle_delay_or_session_error(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 8952 | } while (exception.retry); |
| 8953 | return err; |
| 8954 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8955 | |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8956 | struct nfs_free_stateid_data { |
| 8957 | struct nfs_server *server; |
| 8958 | struct nfs41_free_stateid_args args; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 8959 | struct nfs41_free_stateid_res res; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8960 | }; |
| 8961 | |
| 8962 | static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata) |
| 8963 | { |
| 8964 | struct nfs_free_stateid_data *data = calldata; |
| 8965 | nfs41_setup_sequence(nfs4_get_session(data->server), |
| 8966 | &data->args.seq_args, |
| 8967 | &data->res.seq_res, |
| 8968 | task); |
| 8969 | } |
| 8970 | |
| 8971 | static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata) |
| 8972 | { |
| 8973 | struct nfs_free_stateid_data *data = calldata; |
| 8974 | |
| 8975 | nfs41_sequence_done(task, &data->res.seq_res); |
| 8976 | |
| 8977 | switch (task->tk_status) { |
| 8978 | case -NFS4ERR_DELAY: |
NeilBrown | 8478eaa | 2014-09-18 16:09:27 +1000 | [diff] [blame] | 8979 | if (nfs4_async_handle_error(task, data->server, NULL, NULL) == -EAGAIN) |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8980 | rpc_restart_call_prepare(task); |
| 8981 | } |
| 8982 | } |
| 8983 | |
| 8984 | static void nfs41_free_stateid_release(void *calldata) |
| 8985 | { |
| 8986 | kfree(calldata); |
| 8987 | } |
| 8988 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 8989 | static const struct rpc_call_ops nfs41_free_stateid_ops = { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8990 | .rpc_call_prepare = nfs41_free_stateid_prepare, |
| 8991 | .rpc_call_done = nfs41_free_stateid_done, |
| 8992 | .rpc_release = nfs41_free_stateid_release, |
| 8993 | }; |
| 8994 | |
| 8995 | static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 8996 | const nfs4_stateid *stateid, |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 8997 | struct rpc_cred *cred, |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 8998 | bool privileged) |
| 8999 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9000 | struct rpc_message msg = { |
| 9001 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9002 | .rpc_cred = cred, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9003 | }; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9004 | struct rpc_task_setup task_setup = { |
| 9005 | .rpc_client = server->client, |
| 9006 | .rpc_message = &msg, |
| 9007 | .callback_ops = &nfs41_free_stateid_ops, |
| 9008 | .flags = RPC_TASK_ASYNC, |
| 9009 | }; |
| 9010 | struct nfs_free_stateid_data *data; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9011 | |
Weston Andros Adamson | 3787d50 | 2013-08-13 16:37:36 -0400 | [diff] [blame] | 9012 | nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, |
| 9013 | &task_setup.rpc_client, &msg); |
| 9014 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9015 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9016 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 9017 | if (!data) |
| 9018 | return ERR_PTR(-ENOMEM); |
| 9019 | data->server = server; |
| 9020 | nfs4_stateid_copy(&data->args.stateid, stateid); |
| 9021 | |
| 9022 | task_setup.callback_data = data; |
| 9023 | |
| 9024 | msg.rpc_argp = &data->args; |
| 9025 | msg.rpc_resp = &data->res; |
Chuck Lever | a9c92d6 | 2013-08-09 12:48:18 -0400 | [diff] [blame] | 9026 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9027 | if (privileged) |
| 9028 | nfs4_set_sequence_privileged(&data->args.seq_args); |
| 9029 | |
| 9030 | return rpc_run_task(&task_setup); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9031 | } |
| 9032 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9033 | /** |
| 9034 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 9035 | * |
| 9036 | * @server: server / transport on which to perform the operation |
| 9037 | * @stateid: state ID to release |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9038 | * @cred: credential |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9039 | * @is_recovery: set to true if this call needs to be privileged |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9040 | * |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9041 | * Note: this function is always asynchronous. |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 9042 | */ |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9043 | static int nfs41_free_stateid(struct nfs_server *server, |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9044 | const nfs4_stateid *stateid, |
| 9045 | struct rpc_cred *cred, |
| 9046 | bool is_recovery) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9047 | { |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9048 | struct rpc_task *task; |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9049 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9050 | task = _nfs41_free_stateid(server, stateid, cred, is_recovery); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9051 | if (IS_ERR(task)) |
| 9052 | return PTR_ERR(task); |
Trond Myklebust | 7c1d5fa | 2013-05-03 14:40:01 -0400 | [diff] [blame] | 9053 | rpc_put_task(task); |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9054 | return 0; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 9055 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9056 | |
Jeff Layton | f1cdae8 | 2014-05-01 06:28:47 -0400 | [diff] [blame] | 9057 | static void |
| 9058 | 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] | 9059 | { |
Trond Myklebust | ab7cb0d | 2013-05-20 11:20:27 -0400 | [diff] [blame] | 9060 | struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9061 | |
Trond Myklebust | f0b0bf8 | 2016-09-22 13:39:04 -0400 | [diff] [blame] | 9062 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9063 | nfs4_free_lock_state(server, lsp); |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9064 | } |
| 9065 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9066 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 9067 | const nfs4_stateid *s2) |
| 9068 | { |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 9069 | if (s1->type != s2->type) |
| 9070 | return false; |
| 9071 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9072 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9073 | return false; |
| 9074 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9075 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9076 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 9077 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9078 | return true; |
| 9079 | |
| 9080 | return false; |
| 9081 | } |
| 9082 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 9083 | #endif /* CONFIG_NFS_V4_1 */ |
| 9084 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9085 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 9086 | const nfs4_stateid *s2) |
| 9087 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9088 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9089 | } |
| 9090 | |
| 9091 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9092 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9093 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9094 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9095 | .recover_open = nfs4_open_reclaim, |
| 9096 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9097 | .establish_clid = nfs4_init_clientid, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9098 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9099 | }; |
| 9100 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9101 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9102 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9103 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 9104 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 9105 | .recover_open = nfs4_open_reclaim, |
| 9106 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9107 | .establish_clid = nfs41_init_clientid, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 9108 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 9109 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9110 | }; |
| 9111 | #endif /* CONFIG_NFS_V4_1 */ |
| 9112 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9113 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 9114 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 9115 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Trond Myklebust | 4dfd4f7 | 2014-10-17 15:10:25 +0300 | [diff] [blame] | 9116 | .recover_open = nfs40_open_expired, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9117 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9118 | .establish_clid = nfs4_init_clientid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9119 | }; |
| 9120 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9121 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9122 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9123 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 9124 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 9125 | .recover_open = nfs41_open_expired, |
| 9126 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 9127 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 9128 | }; |
| 9129 | #endif /* CONFIG_NFS_V4_1 */ |
| 9130 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9131 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9132 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9133 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9134 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9135 | }; |
| 9136 | |
| 9137 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 9138 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9139 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 9140 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 9141 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 9142 | }; |
| 9143 | #endif |
| 9144 | |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9145 | static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9146 | .get_locations = _nfs40_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9147 | .fsid_present = _nfs40_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9148 | }; |
| 9149 | |
| 9150 | #if defined(CONFIG_NFS_V4_1) |
| 9151 | static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = { |
Chuck Lever | b03d735 | 2013-10-17 14:12:50 -0400 | [diff] [blame] | 9152 | .get_locations = _nfs41_proc_get_locations, |
Chuck Lever | 44c9993 | 2013-10-17 14:13:30 -0400 | [diff] [blame] | 9153 | .fsid_present = _nfs41_proc_fsid_present, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9154 | }; |
| 9155 | #endif /* CONFIG_NFS_V4_1 */ |
| 9156 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9157 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 9158 | .minor_version = 0, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9159 | .init_caps = NFS_CAP_READDIRPLUS |
| 9160 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9161 | | NFS_CAP_POSIX_LOCK, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9162 | .init_client = nfs40_init_client, |
| 9163 | .shutdown_client = nfs40_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9164 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9165 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9166 | .free_lock_state = nfs4_release_lockowner, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9167 | .test_and_free_expired = nfs40_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9168 | .alloc_seqid = nfs_alloc_seqid, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9169 | .call_sync_ops = &nfs40_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9170 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 9171 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 9172 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9173 | .mig_recovery_ops = &nfs40_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9174 | }; |
| 9175 | |
| 9176 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9177 | static struct nfs_seqid * |
| 9178 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) |
| 9179 | { |
| 9180 | return NULL; |
| 9181 | } |
| 9182 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9183 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 9184 | .minor_version = 1, |
Trond Myklebust | 39c6daa | 2013-03-15 16:11:57 -0400 | [diff] [blame] | 9185 | .init_caps = NFS_CAP_READDIRPLUS |
| 9186 | | NFS_CAP_ATOMIC_OPEN |
Trond Myklebust | 3b66486 | 2013-03-17 15:31:15 -0400 | [diff] [blame] | 9187 | | NFS_CAP_POSIX_LOCK |
Trond Myklebust | 49f9a0f | 2013-03-15 16:44:28 -0400 | [diff] [blame] | 9188 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9189 | | NFS_CAP_ATOMIC_OPEN_V1, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9190 | .init_client = nfs41_init_client, |
| 9191 | .shutdown_client = nfs41_shutdown_client, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 9192 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 9193 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c8b2d0b | 2013-05-03 16:22:55 -0400 | [diff] [blame] | 9194 | .free_lock_state = nfs41_free_lock_state, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9195 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9196 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9197 | .session_trunk = nfs4_test_session_trunk, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9198 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 9199 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9200 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9201 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Chuck Lever | ec011fe | 2013-10-17 14:12:39 -0400 | [diff] [blame] | 9202 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9203 | }; |
| 9204 | #endif |
| 9205 | |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9206 | #if defined(CONFIG_NFS_V4_2) |
| 9207 | static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { |
| 9208 | .minor_version = 2, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9209 | .init_caps = NFS_CAP_READDIRPLUS |
| 9210 | | NFS_CAP_ATOMIC_OPEN |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9211 | | NFS_CAP_POSIX_LOCK |
| 9212 | | NFS_CAP_STATEID_NFSV41 |
Anna Schumaker | e983120 | 2014-10-22 15:53:10 -0400 | [diff] [blame] | 9213 | | NFS_CAP_ATOMIC_OPEN_V1 |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 9214 | | NFS_CAP_ALLOCATE |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 9215 | | NFS_CAP_COPY |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 9216 | | NFS_CAP_DEALLOCATE |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 9217 | | NFS_CAP_SEEK |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 9218 | | NFS_CAP_LAYOUTSTATS |
| 9219 | | NFS_CAP_CLONE, |
Chuck Lever | abf79bb | 2013-08-09 12:49:11 -0400 | [diff] [blame] | 9220 | .init_client = nfs41_init_client, |
| 9221 | .shutdown_client = nfs41_shutdown_client, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9222 | .match_stateid = nfs41_match_stateid, |
| 9223 | .find_root_sec = nfs41_find_root_sec, |
Bryan Schumaker | 7017310 | 2013-06-19 13:41:43 -0400 | [diff] [blame] | 9224 | .free_lock_state = nfs41_free_lock_state, |
Chuck Lever | 9915ea7 | 2013-08-09 12:48:27 -0400 | [diff] [blame] | 9225 | .call_sync_ops = &nfs41_call_sync_ops, |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 9226 | .test_and_free_expired = nfs41_test_and_free_expired_stateid, |
Trond Myklebust | 63f5f79 | 2015-01-23 19:19:25 -0500 | [diff] [blame] | 9227 | .alloc_seqid = nfs_alloc_no_seqid, |
Andy Adamson | 04fa2c6 | 2016-09-09 09:22:29 -0400 | [diff] [blame] | 9228 | .session_trunk = nfs4_test_session_trunk, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9229 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 9230 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 9231 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Kinglong Mee | 18e3b73 | 2015-08-15 21:52:10 +0800 | [diff] [blame] | 9232 | .mig_recovery_ops = &nfs41_mig_recovery_ops, |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9233 | }; |
| 9234 | #endif |
| 9235 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9236 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 9237 | [0] = &nfs_v4_0_minor_ops, |
| 9238 | #if defined(CONFIG_NFS_V4_1) |
| 9239 | [1] = &nfs_v4_1_minor_ops, |
| 9240 | #endif |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 9241 | #if defined(CONFIG_NFS_V4_2) |
| 9242 | [2] = &nfs_v4_2_minor_ops, |
| 9243 | #endif |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 9244 | }; |
| 9245 | |
Trond Myklebust | 1399782 | 2016-07-24 17:10:52 -0400 | [diff] [blame] | 9246 | 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] | 9247 | { |
| 9248 | ssize_t error, error2; |
| 9249 | |
| 9250 | error = generic_listxattr(dentry, list, size); |
| 9251 | if (error < 0) |
| 9252 | return error; |
| 9253 | if (list) { |
| 9254 | list += error; |
| 9255 | size -= error; |
| 9256 | } |
| 9257 | |
| 9258 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
| 9259 | if (error2 < 0) |
| 9260 | return error2; |
| 9261 | return error + error2; |
| 9262 | } |
| 9263 | |
Trond Myklebust | 17f26b1 | 2013-08-21 15:48:42 -0400 | [diff] [blame] | 9264 | static const struct inode_operations nfs4_dir_inode_operations = { |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9265 | .create = nfs_create, |
| 9266 | .lookup = nfs_lookup, |
| 9267 | .atomic_open = nfs_atomic_open, |
| 9268 | .link = nfs_link, |
| 9269 | .unlink = nfs_unlink, |
| 9270 | .symlink = nfs_symlink, |
| 9271 | .mkdir = nfs_mkdir, |
| 9272 | .rmdir = nfs_rmdir, |
| 9273 | .mknod = nfs_mknod, |
| 9274 | .rename = nfs_rename, |
| 9275 | .permission = nfs_permission, |
| 9276 | .getattr = nfs_getattr, |
| 9277 | .setattr = nfs_setattr, |
| 9278 | .getxattr = generic_getxattr, |
| 9279 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9280 | .listxattr = nfs4_listxattr, |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 9281 | .removexattr = generic_removexattr, |
| 9282 | }; |
| 9283 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 9284 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9285 | .permission = nfs_permission, |
| 9286 | .getattr = nfs_getattr, |
| 9287 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9288 | .getxattr = generic_getxattr, |
| 9289 | .setxattr = generic_setxattr, |
Andreas Gruenbacher | c4803c4 | 2015-12-02 14:44:41 +0100 | [diff] [blame] | 9290 | .listxattr = nfs4_listxattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9291 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9292 | }; |
| 9293 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 9294 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9295 | .version = 4, /* protocol version */ |
| 9296 | .dentry_ops = &nfs4_dentry_operations, |
| 9297 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 9298 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 9299 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9300 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 9301 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 9302 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9303 | .getattr = nfs4_proc_getattr, |
| 9304 | .setattr = nfs4_proc_setattr, |
| 9305 | .lookup = nfs4_proc_lookup, |
| 9306 | .access = nfs4_proc_access, |
| 9307 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9308 | .create = nfs4_proc_create, |
| 9309 | .remove = nfs4_proc_remove, |
| 9310 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 9311 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9312 | .unlink_done = nfs4_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9313 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 9314 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 9315 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9316 | .link = nfs4_proc_link, |
| 9317 | .symlink = nfs4_proc_symlink, |
| 9318 | .mkdir = nfs4_proc_mkdir, |
| 9319 | .rmdir = nfs4_proc_remove, |
| 9320 | .readdir = nfs4_proc_readdir, |
| 9321 | .mknod = nfs4_proc_mknod, |
| 9322 | .statfs = nfs4_proc_statfs, |
| 9323 | .fsinfo = nfs4_proc_fsinfo, |
| 9324 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 9325 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9326 | .decode_dirent = nfs4_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 9327 | .pgio_rpc_prepare = nfs4_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9328 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9329 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9330 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9331 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9332 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 9333 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 9334 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9335 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 9336 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 9337 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 9338 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 9339 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 9340 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 9341 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 9342 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 9343 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 9344 | .create_server = nfs4_create_server, |
| 9345 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9346 | }; |
| 9347 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9348 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 9349 | .name = XATTR_NAME_NFSV4_ACL, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9350 | .list = nfs4_xattr_list_nfs4_acl, |
| 9351 | .get = nfs4_xattr_get_nfs4_acl, |
| 9352 | .set = nfs4_xattr_set_nfs4_acl, |
| 9353 | }; |
| 9354 | |
| 9355 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 9356 | &nfs4_xattr_nfs4_acl_handler, |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 9357 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
| 9358 | &nfs4_xattr_nfs4_label_handler, |
| 9359 | #endif |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 9360 | NULL |
| 9361 | }; |
| 9362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9363 | /* |
| 9364 | * Local variables: |
| 9365 | * c-basic-offset: 8 |
| 9366 | * End: |
| 9367 | */ |